temple 0.6.7 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +34 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES +106 -1
  5. data/EXPRESSIONS.md +3 -2
  6. data/Gemfile +0 -1
  7. data/README.md +14 -10
  8. data/Rakefile +4 -11
  9. data/lib/temple/engine.rb +7 -3
  10. data/lib/temple/erb/engine.rb +5 -3
  11. data/lib/temple/erb/parser.rb +1 -1
  12. data/lib/temple/erb/trimming.rb +11 -26
  13. data/lib/temple/filters/ambles.rb +21 -0
  14. data/lib/temple/filters/encoding.rb +1 -1
  15. data/lib/temple/filters/eraser.rb +1 -1
  16. data/lib/temple/filters/escapable.rb +2 -2
  17. data/lib/temple/filters/remove_bom.rb +2 -9
  18. data/lib/temple/filters/static_analyzer.rb +30 -0
  19. data/lib/temple/filters/string_splitter.rb +141 -0
  20. data/lib/temple/filters/validator.rb +1 -1
  21. data/lib/temple/generator.rb +32 -6
  22. data/lib/temple/generators/array.rb +2 -2
  23. data/lib/temple/generators/array_buffer.rb +6 -5
  24. data/lib/temple/generators/erb.rb +1 -5
  25. data/lib/temple/generators/rails_output_buffer.rb +7 -8
  26. data/lib/temple/generators/string_buffer.rb +2 -2
  27. data/lib/temple/html/attribute_merger.rb +6 -11
  28. data/lib/temple/html/attribute_remover.rb +1 -1
  29. data/lib/temple/html/attribute_sorter.rb +1 -1
  30. data/lib/temple/html/fast.rb +49 -44
  31. data/lib/temple/html/pretty.rb +34 -43
  32. data/lib/temple/html/safe.rb +23 -0
  33. data/lib/temple/map.rb +105 -0
  34. data/lib/temple/mixins/dispatcher.rb +10 -7
  35. data/lib/temple/mixins/engine_dsl.rb +42 -67
  36. data/lib/temple/mixins/grammar_dsl.rb +10 -8
  37. data/lib/temple/mixins/options.rb +26 -24
  38. data/lib/temple/mixins/template.rb +3 -3
  39. data/lib/temple/static_analyzer.rb +77 -0
  40. data/lib/temple/templates/rails.rb +17 -36
  41. data/lib/temple/templates/tilt.rb +7 -13
  42. data/lib/temple/utils.rb +27 -29
  43. data/lib/temple/version.rb +1 -1
  44. data/lib/temple.rb +8 -4
  45. data/spec/engine_spec.rb +189 -0
  46. data/{test/test_erb.rb → spec/erb_spec.rb} +12 -13
  47. data/spec/filter_spec.rb +29 -0
  48. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  49. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  50. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  51. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +13 -13
  52. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +15 -13
  53. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  54. data/spec/filters/static_analyzer_spec.rb +35 -0
  55. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  56. data/spec/filters/string_splitter_spec.rb +50 -0
  57. data/spec/generator_spec.rb +158 -0
  58. data/spec/grammar_spec.rb +47 -0
  59. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  60. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  61. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +8 -8
  62. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  63. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +9 -15
  64. data/spec/map_spec.rb +39 -0
  65. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  66. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  67. data/{test/helper.rb → spec/spec_helper.rb} +9 -15
  68. data/spec/static_analyzer_spec.rb +39 -0
  69. data/spec/utils_spec.rb +39 -0
  70. data/temple.gemspec +4 -2
  71. metadata +62 -63
  72. data/.travis.yml +0 -13
  73. data/lib/temple/hash.rb +0 -104
  74. data/test/test_engine.rb +0 -170
  75. data/test/test_filter.rb +0 -29
  76. data/test/test_generator.rb +0 -136
  77. data/test/test_grammar.rb +0 -47
  78. data/test/test_hash.rb +0 -39
  79. data/test/test_utils.rb +0 -39
