hamlit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +34 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +23 -0
  7. data/README.md +45 -0
  8. data/Rakefile +34 -0
  9. data/benchmarks/benchmark.rb +94 -0
  10. data/benchmarks/context.rb +13 -0
  11. data/benchmarks/view.erb +23 -0
  12. data/benchmarks/view.haml +18 -0
  13. data/benchmarks/view.rbhtml +23 -0
  14. data/benchmarks/view.slim +17 -0
  15. data/bin/hamlit +6 -0
  16. data/hamlit.gemspec +40 -0
  17. data/lib/hamlit/attribute.rb +31 -0
  18. data/lib/hamlit/cli.rb +89 -0
  19. data/lib/hamlit/compiler.rb +24 -0
  20. data/lib/hamlit/compilers/attributes.rb +78 -0
  21. data/lib/hamlit/compilers/comment.rb +13 -0
  22. data/lib/hamlit/compilers/doctype.rb +39 -0
  23. data/lib/hamlit/compilers/dynamic.rb +9 -0
  24. data/lib/hamlit/compilers/filter.rb +53 -0
  25. data/lib/hamlit/compilers/new_attribute.rb +107 -0
  26. data/lib/hamlit/compilers/old_attribute.rb +147 -0
  27. data/lib/hamlit/compilers/preserve.rb +10 -0
  28. data/lib/hamlit/compilers/script.rb +31 -0
  29. data/lib/hamlit/compilers/strip.rb +30 -0
  30. data/lib/hamlit/compilers/text.rb +15 -0
  31. data/lib/hamlit/concerns/attribute_builder.rb +21 -0
  32. data/lib/hamlit/concerns/balanceable.rb +59 -0
  33. data/lib/hamlit/concerns/deprecation.rb +20 -0
  34. data/lib/hamlit/concerns/error.rb +27 -0
  35. data/lib/hamlit/concerns/escapable.rb +17 -0
  36. data/lib/hamlit/concerns/included.rb +28 -0
  37. data/lib/hamlit/concerns/indentable.rb +53 -0
  38. data/lib/hamlit/concerns/line_reader.rb +60 -0
  39. data/lib/hamlit/concerns/registerable.rb +24 -0
  40. data/lib/hamlit/concerns/ripperable.rb +20 -0
  41. data/lib/hamlit/concerns/string_interpolation.rb +48 -0
  42. data/lib/hamlit/engine.rb +42 -0
  43. data/lib/hamlit/filters/base.rb +44 -0
  44. data/lib/hamlit/filters/coffee.rb +12 -0
  45. data/lib/hamlit/filters/css.rb +34 -0
  46. data/lib/hamlit/filters/erb.rb +11 -0
  47. data/lib/hamlit/filters/escaped.rb +19 -0
  48. data/lib/hamlit/filters/javascript.rb +34 -0
  49. data/lib/hamlit/filters/less.rb +12 -0
  50. data/lib/hamlit/filters/markdown.rb +11 -0
  51. data/lib/hamlit/filters/plain.rb +21 -0
  52. data/lib/hamlit/filters/preserve.rb +11 -0
  53. data/lib/hamlit/filters/ruby.rb +11 -0
  54. data/lib/hamlit/filters/sass.rb +12 -0
  55. data/lib/hamlit/filters/scss.rb +12 -0
  56. data/lib/hamlit/filters/tilt.rb +41 -0
  57. data/lib/hamlit/helpers.rb +38 -0
  58. data/lib/hamlit/html/pretty.rb +49 -0
  59. data/lib/hamlit/html/ugly.rb +10 -0
  60. data/lib/hamlit/parser.rb +123 -0
  61. data/lib/hamlit/parsers/attribute.rb +52 -0
  62. data/lib/hamlit/parsers/comment.rb +27 -0
  63. data/lib/hamlit/parsers/doctype.rb +18 -0
  64. data/lib/hamlit/parsers/filter.rb +18 -0
  65. data/lib/hamlit/parsers/multiline.rb +54 -0
  66. data/lib/hamlit/parsers/script.rb +93 -0
  67. data/lib/hamlit/parsers/tag.rb +71 -0
  68. data/lib/hamlit/parsers/text.rb +11 -0
  69. data/lib/hamlit/parsers/whitespace.rb +38 -0
  70. data/lib/hamlit/railtie.rb +21 -0
  71. data/lib/hamlit/template.rb +9 -0
  72. data/lib/hamlit/version.rb +3 -0
  73. data/lib/hamlit.rb +8 -0
  74. data/spec/Rakefile +79 -0
  75. data/spec/hamlit/compilers/script_spec.rb +46 -0
  76. data/spec/hamlit/engine/comment_spec.rb +29 -0
  77. data/spec/hamlit/engine/doctype_spec.rb +19 -0
  78. data/spec/hamlit/engine/error_spec.rb +47 -0
  79. data/spec/hamlit/engine/multiline_spec.rb +44 -0
  80. data/spec/hamlit/engine/new_attribute_spec.rb +19 -0
  81. data/spec/hamlit/engine/old_attributes_spec.rb +85 -0
  82. data/spec/hamlit/engine/preservation_spec.rb +11 -0
  83. data/spec/hamlit/engine/script_spec.rb +87 -0
  84. data/spec/hamlit/engine/silent_script_spec.rb +135 -0
  85. data/spec/hamlit/engine/tag_spec.rb +210 -0
  86. data/spec/hamlit/engine/text_spec.rb +29 -0
  87. data/spec/hamlit/engine_spec.rb +20 -0
  88. data/spec/hamlit/filters/coffee_spec.rb +41 -0
  89. data/spec/hamlit/filters/css_spec.rb +33 -0
  90. data/spec/hamlit/filters/erb_spec.rb +16 -0
  91. data/spec/hamlit/filters/javascript_spec.rb +82 -0
  92. data/spec/hamlit/filters/less_spec.rb +22 -0
  93. data/spec/hamlit/filters/markdown_spec.rb +28 -0
  94. data/spec/hamlit/filters/ruby_spec.rb +24 -0
  95. data/spec/hamlit/filters/sass_spec.rb +37 -0
  96. data/spec/hamlit/filters/scss_spec.rb +21 -0
  97. data/spec/hamlit/ugly_spec.rb +912 -0
  98. data/spec/rails/.gitignore +17 -0
  99. data/spec/rails/.rspec +2 -0
  100. data/spec/rails/Gemfile +19 -0
  101. data/spec/rails/Gemfile.lock +177 -0
  102. data/spec/rails/README.rdoc +28 -0
  103. data/spec/rails/Rakefile +6 -0
  104. data/spec/rails/app/assets/images/.keep +0 -0
  105. data/spec/rails/app/assets/javascripts/application.js +15 -0
  106. data/spec/rails/app/assets/stylesheets/application.css +15 -0
  107. data/spec/rails/app/controllers/application_controller.rb +8 -0
  108. data/spec/rails/app/controllers/concerns/.keep +0 -0
  109. data/spec/rails/app/controllers/users_controller.rb +20 -0
  110. data/spec/rails/app/helpers/application_helper.rb +2 -0
  111. data/spec/rails/app/mailers/.keep +0 -0
  112. data/spec/rails/app/models/.keep +0 -0
  113. data/spec/rails/app/models/concerns/.keep +0 -0
  114. data/spec/rails/app/views/application/index.html.haml +15 -0
  115. data/spec/rails/app/views/layouts/application.html.haml +12 -0
  116. data/spec/rails/app/views/users/capture.html.haml +5 -0
  117. data/spec/rails/app/views/users/capture_haml.html.haml +5 -0
  118. data/spec/rails/app/views/users/form.html.haml +2 -0
  119. data/spec/rails/app/views/users/helpers.html.haml +1 -0
  120. data/spec/rails/app/views/users/index.html.haml +9 -0
  121. data/spec/rails/app/views/users/safe_buffer.html.haml +4 -0
  122. data/spec/rails/bin/bundle +3 -0
  123. data/spec/rails/bin/rails +8 -0
  124. data/spec/rails/bin/rake +8 -0
  125. data/spec/rails/bin/setup +29 -0
  126. data/spec/rails/bin/spring +15 -0
  127. data/spec/rails/config/application.rb +34 -0
  128. data/spec/rails/config/boot.rb +3 -0
  129. data/spec/rails/config/database.yml +25 -0
  130. data/spec/rails/config/environment.rb +5 -0
  131. data/spec/rails/config/environments/development.rb +41 -0
  132. data/spec/rails/config/environments/production.rb +79 -0
  133. data/spec/rails/config/environments/test.rb +42 -0
  134. data/spec/rails/config/initializers/assets.rb +11 -0
  135. data/spec/rails/config/initializers/backtrace_silencers.rb +7 -0
  136. data/spec/rails/config/initializers/cookies_serializer.rb +3 -0
  137. data/spec/rails/config/initializers/filter_parameter_logging.rb +4 -0
  138. data/spec/rails/config/initializers/inflections.rb +16 -0
  139. data/spec/rails/config/initializers/mime_types.rb +4 -0
  140. data/spec/rails/config/initializers/session_store.rb +3 -0
  141. data/spec/rails/config/initializers/wrap_parameters.rb +14 -0
  142. data/spec/rails/config/locales/en.yml +23 -0
  143. data/spec/rails/config/routes.rb +13 -0
  144. data/spec/rails/config/secrets.yml +22 -0
  145. data/spec/rails/config.ru +4 -0
  146. data/spec/rails/db/schema.rb +16 -0
  147. data/spec/rails/db/seeds.rb +7 -0
  148. data/spec/rails/lib/assets/.keep +0 -0
  149. data/spec/rails/lib/tasks/.keep +0 -0
  150. data/spec/rails/log/.keep +0 -0
  151. data/spec/rails/public/404.html +67 -0
  152. data/spec/rails/public/422.html +67 -0
  153. data/spec/rails/public/500.html +66 -0
  154. data/spec/rails/public/favicon.ico +0 -0
  155. data/spec/rails/public/robots.txt +5 -0
  156. data/spec/rails/spec/hamlit_spec.rb +87 -0
  157. data/spec/rails/spec/rails_helper.rb +56 -0
  158. data/spec/rails/spec/spec_helper.rb +91 -0
  159. data/spec/rails/vendor/assets/javascripts/.keep +0 -0
  160. data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
  161. data/spec/spec_helper.rb +48 -0
  162. metadata +560 -0
