faml 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/benchmark/compiling.rb +1 -0
  4. data/benchmark/context.rb +1 -0
  5. data/benchmark/rendering.rb +1 -0
  6. data/benchmark/slim.rb +1 -0
  7. data/ext/attribute_builder/extconf.rb +1 -0
  8. data/faml.gemspec +1 -1
  9. data/haml_spec_test.rb +1 -0
  10. data/incompatibilities/README.md +1 -1
  11. data/incompatibilities/spec/compiler_newline_spec.md +1 -1
  12. data/incompatibilities/spec/render/attribute_spec.md +314 -28
  13. data/incompatibilities/spec/render/comment_spec.md +1 -1
  14. data/incompatibilities/spec/render/doctype_spec.md +1 -1
  15. data/incompatibilities/spec/render/element_spec.md +1 -1
  16. data/incompatibilities/spec/render/filters/cdata_spec.md +1 -1
  17. data/incompatibilities/spec/render/filters/css_spec.md +1 -1
  18. data/incompatibilities/spec/render/filters/escaped_spec.md +1 -1
  19. data/incompatibilities/spec/render/filters/javascript_spec.md +1 -1
  20. data/incompatibilities/spec/render/filters/markdown_spec.md +1 -1
  21. data/incompatibilities/spec/render/filters/plain_spec.md +2 -2
  22. data/incompatibilities/spec/render/filters/preserve_spec.md +1 -1
  23. data/incompatibilities/spec/render/helpers_spec.md +2 -2
  24. data/incompatibilities/spec/render/multiline_spec.md +2 -2
  25. data/incompatibilities/spec/render/newline_spec.md +4 -4
  26. data/incompatibilities/spec/render/plain_spec.md +1 -1
  27. data/incompatibilities/spec/render/sanitize_spec.md +2 -2
  28. data/incompatibilities/spec/render/silent_script_spec.md +1 -1
  29. data/incompatibilities/spec/render/unescape_spec.md +3 -3
  30. data/lib/faml.rb +1 -0
  31. data/lib/faml/attribute_compiler.rb +1 -0
  32. data/lib/faml/attribute_optimizer.rb +14 -3
  33. data/lib/faml/cli.rb +1 -0
  34. data/lib/faml/compiler.rb +1 -0
  35. data/lib/faml/engine.rb +1 -0
  36. data/lib/faml/error.rb +1 -0
  37. data/lib/faml/filter_compilers.rb +1 -0
  38. data/lib/faml/filter_compilers/base.rb +1 -0
  39. data/lib/faml/filter_compilers/cdata.rb +1 -0
  40. data/lib/faml/filter_compilers/coffee.rb +1 -0
  41. data/lib/faml/filter_compilers/css.rb +1 -0
  42. data/lib/faml/filter_compilers/escaped.rb +1 -0
  43. data/lib/faml/filter_compilers/javascript.rb +1 -0
  44. data/lib/faml/filter_compilers/markdown.rb +1 -0
  45. data/lib/faml/filter_compilers/plain.rb +1 -0
  46. data/lib/faml/filter_compilers/preserve.rb +1 -0
  47. data/lib/faml/filter_compilers/ruby.rb +1 -0
  48. data/lib/faml/filter_compilers/sass.rb +1 -0
  49. data/lib/faml/filter_compilers/scss.rb +1 -0
  50. data/lib/faml/filter_compilers/tilt_base.rb +1 -0
  51. data/lib/faml/helpers.rb +1 -0
  52. data/lib/faml/html.rb +1 -0
  53. data/lib/faml/newline.rb +1 -0
  54. data/lib/faml/object_ref.rb +1 -0
  55. data/lib/faml/rails_handler.rb +1 -0
  56. data/lib/faml/rails_helpers.rb +1 -0
  57. data/lib/faml/railtie.rb +1 -0
  58. data/lib/faml/ruby_syntax_checker.rb +1 -0
  59. data/lib/faml/script_end.rb +1 -0
  60. data/lib/faml/static_hash_parser.rb +37 -13
  61. data/lib/faml/stats.rb +1 -0
  62. data/lib/faml/text_compiler.rb +1 -0
  63. data/lib/faml/tilt.rb +1 -0
  64. data/lib/faml/version.rb +2 -1
  65. data/spec/compiler_newline_spec.rb +1 -0
  66. data/spec/rails/app/controllers/application_controller.rb +1 -0
  67. data/spec/rails/app/controllers/books_controller.rb +1 -0
  68. data/spec/rails/app/helpers/application_helper.rb +1 -0
  69. data/spec/rails/app/models/book.rb +1 -0
  70. data/spec/rails/config/application.rb +1 -0
  71. data/spec/rails/config/boot.rb +1 -0
  72. data/spec/rails/config/environment.rb +1 -0
  73. data/spec/rails/config/environments/development.rb +1 -0
  74. data/spec/rails/config/environments/production.rb +1 -0
  75. data/spec/rails/config/environments/test.rb +1 -0
  76. data/spec/rails/config/initializers/assets.rb +1 -0
  77. data/spec/rails/config/initializers/backtrace_silencers.rb +1 -0
  78. data/spec/rails/config/initializers/cookies_serializer.rb +1 -0
  79. data/spec/rails/config/initializers/filter_parameter_logging.rb +1 -0
  80. data/spec/rails/config/initializers/inflections.rb +1 -0
  81. data/spec/rails/config/initializers/mime_types.rb +1 -0
  82. data/spec/rails/config/initializers/secret_key_base.rb +1 -0
  83. data/spec/rails/config/initializers/session_store.rb +1 -0
  84. data/spec/rails/config/initializers/wrap_parameters.rb +1 -0
  85. data/spec/rails/config/routes.rb +1 -0
  86. data/spec/rails/db/seeds.rb +1 -0
  87. data/spec/rails/spec/requests/faml_spec.rb +1 -0
  88. data/spec/rails_helper.rb +1 -0
  89. data/spec/render/attribute_spec.rb +33 -0
  90. data/spec/render/comment_spec.rb +1 -0
  91. data/spec/render/doctype_spec.rb +1 -0
  92. data/spec/render/element_spec.rb +1 -0
  93. data/spec/render/filters/cdata_spec.rb +1 -0
  94. data/spec/render/filters/coffee_spec.rb +1 -0
  95. data/spec/render/filters/css_spec.rb +1 -0
  96. data/spec/render/filters/escaped_spec.rb +1 -0
  97. data/spec/render/filters/javascript_spec.rb +1 -0
  98. data/spec/render/filters/markdown_spec.rb +1 -0
  99. data/spec/render/filters/plain_spec.rb +1 -0
  100. data/spec/render/filters/preserve_spec.rb +1 -0
  101. data/spec/render/filters/ruby_spec.rb +1 -0
  102. data/spec/render/filters/sass_spec.rb +1 -0
  103. data/spec/render/filters/scss_spec.rb +1 -0
  104. data/spec/render/filters_spec.rb +1 -0
  105. data/spec/render/haml_comment_spec.rb +1 -0
  106. data/spec/render/helpers_spec.rb +1 -0
  107. data/spec/render/multiline_spec.rb +1 -0
  108. data/spec/render/newline_spec.rb +1 -0
  109. data/spec/render/plain_spec.rb +1 -0
  110. data/spec/render/preserve_spec.rb +1 -0
  111. data/spec/render/sanitize_spec.rb +1 -0
  112. data/spec/render/script_spec.rb +1 -0
  113. data/spec/render/silent_script_spec.rb +1 -0
  114. data/spec/render/unescape_spec.rb +1 -0
  115. data/spec/spec_helper.rb +1 -0
  116. data/spec/support/incompatibilities_generator.rb +2 -1
  117. data/spec/tilt_spec.rb +1 -0
  118. metadata +3 -3
