hamlit 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/lib/hamlit.rb +1 -0
  4. data/lib/hamlit/attribute_builder.rb +1 -0
  5. data/lib/hamlit/attribute_compiler.rb +4 -3
  6. data/lib/hamlit/attribute_parser.rb +6 -5
  7. data/lib/hamlit/cli.rb +1 -0
  8. data/lib/hamlit/compiler.rb +1 -0
  9. data/lib/hamlit/compiler/children_compiler.rb +2 -1
  10. data/lib/hamlit/compiler/doctype_compiler.rb +1 -0
  11. data/lib/hamlit/compiler/script_compiler.rb +3 -2
  12. data/lib/hamlit/compiler/silent_script_compiler.rb +1 -0
  13. data/lib/hamlit/compiler/tag_compiler.rb +2 -1
  14. data/lib/hamlit/engine.rb +1 -0
  15. data/lib/hamlit/error.rb +1 -0
  16. data/lib/hamlit/escapable.rb +1 -0
  17. data/lib/hamlit/filters.rb +3 -0
  18. data/lib/hamlit/filters/base.rb +1 -0
  19. data/lib/hamlit/filters/cdata.rb +20 -0
  20. data/lib/hamlit/filters/coffee.rb +3 -2
  21. data/lib/hamlit/filters/css.rb +7 -6
  22. data/lib/hamlit/filters/erb.rb +1 -0
  23. data/lib/hamlit/filters/escaped.rb +1 -0
  24. data/lib/hamlit/filters/javascript.rb +7 -6
  25. data/lib/hamlit/filters/less.rb +3 -2
  26. data/lib/hamlit/filters/plain.rb +1 -0
  27. data/lib/hamlit/filters/preserve.rb +1 -0
  28. data/lib/hamlit/filters/ruby.rb +1 -0
  29. data/lib/hamlit/filters/sass.rb +3 -2
  30. data/lib/hamlit/filters/scss.rb +3 -2
  31. data/lib/hamlit/filters/text_base.rb +1 -0
  32. data/lib/hamlit/filters/tilt_base.rb +2 -1
  33. data/lib/hamlit/force_escapable.rb +1 -0
  34. data/lib/hamlit/helpers.rb +1 -0
  35. data/lib/hamlit/html.rb +1 -0
  36. data/lib/hamlit/identity.rb +1 -0
  37. data/lib/hamlit/object_ref.rb +1 -0
  38. data/lib/hamlit/parser.rb +1 -0
  39. data/lib/hamlit/rails_helpers.rb +1 -0
  40. data/lib/hamlit/rails_template.rb +1 -0
  41. data/lib/hamlit/railtie.rb +1 -0
  42. data/lib/hamlit/ruby_expression.rb +1 -0
  43. data/lib/hamlit/static_analyzer.rb +1 -0
  44. data/lib/hamlit/template.rb +1 -0
  45. data/lib/hamlit/utils.rb +1 -0
  46. data/lib/hamlit/version.rb +2 -1
  47. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b8b35eeaefa28bac22fe4535c4d33563974f734
4
- data.tar.gz: 2c321cb4eafe5c6e0c7e913334867b46680b6510
3
+ metadata.gz: b22430fc90715fc9557d4cd0f63bf7cd616c43c4
4
+ data.tar.gz: aa4ce7df77eb79e02688a208b8efa8cfdf572c60
5
5
  SHA512:
6
- metadata.gz: 4ee32ce74ac89cf0fe7142ffdf3321ce83f4d69806976f7bed04757b943f78434c2a36ab85dc6c9b8ae85594cdfc2e3cfe5ffeb5eba0c723a9e9ec2c0006dec8
7
- data.tar.gz: a15d8443095adca91607fa58e82e1c03bfa8cc2a64df0244b76e630377f2360f3c6b58281978b3ca5340d34092477f3aefc6e9594a376b45736bc10c177ac25a
6
+ metadata.gz: 0b4d121ab0326143c3651727f7d122006389fd9064810aa38b8b9d251a92bba143ebe9582614fd76e2611e7b1a50e43d76bd904acbf18c0aa3096ada925d74ec
7
+ data.tar.gz: 512e91b9d64b94615f9fde9fec22145db8a8e8eeac74a663896cb43d1065d5e0f51ff4a61ffbd1e68e89896393f7cfc9a6e93564d302009c1d60988ba591d2e4
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. This
4
4
  project adheres to [Semantic Versioning](http://semver.org/). This change log is based upon
5
5
  [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
6
6
 
7
+ ## [2.6.2](https://github.com/k0kubun/hamlit/compare/v2.6.1...v2.6.2) - 2016-08-27
8
+
9
+ ### Added
10
+
11
+ - Add cdata filter
12
+ [#84](https://github.com/k0kubun/hamlit/issues/84). *Thanks to @shmargum*
13
+ - Minimize string allocation on template comipilation using `# frozen_string_literal: true`
14
+
7
15
  ## [2.6.1](https://github.com/k0kubun/hamlit/compare/v2.6.0...v2.6.1) - 2016-08-18
8
16
 
9
17
  ### Fixed
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/engine'
2
3
  require 'hamlit/error'
3
4
  require 'hamlit/version'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/hamlit'
2
3
  require 'hamlit/object_ref'
3
4
  require 'hamlit/utils'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/attribute_builder'
2
3
  require 'hamlit/attribute_parser'
3
4
  require 'hamlit/ruby_expression'
@@ -41,11 +42,11 @@ module Hamlit
41
42
  values.select! { |_, exp| exp != nil }
42
43
 
43
44
  case key
44
- when 'id'.freeze
45
+ when 'id'
45
46
  compile_id!(temple, key, values)
46
- when 'class'.freeze
47
+ when 'class'
47
48
  compile_class!(temple, key, values)
48
- when 'data'.freeze
49
+ when 'data'
49
50
  compile_data!(temple, key, values)
50
51
  when *AttributeBuilder::BOOLEAN_ATTRIBUTES, /\Adata-/
51
52
  compile_boolean!(temple, key, values)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/ruby_expression'
2
3
 
3
4
  module Hamlit
@@ -28,8 +29,8 @@ module Hamlit
28
29
 
29
30
  def wrap_bracket(text)
30
31
  text = text.strip
31
- return text if text[0] == '{'.freeze
32
- '{' << text << '}'.freeze
32
+ return text if text[0] == '{'
33
+ "{#{text}}"
33
34
  end
34
35
 
35
36
  def parse_key!(tokens)
@@ -38,10 +39,10 @@ module Hamlit
38
39
  when :on_sp
39
40
  parse_key!(tokens)
40
41
  when :on_label
41
- str.tr(':'.freeze, ''.freeze)
42
+ str.tr(':', '')
42
43
  when :on_symbeg
43
44
  _, _, key = tokens.shift
44
- assert_type!(tokens.shift, :on_tstring_end) if str != ':'.freeze
45
+ assert_type!(tokens.shift, :on_tstring_end) if str != ':'
45
46
  skip_until_hash_rocket!(tokens)
46
47
  key
47
48
  when :on_tstring_beg
@@ -64,7 +65,7 @@ module Hamlit
64
65
  def skip_until_hash_rocket!(tokens)
65
66
  until tokens.empty?
66
67
  _, type, str = tokens.shift
67
- break if type == :on_op && str == '=>'.freeze
68
+ break if type == :on_op && str == '=>'
68
69
  end
69
70
  end
70
71
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit'
2
3
  require 'thor'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/compiler/children_compiler'
2
3
  require 'hamlit/compiler/comment_compiler'
3
4
  require 'hamlit/compiler/doctype_compiler'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Compiler
3
4
  class ChildrenCompiler
@@ -101,7 +102,7 @@ module Hamlit
101
102
  when :script
102
103
  node.children.empty? && !nuke_inner_whitespace?(node)
103
104
  when :filter
104
- !%w[ruby].freeze.include?(node.value[:name])
105
+ !%w[ruby].include?(node.value[:name])
105
106
  else
106
107
  false
107
108
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Compiler
3
4
  class DoctypeCompiler
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/ruby_expression'
2
3
  require 'hamlit/static_analyzer'
3
4
  require 'hamlit/string_splitter'
@@ -69,7 +70,7 @@ module Hamlit
69
70
  [:multi,
70
71
  [:code, "#{var} = (#{node.value[:text]}"],
71
72
  [:newline],
72
- [:code, ')'.freeze],
73
+ [:code, ')'],
73
74
  ]
74
75
  else
75
76
  [:multi,
@@ -84,7 +85,7 @@ module Hamlit
84
85
  if !node.value[:escape_html] && node.value[:preserve]
85
86
  result = find_and_preserve(result)
86
87
  else
87
- result = '(' << result << ').to_s'.freeze
88
+ result = "(#{result}).to_s"
88
89
  end
89
90
  [:escape, node.value[:escape_html], [:dynamic, result]]
90
91
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Compiler
3
4
  class SilentScriptCompiler
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/parser/haml_util'
2
3
  require 'hamlit/attribute_compiler'
3
4
  require 'hamlit/static_analyzer'
@@ -35,7 +36,7 @@ module Hamlit
35
36
  [:multi,
36
37
  [:code, "#{var} = (#{node.value[:value]}"],
37
38
  [:newline],
38
- [:code, ')'.freeze],
39
+ [:code, ')'],
39
40
  [:escape, node.value[:escape_html], [:dynamic, var]]
40
41
  ]
41
42
  else
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'temple'
2
3
  require 'hamlit/parser'
3
4
  require 'hamlit/compiler'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Error < StandardError
3
4
  attr_reader :line
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/utils'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/filters/base'
2
3
  require 'hamlit/filters/text_base'
3
4
  require 'hamlit/filters/tilt_base'
@@ -13,6 +14,7 @@ require 'hamlit/filters/preserve'
13
14
  require 'hamlit/filters/ruby'
14
15
  require 'hamlit/filters/sass'
15
16
  require 'hamlit/filters/scss'
17
+ require 'hamlit/filters/cdata'
16
18
 
17
19
  module Hamlit
18
20
  class Filters
@@ -48,6 +50,7 @@ module Hamlit
48
50
  register :ruby, Ruby
49
51
  register :sass, Sass
50
52
  register :scss, Scss
53
+ register :cdata, Cdata
51
54
 
52
55
  def initialize(options = {})
53
56
  @options = options
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/parser/haml_util'
2
3
 
3
4
  module Hamlit
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module Hamlit
3
+ class Filters
4
+ class Cdata < TextBase
5
+ def compile(node)
6
+ compile_cdata(node)
7
+ end
8
+
9
+ private
10
+
11
+ def compile_cdata(node)
12
+ temple = [:multi]
13
+ temple << [:static, "<![CDATA[\n"]
14
+ compile_text!(temple, node, ' ')
15
+ temple << [:static, "\n]]>"]
16
+ temple
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Coffee < TiltBase
4
5
  def compile(node)
5
6
  require 'tilt/coffee' if explicit_require?
6
7
  temple = [:multi]
7
- temple << [:static, "<script>\n".freeze]
8
+ temple << [:static, "<script>\n"]
8
9
  temple << compile_with_tilt(node, 'coffee', indent_width: 2)
9
- temple << [:static, "</script>".freeze]
10
+ temple << [:static, "</script>"]
10
11
  temple
11
12
  end
12
13
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Css < TextBase
@@ -14,17 +15,17 @@ module Hamlit
14
15
 
15
16
  def compile_html(node)
16
17
  temple = [:multi]
17
- temple << [:static, "<style>\n".freeze]
18
- compile_text!(temple, node, ' '.freeze)
19
- temple << [:static, "\n</style>".freeze]
18
+ temple << [:static, "<style>\n"]
19
+ compile_text!(temple, node, ' ')
20
+ temple << [:static, "\n</style>"]
20
21
  temple
21
22
  end
22
23
 
23
24
  def compile_xhtml(node)
24
25
  temple = [:multi]
25
- temple << [:static, "<style type='text/css'>\n /*<![CDATA[*/\n".freeze]
26
- compile_text!(temple, node, ' '.freeze)
27
- temple << [:static, "\n /*]]>*/\n</style>".freeze]
26
+ temple << [:static, "<style type='text/css'>\n /*<![CDATA[*/\n"]
27
+ compile_text!(temple, node, ' ')
28
+ temple << [:static, "\n /*]]>*/\n</style>"]
28
29
  temple
29
30
  end
30
31
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Erb < TiltBase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Escaped < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Javascript < TextBase
@@ -14,17 +15,17 @@ module Hamlit
14
15
 
15
16
  def compile_html(node)
16
17
  temple = [:multi]
17
- temple << [:static, "<script>\n".freeze]
18
- compile_text!(temple, node, ' '.freeze)
19
- temple << [:static, "\n</script>".freeze]
18
+ temple << [:static, "<script>\n"]
19
+ compile_text!(temple, node, ' ')
20
+ temple << [:static, "\n</script>"]
20
21
  temple
21
22
  end
22
23
 
23
24
  def compile_xhtml(node)
24
25
  temple = [:multi]
25
- temple << [:static, "<script type='text/javascript'>\n //<![CDATA[\n".freeze]
26
- compile_text!(temple, node, ' '.freeze)
27
- temple << [:static, "\n //]]>\n</script>".freeze]
26
+ temple << [:static, "<script type='text/javascript'>\n //<![CDATA[\n"]
27
+ compile_text!(temple, node, ' ')
28
+ temple << [:static, "\n //]]>\n</script>"]
28
29
  temple
29
30
  end
30
31
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # LESS support is deprecated since it requires therubyracer.gem,
2
3
  # which is hard to maintain.
3
4
  #
@@ -9,9 +10,9 @@ module Hamlit
9
10
  def compile(node)
10
11
  require 'tilt/less' if explicit_require?
11
12
  temple = [:multi]
12
- temple << [:static, "<style>\n".freeze]
13
+ temple << [:static, "<style>\n"]
13
14
  temple << compile_with_tilt(node, 'less', indent_width: 2)
14
- temple << [:static, "</style>".freeze]
15
+ temple << [:static, '</style>']
15
16
  temple
16
17
  end
17
18
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/string_splitter'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Preserve < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Ruby < Base
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Sass < TiltBase
4
5
  def compile(node)
5
6
  require 'tilt/sass' if explicit_require?
6
7
  temple = [:multi]
7
- temple << [:static, "<style>\n".freeze]
8
+ temple << [:static, "<style>\n"]
8
9
  temple << compile_with_tilt(node, 'sass', indent_width: 2)
9
- temple << [:static, "</style>".freeze]
10
+ temple << [:static, "</style>"]
10
11
  temple
11
12
  end
12
13
  end
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class Scss < TiltBase
4
5
  def compile(node)
5
6
  require 'tilt/sass' if explicit_require?
6
7
  temple = [:multi]
7
- temple << [:static, "<style>\n".freeze]
8
+ temple << [:static, "<style>\n"]
8
9
  temple << compile_with_tilt(node, 'scss', indent_width: 2)
9
- temple << [:static, "</style>".freeze]
10
+ temple << [:static, "</style>"]
10
11
  temple
11
12
  end
12
13
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Filters
3
4
  class TextBase < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'tilt'
2
3
 
3
4
  module Hamlit
@@ -6,7 +7,7 @@ module Hamlit
6
7
  def self.render(name, source, indent_width: 0)
7
8
  text = ::Tilt["t.#{name}"].new { source }.render
8
9
  return text if indent_width == 0
9
- text.gsub!(/^/, ' '.freeze * indent_width)
10
+ text.gsub!(/^/, ' ' * indent_width)
10
11
  end
11
12
 
12
13
  def explicit_require?
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/escapable'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  module Helpers
3
4
  extend self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class HTML < Temple::HTML::Fast
3
4
  DEPRECATED_FORMATS = %i[html4 html5].freeze
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  class Identity
3
4
  def initialize
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
3
  module ObjectRef
3
4
  class << self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Hamlit::Parser uses original Haml::Parser to generate Haml AST.
2
3
  # hamlit/parser/haml_* are modules originally in haml gem.
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  require 'hamlit/helpers'
2
3
 
3
4
  # Currently this Hamlit::Helpers depends on
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'temple'
2
3
  require 'hamlit/engine'
3
4
  require 'hamlit/rails_helpers'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'ripper'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/ruby_expression'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  require 'temple'
2
3
  require 'hamlit/engine'
3
4
  require 'hamlit/helpers'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'hamlit/hamlit'
2
3
 
3
4
  module Hamlit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Hamlit
2
- VERSION = '2.6.1'
3
+ VERSION = '2.6.2'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -309,6 +309,7 @@ files:
309
309
  - lib/hamlit/escapable.rb
310
310
  - lib/hamlit/filters.rb
311
311
  - lib/hamlit/filters/base.rb
312
+ - lib/hamlit/filters/cdata.rb
312
313
  - lib/hamlit/filters/coffee.rb
313
314
  - lib/hamlit/filters/css.rb
314
315
  - lib/hamlit/filters/erb.rb