@@ -0,0 +1,29 @@
1
+ describe Hamlit::Engine do
2
+ describe 'text' do
3
+ it 'renders string interpolation' do
4
+ assert_render(<<-'HAML', <<-HTML)
5
+ #{ "a#{3}a" }a" #{["1", 2]} b " !
6
+ a#{{ a: 3 }}
7
+ <ht#{2}ml>
8
+ HAML
9
+ a3aa" ["1", 2] b " !
10
+ a{:a=>3}
11
+ <ht2ml>
12
+ HTML
13
+ end
14
+
15
+ it 'renders . or # which is not continued by tag name' do
16
+ assert_render(<<-HAML, <<-HTML)
17
+ .
18
+ .*
19
+ #
20
+ #+
21
+ HAML
22
+ .
23
+ .*
24
+ #
25
+ #+
26
+ HTML
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ describe Hamlit::Engine do
2
+ describe '.new' do
3
+ subject { described_class.new(options) }
4
+
5
+ let(:buffer) { '_a' }
6
+ let(:options) do
7
+ {
8
+ buffer: buffer,
9
+ generator: Temple::Generators::ArrayBuffer,
10
+ ugly: true,
11
+ }
12
+ end
13
+
14
+ it 'accepts generator valid options' do
15
+ expect(subject.call('')).to eq(
16
+ "#{buffer} = []; ; #{buffer} = #{buffer}.join",
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ describe Hamlit::Filters::Coffee do
2
+ describe '#compile' do
3
+ it 'renders coffee filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :coffee
6
+ foo = ->
7
+ alert('hello')
8
+ HAML
9
+ <script>
10
+ (function() {
11
+ var foo;
12
+
13
+ foo = function() {
14
+ return alert('hello');
15
+ };
16
+
17
+ }).call(this);
18
+ </script>
19
+ HTML
20
+ end
21
+
22
+ it 'renders coffeescript filter' do
23
+ assert_render(<<-HAML, <<-HTML)
24
+ :coffee
25
+ foo = ->
26
+ alert('hello')
27
+ HAML
28
+ <script>
29
+ (function() {
30
+ var foo;
31
+
32
+ foo = function() {
33
+ return alert('hello');
34
+ };
35
+
36
+ }).call(this);
37
+ </script>
38
+ HTML
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ describe Hamlit::Filters::Css do
2
+ describe '#compile' do
3
+ it 'renders css' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :css
6
+ .foo {
7
+ width: 100px;
8
+ }
9
+ HAML
10
+ <style>
11
+ .foo {
12
+ width: 100px;
13
+ }
14
+ </style>
15
+ HTML
16
+ end
17
+
18
+ it 'parses string interpolation' do
19
+ assert_render(<<-'HAML', <<-HTML)
20
+ :css
21
+ .foo {
22
+ width: #{100 * 3}px;
23
+ }
24
+ HAML
25
+ <style>
26
+ .foo {
27
+ width: 300px;
28
+ }
29
+ </style>
30
+ HTML
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ describe Hamlit::Filters::Erb do
2
+ describe '#compile' do
3
+ it 'renders erb filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :erb
6
+ <% if true %>
7
+ ok
8
+ <% else %>
9
+ ng
10
+ <% end %>
11
+ HAML
12
+ ok
13
+ HTML
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,82 @@
1
+ describe Hamlit::Filters::Javascript do
2
+ describe '#compile' do
3
+ it 'just renders script tag for empty filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ before
6
+ :javascript
7
+ after
8
+ HAML
9
+ before
10
+ <script>
11
+
12
+ </script>
13
+ after
14
+ HTML
15
+ end
16
+
17
+ it 'compiles javascript filter' do
18
+ assert_render(<<-HAML, <<-HTML)
19
+ before
20
+ :javascript
21
+ alert('hello');
22
+ after
23
+ HAML
24
+ before
25
+ <script>
26
+ alert('hello');
27
+ </script>
28
+ after
29
+ HTML
30
+ end
31
+
32
+ it 'accepts illegal indentation' do
33
+ assert_render(<<-HAML, <<-HTML)
34
+ :javascript
35
+ if {
36
+ alert('hello');
37
+ }
38
+ :javascript
39
+ if {
40
+ alert('hello');
41
+ }
42
+ HAML
43
+ <script>
44
+ if {
45
+ alert('hello');
46
+ }
47
+ </script>
48
+ <script>
49
+ if {
50
+ alert('hello');
51
+ }
52
+ </script>
53
+ HTML
54
+ end
55
+
56
+ it 'accepts illegal indentation' do
57
+ assert_render(<<-HAML, <<-HTML)
58
+ :javascript
59
+ if {
60
+ alert('a');
61
+ }
62
+ HAML
63
+ <script>
64
+ if {
65
+ alert('a');
66
+ }
67
+ </script>
68
+ HTML
69
+ end
70
+
71
+ it 'parses string interpolation' do
72
+ assert_render(<<-'HAML', <<-HTML)
73
+ :javascript
74
+ var a = #{[1, 2]};
75
+ HAML
76
+ <script>
77
+ var a = [1, 2];
78
+ </script>
79
+ HTML
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,22 @@
1
+ describe Hamlit::Filters::Less do
2
+ describe '#compile' do
3
+ it 'renders less filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :less
6
+ .users_controller {
7
+ .show_action {
8
+ margin: 10px;
9
+ padding: 20px;
10
+ }
11
+ }
12
+ HAML
13
+ <style>
14
+ .users_controller .show_action {
15
+ margin: 10px;
16
+ padding: 20px;
17
+ }
18
+ </style>
19
+ HTML
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ describe Hamlit::Filters::Markdown do
2
+ describe '#compile' do
3
+ it 'renders markdown filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :markdown
6
+ # Hamlit
7
+ Yet another haml implementation
8
+ HAML
9
+ <h1>Hamlit</h1>
10
+
11
+ <p>Yet another haml implementation</p>
12
+ HTML
13
+ end
14
+
15
+ it 'renders markdown filter with string interpolation' do
16
+ assert_render(<<-'HAML', <<-HTML)
17
+ - project = 'Hamlit'
18
+ :markdown
19
+ # #{project}
20
+ Yet another haml implementation
21
+ HAML
22
+ <h1>Hamlit</h1>
23
+
24
+ <p>Yet another haml implementation</p>
25
+ HTML
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hamlit::Filters::Ruby do
4
+ it 'renders ruby filter' do
5
+ assert_render(<<-HAML, <<-HTML)
6
+ :ruby
7
+ hello
8
+ HAML
9
+ hello
10
+ HTML
11
+ end
12
+
13
+ it 'renders ruby filter' do
14
+ assert_render(<<-HAML, <<-HTML)
15
+ :ruby
16
+ hash = {
17
+ a: 3,
18
+ }
19
+ = hash[:a]
20
+ HAML
21
+ 3
22
+ HTML
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ describe Hamlit::Filters::Sass do
2
+ describe '#compile' do
3
+ it 'renders sass filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :sass
6
+ .users_controller
7
+ .show_action
8
+ margin: 10px
9
+ padding: 20px
10
+ HAML
11
+ <style>
12
+ .users_controller .show_action {
13
+ margin: 10px;
14
+ padding: 20px; }
15
+ </style>
16
+ HTML
17
+ end
18
+
19
+ it 'renders sass filter with string interpolation' do
20
+ assert_render(<<-'HAML', <<-HTML)
21
+ - width = 1200
22
+ - height = 800
23
+ :sass
24
+ .users_controller
25
+ .show_action
26
+ width: #{width}px
27
+ height: #{height}px
28
+ HAML
29
+ <style>
30
+ .users_controller .show_action {
31
+ width: 1200px;
32
+ height: 800px; }
33
+ </style>
34
+ HTML
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ describe Hamlit::Filters::Scss do
2
+ describe '#compile' do
3
+ it 'renders scss filter' do
4
+ assert_render(<<-HAML, <<-HTML)
5
+ :scss
6
+ .users_controller {
7
+ .show_action {
8
+ margin: 10px;
9
+ padding: 20px;
10
+ }
11
+ }
12
+ HAML
13
+ <style>
14
+ .users_controller .show_action {
15
+ margin: 10px;
16
+ padding: 20px; }
17
+ </style>
18
+ HTML
19
+ end
20
+ end
21
+ end