@@ -1,4 +1,4 @@
1
- # [./spec/render/comment_spec.rb:31](../../../spec/render/comment_spec.rb#L31)
1
+ # [./spec/render/comment_spec.rb:32](../../../spec/render/comment_spec.rb#L32)
2
2
  ## Input
3
3
  ```haml
4
4
  / [if IE] hello
@@ -1,4 +1,4 @@
1
- # [./spec/render/doctype_spec.rb:9](../../../spec/render/doctype_spec.rb#L9)
1
+ # [./spec/render/doctype_spec.rb:10](../../../spec/render/doctype_spec.rb#L10)
2
2
  ## Input
3
3
  ```haml
4
4
  !!! xml
@@ -1,4 +1,4 @@
1
- # [./spec/render/element_spec.rb:56](../../../spec/render/element_spec.rb#L56)
1
+ # [./spec/render/element_spec.rb:57](../../../spec/render/element_spec.rb#L57)
2
2
  ## Input
3
3
  ```haml
4
4
  - @var = '</span>'
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/cdata_spec.rb:4](../../../../spec/render/filters/cdata_spec.rb#L4)
1
+ # [./spec/render/filters/cdata_spec.rb:5](../../../../spec/render/filters/cdata_spec.rb#L5)
2
2
  ## Input
3
3
  ```haml
