1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Freeze some constants

This commit is contained in:
Akira Matsuda 2019-05-25 16:41:16 +09:00
parent f7c5baa77c
commit d134875c7f
8 changed files with 33 additions and 33 deletions

View file

@ -16,7 +16,7 @@ module Haml
TYPE = 1 TYPE = 1
TEXT = 2 TEXT = 2
IGNORED_TYPES = %i[on_sp on_ignored_nl] IGNORED_TYPES = %i[on_sp on_ignored_nl].freeze
class << self class << self
# @return [Boolean] - return true if AttributeParser.parse can be used. # @return [Boolean] - return true if AttributeParser.parse can be used.

View file

@ -5,29 +5,29 @@ module Haml
class Error < StandardError class Error < StandardError
MESSAGES = { MESSAGES = {
:bad_script_indent => '"%s" is indented at wrong level: expected %d, but was at %d.', bad_script_indent: '"%s" is indented at wrong level: expected %d, but was at %d.',
:cant_run_filter => 'Can\'t run "%s" filter; you must require its dependencies first', cant_run_filter: 'Can\'t run "%s" filter; you must require its dependencies first',
:cant_use_tabs_and_spaces => "Indentation can't use both tabs and spaces.", cant_use_tabs_and_spaces: "Indentation can't use both tabs and spaces.",
:deeper_indenting => "The line was indented %d levels deeper than the previous line.", deeper_indenting: "The line was indented %d levels deeper than the previous line.",
:filter_not_defined => 'Filter "%s" is not defined.', filter_not_defined: 'Filter "%s" is not defined.',
:gem_install_filter_deps => '"%s" filter\'s %s dependency missing: try installing it or adding it to your Gemfile', gem_install_filter_deps: '"%s" filter\'s %s dependency missing: try installing it or adding it to your Gemfile',
:illegal_element => "Illegal element: classes and ids must have values.", illegal_element: "Illegal element: classes and ids must have values.",
:illegal_nesting_content => "Illegal nesting: nesting within a tag that already has content is illegal.", illegal_nesting_content: "Illegal nesting: nesting within a tag that already has content is illegal.",
:illegal_nesting_header => "Illegal nesting: nesting within a header command is illegal.", illegal_nesting_header: "Illegal nesting: nesting within a header command is illegal.",
:illegal_nesting_line => "Illegal nesting: content can't be both given on the same line as %%%s and nested within it.", illegal_nesting_line: "Illegal nesting: content can't be both given on the same line as %%%s and nested within it.",
:illegal_nesting_plain => "Illegal nesting: nesting within plain text is illegal.", illegal_nesting_plain: "Illegal nesting: nesting within plain text is illegal.",
:illegal_nesting_self_closing => "Illegal nesting: nesting within a self-closing tag is illegal.", illegal_nesting_self_closing: "Illegal nesting: nesting within a self-closing tag is illegal.",
:inconsistent_indentation => "Inconsistent indentation: %s used for indentation, but the rest of the document was indented using %s.", inconsistent_indentation: "Inconsistent indentation: %s used for indentation, but the rest of the document was indented using %s.",
:indenting_at_start => "Indenting at the beginning of the document is illegal.", indenting_at_start: "Indenting at the beginning of the document is illegal.",
:install_haml_contrib => 'To use the "%s" filter, please install the haml-contrib gem.', install_haml_contrib: 'To use the "%s" filter, please install the haml-contrib gem.',
:invalid_attribute_list => 'Invalid attribute list: %s.', invalid_attribute_list: 'Invalid attribute list: %s.',
:invalid_filter_name => 'Invalid filter name ":%s".', invalid_filter_name: 'Invalid filter name ":%s".',
:invalid_tag => 'Invalid tag: "%s".', invalid_tag: 'Invalid tag: "%s".',
:missing_if => 'Got "%s" with no preceding "if"', missing_if: 'Got "%s" with no preceding "if"',
:no_ruby_code => "There's no Ruby code for %s to evaluate.", no_ruby_code: "There's no Ruby code for %s to evaluate.",
:self_closing_content => "Self-closing tags can't have content.", self_closing_content: "Self-closing tags can't have content.",
:unbalanced_brackets => 'Unbalanced brackets.', unbalanced_brackets: 'Unbalanced brackets.',
:no_end => <<-END no_end: <<-END
You don't need to use "- end" in Haml. Un-indent to close a block: You don't need to use "- end" in Haml. Un-indent to close a block:
- if foo? - if foo?
%strong Foo! %strong Foo!
@ -35,7 +35,7 @@ You don't need to use "- end" in Haml. Un-indent to close a block:
Not foo. Not foo.
%p This line is un-indented, so it isn't part of the "if" block %p This line is un-indented, so it isn't part of the "if" block
END END
} }.freeze
def self.message(key, *args) def self.message(key, *args)
string = MESSAGES[key] or raise "[HAML BUG] No error messages for #{key}" string = MESSAGES[key] or raise "[HAML BUG] No error messages for #{key}"