data/test/test_grammar.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'helper'
2
-
3
- describe Temple::Grammar do
4
- it 'should match core expressions' do
5
- Temple::Grammar.should.match [:multi]
6
- Temple::Grammar.should.match [:multi, [:multi]]
7
- Temple::Grammar.should.match [:static, 'Text']
8
- Temple::Grammar.should.match [:dynamic, 'Text']
9
- Temple::Grammar.should.match [:code, 'Text']
10
- Temple::Grammar.should.match [:capture, 'Text', [:multi]]
11
- Temple::Grammar.should.match [:newline]
12
- end
13
-
14
- it 'should not match invalid core expressions' do
15
- Temple::Grammar.should.not.match [:multi, 'String']
16
- Temple::Grammar.should.not.match [:static]
17
- Temple::Grammar.should.not.match [:dynamic, 1]
18
- Temple::Grammar.should.not.match [:code, :sym]
19
- Temple::Grammar.should.not.match [:capture, [:multi]]
20
- Temple::Grammar.should.not.match [:newline, [:multi]]
21
- end
22
-
23
- it 'should match control flow expressions' do
24
- Temple::Grammar.should.match [:if, 'Condition', [:multi]]
25
- Temple::Grammar.should.match [:if, 'Condition', [:multi], [:multi]]
26
- Temple::Grammar.should.match [:block, 'Loop', [:multi]]
27
- Temple::Grammar.should.match [:case, 'Arg', ['Cond1', [:multi]], ['Cond1', [:multi]], [:else, [:multi]]]
28
- Temple::Grammar.should.not.match [:case, 'Arg', [:sym, [:multi]]]
29
- Temple::Grammar.should.match [:cond, ['Cond1', [:multi]], ['Cond2', [:multi]], [:else, [:multi]]]
30
- Temple::Grammar.should.not.match [:cond, [:sym, [:multi]]]
31
- end
32
-
33
- it 'should match escape expression' do
34
- Temple::Grammar.should.match [:escape, true, [:multi]]
35
- Temple::Grammar.should.match [:escape, false, [:multi]]
36
- end
37
-
38
- it 'should match html expressions' do
39
- Temple::Grammar.should.match [:html, :doctype, 'Doctype']
40
- Temple::Grammar.should.match [:html, :comment, [:multi]]
41
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi]]
42
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:multi]]
43
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:multi], [:static, 'Text']]
44
- Temple::Grammar.should.match [:html, :tag, 'Tag', [:html, :attrs, [:html, :attr, 'id',
45
- [:static, 'val']]], [:static, 'Text']]
46
- end
47
- end
data/test/test_hash.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- describe Temple::ImmutableHash do
4
- it 'has read accessor' do
5
- hash = Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
6
- hash[:a].should.equal 1
7
- hash[:b].should.equal 2
8
- end
9
-
10
- it 'has include?' do
11
- hash = Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3})
12
- hash.should.include :a
13
- hash.should.include :b
14
- hash.should.not.include :c
15
- end
16
-
17
- it 'has values' do
18
- Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).values.sort.should.equal [1,2]
19
- end
20
-
21
- it 'has keys' do
22
- Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).keys.should.equal [:a,:b]
23
- end
24
-
25
- it 'has to_a' do
26
- Temple::ImmutableHash.new({:a => 1},{:b => 2, :a => 3}).to_a.should.equal [[:a, 1], [:b, 2]]
27
- end
28
- end
29
-
30
- describe Temple::MutableHash do
31
- it 'has write accessor' do
32
- parent = {:a => 1}
33
- hash = Temple::MutableHash.new(parent)
34
- hash[:a].should.equal 1
35
- hash[:a] = 2
36
- hash[:a].should.equal 2
37
- parent[:a].should.equal 1
38
- end
39
- end
data/test/test_utils.rb DELETED
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- class UniqueTest
4
- include Temple::Utils
5
- end
6
-
7
- describe Temple::Utils do
8
- it 'has empty_exp?' do
9
- Temple::Utils.empty_exp?([:multi]).should.be.true
10
- Temple::Utils.empty_exp?([:multi, [:multi]]).should.be.true
11
- Temple::Utils.empty_exp?([:multi, [:multi, [:newline]], [:newline]]).should.be.true
12
- Temple::Utils.empty_exp?([:multi]).should.be.true
13
- Temple::Utils.empty_exp?([:multi, [:multi, [:static, 'text']]]).should.be.false
14
- Temple::Utils.empty_exp?([:multi, [:newline], [:multi, [:dynamic, 'text']]]).should.be.false
15
- end
16
-
17
- it 'has unique_name' do
18
- u = UniqueTest.new
19
- u.unique_name.should.equal '_uniquetest1'
20
- u.unique_name.should.equal '_uniquetest2'
21
- UniqueTest.new.unique_name.should.equal '_uniquetest1'
22
- end
23
-
24
- it 'has escape_html' do
25
- Temple::Utils.escape_html('<').should.equal '&lt;'
26
- end
27
-
28
- it 'should escape unsafe html strings' do
29
- with_html_safe do
30
- Temple::Utils.escape_html_safe('<').should.equal '&lt;'
31
- end
32
- end
33
-
34
- it 'should not escape safe html strings' do
35
- with_html_safe do
36
- Temple::Utils.escape_html_safe('<'.html_safe).should.equal '<'
37
- end
38
- end
39
- end