4
4
  :cdata
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/css_spec.rb:24](../../../../spec/render/filters/css_spec.rb#L24)
1
+ # [./spec/render/filters/css_spec.rb:25](../../../../spec/render/filters/css_spec.rb#L25)
2
2
  ## Input
3
3
  ```haml
4
4
  %div
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/escaped_spec.rb:4](../../../../spec/render/filters/escaped_spec.rb#L4)
1
+ # [./spec/render/filters/escaped_spec.rb:5](../../../../spec/render/filters/escaped_spec.rb#L5)
2
2
  ## Input
3
3
  ```haml
4
4
  %span start
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/javascript_spec.rb:23](../../../../spec/render/filters/javascript_spec.rb#L23)
1
+ # [./spec/render/filters/javascript_spec.rb:24](../../../../spec/render/filters/javascript_spec.rb#L24)
2
2
  ## Input
3
3
  ```haml
4
4
  %div
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/markdown_spec.rb:12](../../../../spec/render/filters/markdown_spec.rb#L12)
1
+ # [./spec/render/filters/markdown_spec.rb:13](../../../../spec/render/filters/markdown_spec.rb#L13)
2
2
  ## Input
3
3
  ```haml
4
4
  :markdown
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/plain_spec.rb:4](../../../../spec/render/filters/plain_spec.rb#L4)
1
+ # [./spec/render/filters/plain_spec.rb:5](../../../../spec/render/filters/plain_spec.rb#L5)
2
2
  ## Input
3
3
  ```haml
4
4
  %span
@@ -27,7 +27,7 @@ hello
27
27
 
28
28
  ```
29
29
 
30
- # [./spec/render/filters/plain_spec.rb:13](../../../../spec/render/filters/plain_spec.rb#L13)
30
+ # [./spec/render/filters/plain_spec.rb:14](../../../../spec/render/filters/plain_spec.rb#L14)
31
31
  ## Input
32
32
  ```haml
33
33
  %span
@@ -1,4 +1,4 @@
1
- # [./spec/render/filters/preserve_spec.rb:4](../../../../spec/render/filters/preserve_spec.rb#L4)
1
+ # [./spec/render/filters/preserve_spec.rb:5](../../../../spec/render/filters/preserve_spec.rb#L5)
2
2
  ## Input
3
3
  ```haml
4
4
  %span start
@@ -1,4 +1,4 @@
1
- # [./spec/render/helpers_spec.rb:4](../../../spec/render/helpers_spec.rb#L4)
1
+ # [./spec/render/helpers_spec.rb:5](../../../spec/render/helpers_spec.rb#L5)
2
2
  ## Input (with options={:extend_helpers=>true})
3
3
  ```haml
4
4
  %span!= preserve "hello\nworld !"
@@ -12,6 +12,6 @@
12
12
 
13
13
  ## Hamlit (Error)
14
14
  ```html
15
- undefined method `preserve' for #<Object:0x00000002ca2b08>
15
+ undefined method `preserve' for #<Object:0x000000047293c8>
16
16
  ```
17
17
 
@@ -1,4 +1,4 @@
1
- # [./spec/render/multiline_spec.rb:22](../../../spec/render/multiline_spec.rb#L22)
1
+ # [./spec/render/multiline_spec.rb:23](../../../spec/render/multiline_spec.rb#L23)
2
2
  ## Input
3
3
  ```haml
4
4
  %p
@@ -24,7 +24,7 @@ foo bar baz
24
24
 
25
25
  ```
26
26
 
27
- # [./spec/render/multiline_spec.rb:47](../../../spec/render/multiline_spec.rb#L47)
27
+ # [./spec/render/multiline_spec.rb:48](../../../spec/render/multiline_spec.rb#L48)
28
28
  ## Input
29
29
  ```haml
30
30
  :javascript
@@ -1,4 +1,4 @@
1
- # [./spec/render/newline_spec.rb:19](../../../spec/render/newline_spec.rb#L19)
1
+ # [./spec/render/newline_spec.rb:20](../../../spec/render/newline_spec.rb#L20)
2
2
  ## Input
3
3
  ```haml
4
4
  %div
@@ -20,7 +20,7 @@
20
20
 
21
21
  ```
22
22
 
23
- # [./spec/render/newline_spec.rb:27](../../../spec/render/newline_spec.rb#L27)
23
+ # [./spec/render/newline_spec.rb:28](../../../spec/render/newline_spec.rb#L28)
24
24
  ## Input
25
25
  ```haml
26
26
  %div
@@ -46,7 +46,7 @@
46
46
 
47
47
  ```
48
48
 
49
- # [./spec/render/newline_spec.rb:36](../../../spec/render/newline_spec.rb#L36)
49
+ # [./spec/render/newline_spec.rb:37](../../../spec/render/newline_spec.rb#L37)
50
50
  ## Input
51
51
  ```haml
52
52
  %div
@@ -72,7 +72,7 @@
72
72
 
73
73
  ```
74
74
 
75
- # [./spec/render/newline_spec.rb:71](../../../spec/render/newline_spec.rb#L71)
75
+ # [./spec/render/newline_spec.rb:72](../../../spec/render/newline_spec.rb#L72)
76
76
  ## Input
77
77
  ```haml
78
78
  %div(foo="bar") <b>hello</b>
@@ -1,4 +1,4 @@
1
- # [./spec/render/plain_spec.rb:8](../../../spec/render/plain_spec.rb#L8)
1
+ # [./spec/render/plain_spec.rb:9](../../../spec/render/plain_spec.rb#L9)
2
2
  ## Input
3
3
  ```haml
4
4
  %span foo\\#{1 + 2}bar
@@ -1,4 +1,4 @@
1
- # [./spec/render/sanitize_spec.rb:24](../../../spec/render/sanitize_spec.rb#L24)
1
+ # [./spec/render/sanitize_spec.rb:25](../../../spec/render/sanitize_spec.rb#L25)
2
2
  ## Input
3
3
  ```haml
4
4
  &~ "<p>hello</p>"
@@ -16,7 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- # [./spec/render/sanitize_spec.rb:24](../../../spec/render/sanitize_spec.rb#L24)
19
+ # [./spec/render/sanitize_spec.rb:25](../../../spec/render/sanitize_spec.rb#L25)
20
20
  ## Input
21
21
  ```haml
22
22
  %span&~ "<p>hello</p>"
@@ -1,4 +1,4 @@
1
- # [./spec/render/silent_script_spec.rb:51](../../../spec/render/silent_script_spec.rb#L51)
1
+ # [./spec/render/silent_script_spec.rb:52](../../../spec/render/silent_script_spec.rb#L52)
2
2
  ## Input
3
3
  ```haml
4
4
  %div
@@ -1,4 +1,4 @@
1
- # [./spec/render/unescape_spec.rb:17](../../../spec/render/unescape_spec.rb#L17)
1
+ # [./spec/render/unescape_spec.rb:18](../../../spec/render/unescape_spec.rb#L18)
2
2
  ## Input
3
3
  ```haml
4
4
  !<p>hello</p>
@@ -16,7 +16,7 @@
16
16
 
17
17
  ```
18
18
 
19
- # [./spec/render/unescape_spec.rb:33](../../../spec/render/unescape_spec.rb#L33)
19
+ # [./spec/render/unescape_spec.rb:34](../../../spec/render/unescape_spec.rb#L34)
20
20
  ## Input
21
21
  ```haml
22
22
  !~ "<p>hello\n<pre>pre\nworld</pre></p>"
@@ -35,7 +35,7 @@
35
35
 
36
36
  ```
37
37
 
38
- # [./spec/render/unescape_spec.rb:33](../../../spec/render/unescape_spec.rb#L33)
38
+ # [./spec/render/unescape_spec.rb:34](../../../spec/render/unescape_spec.rb#L34)
39
39
  ## Input
40
40
  ```haml
41
41
  %span!~ "<p>hello\n<pre>pre\nworld</pre></p>"
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'faml/engine'
2
3
  require_relative 'faml/tilt'
3
4
  require_relative 'faml/version'
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'attribute_optimizer'
2
3
  require_relative 'object_ref'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'error'
2
3
  require_relative 'ruby_syntax_checker'
3
4
  require_relative 'static_hash_parser'
@@ -40,11 +41,21 @@ module Faml
40
41
 
41
42
  def build_optimized_static_attributes(parser, static_id, static_class)
42
43
  static_attributes = {}
44
+ class_list = []
45
+ id_list = []
43
46
  parser.static_attributes.each do |k, v|
44
- static_attributes[k.to_s] = v
47
+ k = k.to_s
48
+ case k
49
+ when 'id'
50
+ id_list.concat(Array(v))
51
+ when 'class'
52
+ class_list.concat(Array(v))
53
+ else
54
+ static_attributes[k] = v
55
+ end
45
56
  end
46
57
 
47
- class_list = Array(static_attributes.delete('class')).select { |v| v }.flat_map { |c| c.to_s.split(/ +/) }
58
+ class_list = class_list.select { |v| v }.flat_map { |c| c.to_s.split(/ +/) }
48
59
  unless static_class.empty?
49
60
  class_list.concat(static_class.split(/ +/))
50
61
  end
@@ -52,7 +63,7 @@ module Faml
52
63
  static_attributes['class'] = class_list.uniq.sort.join(' ')
53
64
  end
54
65
 
55
- id_list = Array(static_attributes.delete('id')).select { |v| v }
66
+ id_list = id_list.select { |v| v }
56
67
  unless static_id.empty?
57
68
  id_list = [static_id].concat(id_list)
58
69
  end
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative '../faml'
2
3
  require 'thor'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'ripper'
2
3
  require 'temple'
3
4
  require 'haml_parser/ast'
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'haml_parser/parser'
2
3
  require 'temple'
3
4
  require_relative 'compiler'
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  module Faml
2
3
  class Error < StandardError
3
4
  attr_accessor :lineno
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'error'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative '../text_compiler'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'tilt_base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'tilt_base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'tilt_base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'tilt_base'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'temple'
2
3
  require 'tilt'
3
4
  require_relative 'base'
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  module Faml
2
3
  # Don't use these methods!
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'faml/attribute_builder'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'temple'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  module Faml
2
3
  module ObjectRef
3
4
  class << self
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  module Faml
2
3
  class RailsHandler
3
4
  def call(template)
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require_relative 'helpers'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  module Faml
2
3
  class Railtie < ::Rails::Railtie
3
4
  initializer :faml do
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'ripper'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'temple'
2
3
 
3
4
  module Faml
@@ -1,3 +1,4 @@
1
+ # frozen-string-literal: true
1
2
  require 'parser/current'
2
3
 
3
4
  module Faml
@@ -65,24 +66,26 @@ module Faml
65
66
  end
66
67
  end
67
68
 
68
- def try_static_value(key_static, node)
69
+ def try_static_value(key_static, node, force_static: false)
69
70
  case node.type
70
71
  when :sym, :int, :float, :str, :rational, :complex
71
- @static_attributes[key_static] = node.children[0]
72
+ set_static_attribute(key_static, node.children[0])
72
73
  when :true
73
- @static_attributes[key_static] = true
74
+ set_static_attribute(key_static, true)
74
75
  when :false
75
- @static_attributes[key_static] = false
76
+ set_static_attribute(key_static, false)
76
77
  when :nil
77
- @static_attributes[key_static] = nil
78
+ set_static_attribute(key_static, nil)
78
79
  when :dstr
79
- @dynamic_attributes[key_static] = node.location.expression.source
80
+ if force_static
81
+ throw FAILURE_TAG
82
+ end
83
+ set_dynamic_attributes(key_static, node.location.expression.source)
80
84
  when :send
81
- if SPECIAL_ATTRIBUTES.include?(key_static.to_s)
85
+ if force_static
82
86
  throw FAILURE_TAG
83
- else
84
- @dynamic_attributes[key_static] = node.location.expression.source
85
87
  end
88
+ set_dynamic_attributes(key_static, node.location.expression.source)
86
89
  when :hash
87
90
  try_static_hash_value(key_static, node)
88
91
  when :array
@@ -91,6 +94,7 @@ module Faml
91
94
  throw FAILURE_TAG
92
95
  end
93
96
  end
97
+ protected :try_static_value
94
98
 
95
99
  def try_static_hash_value(key_static, node)
96
100
  parser = self.class.new
@@ -104,7 +108,7 @@ module Faml
104
108
 
105
109
  def merge_attributes(key_static, parser)
106
110
  unless parser.static_attributes.empty?
107
- @static_attributes[key_static] = parser.static_attributes
111
+ set_static_attribute(key_static, parser.static_attributes)
108
112
  end
109
113
 
110
114
  unless parser.dynamic_attributes.empty?
@@ -116,10 +120,30 @@ module Faml
116
120
  end
117
121
 
118
122
  def try_static_array_value(key_static, node)
119
- arr = node.children.map do |child|
120
- try_static_value(key_static, child)
123
+ parser = self.class.new
124
+ arr = node.children.map.with_index do |child, i|
125
+ # TODO: Support dynamic_attributes?
126
+ parser.try_static_value(i, child, force_static: true)
127
+ end
128
+ set_static_attribute(key_static, arr)
129
+ end
130
+
131
+ def set_static_attribute(key, val)
132
+ case key.to_s
133
+ when 'id', 'class'
134
+ @static_attributes[key] ||= []
135
+ @static_attributes[key].concat(Array(val))
136
+ else
137
+ @static_attributes[key] = val
138
+ end
139
+ val
140
+ end
141
+
142
+ def set_dynamic_attributes(key, val)
143
+ if SPECIAL_ATTRIBUTES.include?(key.to_s)
144
+ throw FAILURE_TAG
121
145
  end
122
- @static_attributes[key_static] = arr
146
+ @dynamic_attributes[key] = val
123
147
  end
124
148
  end
125
149
  end