View file

@ -121,7 +121,7 @@ module Haml
@options[:input], @options[:output] = input, output @options[:input], @options[:output] = input, output
end end
COLORS = { :red => 31, :green => 32, :yellow => 33 } COLORS = {red: 31, green: 32, yellow: 33}.freeze
# Prints a status message about performing the given action, # Prints a status message about performing the given action,
# colored using the given color (via terminal escapes) if possible. # colored using the given color (via terminal escapes) if possible.

View file

@ -593,7 +593,7 @@ MESSAGE
end end
# Characters that need to be escaped to HTML entities from user input # Characters that need to be escaped to HTML entities from user input
HTML_ESCAPE = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;', "'" => '&#39;' } HTML_ESCAPE = {'&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;', "'" => '&#39;'}.freeze
HTML_ESCAPE_REGEX = /['"><&]/ HTML_ESCAPE_REGEX = /['"><&]/

View file

@ -61,7 +61,7 @@ module Haml
SILENT_SCRIPT, SILENT_SCRIPT,
ESCAPE, ESCAPE,
FILTER FILTER
] ].freeze
# The value of the character that designates that a line is part # The value of the character that designates that a line is part
# of a multiline string. # of a multiline string.
@ -75,8 +75,8 @@ module Haml
# #
BLOCK_WITH_SPACES = /do\s*\|\s*[^\|]*\s+\|\z/ BLOCK_WITH_SPACES = /do\s*\|\s*[^\|]*\s+\|\z/
MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when] MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when].freeze
START_BLOCK_KEYWORDS = %w[if begin case unless] START_BLOCK_KEYWORDS = %w[if begin case unless].freeze
# Try to parse assignments to block starters as best as possible # Try to parse assignments to block starters as best as possible
START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{START_BLOCK_KEYWORDS.join('|')})/ START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{START_BLOCK_KEYWORDS.join('|')})/
BLOCK_KEYWORD_REGEX = /^-?\s*(?:(#{MID_BLOCK_KEYWORDS.join('|')})|#{START_BLOCK_KEYWORD_REGEX.source})\b/ BLOCK_KEYWORD_REGEX = /^-?\s*(?:(#{MID_BLOCK_KEYWORDS.join('|')})|#{START_BLOCK_KEYWORD_REGEX.source})\b/

View file

@ -80,7 +80,7 @@ class EngineTest < Haml::TestCase
"foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5], "foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5],
"= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1], "= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1],
"- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4], "- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4],
} }.freeze
User = Struct.new('User', :id) User = Struct.new('User', :id)
CustomHamlClass = Struct.new(:id) do CustomHamlClass = Struct.new(:id) do

View file

@ -11,7 +11,7 @@ class TemplateTest < Haml::TestCase
whitespace_handling original_engine list helpful whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff partials silent_script tag_parsing just_stuff partials
nuke_outer_whitespace nuke_inner_whitespace bemit nuke_outer_whitespace nuke_inner_whitespace bemit
render_layout partial_layout partial_layout_erb} render_layout partial_layout partial_layout_erb}.freeze
def setup def setup
@base = create_base @base = create_base

View file

@ -24,7 +24,7 @@ class TempleLineCounterTest < Haml::TestCase
[:escape, true, [:static, "foo\nbar"]], [:escape, true, [:static, "foo\nbar"]],
[:escape, :once, [:static, "foo\nbar"]], [:escape, :once, [:static, "foo\nbar"]],
[:escape, false, [:dynamic, "foo\nbar"]], [:escape, false, [:dynamic, "foo\nbar"]],
] ].freeze
def test_count_lines def test_count_lines
TESTED_TEMPLES.each do |temple| TESTED_TEMPLES.each do |temple|