hamlit 1.7.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -3
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +25 -37
  5. data/CHANGELOG.md +18 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE.txt +23 -2
  8. data/README.md +106 -48
  9. data/REFERENCE.md +222 -0
  10. data/Rakefile +77 -19
  11. data/benchmark/boolean_attribute.haml +6 -0
  12. data/benchmark/class_attribute.haml +5 -0
  13. data/benchmark/common_attribute.haml +3 -0
  14. data/benchmark/data_attribute.haml +4 -0
  15. data/benchmark/dynamic_attributes/boolean_attribute.haml +4 -0
  16. data/benchmark/dynamic_attributes/class_attribute.haml +4 -0
  17. data/benchmark/dynamic_attributes/common_attribute.haml +2 -0
  18. data/benchmark/dynamic_attributes/data_attribute.haml +2 -0
  19. data/benchmark/dynamic_attributes/id_attribute.haml +2 -0
  20. data/benchmark/etc/attribute_builder.haml +5 -0
  21. data/benchmark/etc/real_sample.haml +888 -0
  22. data/benchmark/etc/real_sample.rb +11 -0
  23. data/benchmark/etc/static_analyzer.haml +1 -0
  24. data/benchmark/etc/tags.haml +3 -0
  25. data/benchmark/ext/build_data.rb +15 -0
  26. data/benchmark/ext/build_id.rb +13 -0
  27. data/benchmark/id_attribute.haml +3 -0
  28. data/benchmark/plain.haml +4 -0
  29. data/benchmark/script.haml +4 -0
  30. data/benchmark/slim/LICENSE +21 -0
  31. data/{benchmarks → benchmark/slim}/context.rb +2 -4
  32. data/benchmark/slim/run-benchmarks.rb +94 -0
  33. data/{benchmarks → benchmark/slim}/view.erb +3 -3
  34. data/{benchmarks → benchmark/slim}/view.haml +0 -0
  35. data/{benchmarks/view.escaped.slim → benchmark/slim/view.slim} +1 -1
  36. data/benchmark/string_interpolation.haml +2 -0
  37. data/benchmark/utils/benchmark_ips_extension.rb +43 -0
  38. data/bin/bench +85 -0
  39. data/bin/clone +14 -0
  40. data/bin/console +11 -0
  41. data/bin/lineprof +48 -0
  42. data/bin/ruby +3 -0
  43. data/bin/setup +7 -0
  44. data/bin/stackprof +27 -0
  45. data/{test → bin/test} +6 -10
  46. data/{bin → exe}/hamlit +0 -0
  47. data/ext/hamlit/extconf.rb +14 -0
  48. data/ext/hamlit/hamlit.c +512 -0
  49. data/ext/hamlit/houdini/.gitignore +3 -0
  50. data/ext/hamlit/houdini/COPYING +7 -0
  51. data/ext/hamlit/houdini/Makefile +79 -0
  52. data/ext/hamlit/houdini/README.md +59 -0
  53. data/ext/hamlit/houdini/buffer.c +249 -0
  54. data/ext/hamlit/houdini/buffer.h +113 -0
  55. data/ext/hamlit/houdini/houdini.h +46 -0
  56. data/ext/hamlit/houdini/houdini_href_e.c +115 -0
  57. data/ext/hamlit/houdini/houdini_html_e.c +90 -0
  58. data/ext/hamlit/houdini/houdini_html_u.c +122 -0
  59. data/ext/hamlit/houdini/houdini_js_e.c +90 -0
  60. data/ext/hamlit/houdini/houdini_js_u.c +60 -0
  61. data/ext/hamlit/houdini/houdini_uri_e.c +107 -0
  62. data/ext/hamlit/houdini/houdini_uri_u.c +68 -0
  63. data/ext/hamlit/houdini/houdini_xml_e.c +136 -0
  64. data/ext/hamlit/houdini/html_unescape.gperf +258 -0
  65. data/ext/hamlit/houdini/html_unescape.h +754 -0
  66. data/ext/hamlit/houdini/tools/build_table.py +13 -0
  67. data/ext/hamlit/houdini/tools/build_tables.c +51 -0
  68. data/ext/hamlit/houdini/tools/wikipedia_table.txt +2025 -0
  69. data/hamlit.gemspec +30 -31
  70. data/lib/hamlit.rb +3 -1
  71. data/lib/hamlit/attribute_builder.rb +12 -0
  72. data/lib/hamlit/cli.rb +44 -43
  73. data/lib/hamlit/compiler.rb +92 -16
  74. data/lib/hamlit/compiler/attribute_compiler.rb +148 -0
  75. data/lib/hamlit/compiler/children_compiler.rb +111 -0
  76. data/lib/hamlit/compiler/comment_compiler.rb +36 -0
  77. data/lib/hamlit/compiler/doctype_compiler.rb +45 -0
  78. data/lib/hamlit/compiler/script_compiler.rb +97 -0
  79. data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
  80. data/lib/hamlit/compiler/tag_compiler.rb +69 -0
  81. data/lib/hamlit/engine.rb +12 -7
  82. data/lib/hamlit/error.rb +14 -0
  83. data/lib/hamlit/escapable.rb +12 -0
  84. data/lib/hamlit/filters.rb +65 -0
  85. data/lib/hamlit/filters/base.rb +4 -62
  86. data/lib/hamlit/filters/coffee.rb +9 -7
  87. data/lib/hamlit/filters/css.rb +25 -8
  88. data/lib/hamlit/filters/erb.rb +4 -6
  89. data/lib/hamlit/filters/escaped.rb +11 -9
  90. data/lib/hamlit/filters/javascript.rb +25 -8
  91. data/lib/hamlit/filters/less.rb +9 -7
  92. data/lib/hamlit/filters/markdown.rb +5 -6
  93. data/lib/hamlit/filters/plain.rb +11 -15
  94. data/lib/hamlit/filters/preserve.rb +15 -5
  95. data/lib/hamlit/filters/ruby.rb +3 -5
  96. data/lib/hamlit/filters/sass.rb +9 -7
  97. data/lib/hamlit/filters/scss.rb +9 -7
  98. data/lib/hamlit/filters/text_base.rb +24 -0
  99. data/lib/hamlit/filters/tilt_base.rb +47 -0
  100. data/lib/hamlit/hash_parser.rb +107 -0
  101. data/lib/hamlit/html.rb +9 -6
  102. data/lib/hamlit/identity.rb +12 -0
  103. data/lib/hamlit/object_ref.rb +29 -0
  104. data/lib/hamlit/parser.rb +25 -142
  105. data/lib/hamlit/parser/MIT-LICENSE +20 -0
  106. data/lib/hamlit/parser/README.md +28 -0
  107. data/lib/hamlit/parser/haml_buffer.rb +348 -0
  108. data/lib/hamlit/parser/haml_compiler.rb +553 -0
  109. data/lib/hamlit/parser/haml_error.rb +61 -0
  110. data/lib/hamlit/parser/haml_helpers.rb +727 -0
  111. data/lib/hamlit/parser/haml_options.rb +286 -0
  112. data/lib/hamlit/parser/haml_parser.rb +801 -0
  113. data/lib/hamlit/parser/haml_util.rb +283 -0
  114. data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
  115. data/lib/hamlit/{helpers.rb → rails_helpers.rb} +2 -7
  116. data/lib/hamlit/rails_template.rb +30 -0
  117. data/lib/hamlit/railtie.rb +1 -12
  118. data/lib/hamlit/ruby_expression.rb +31 -0
  119. data/lib/hamlit/static_analyzer.rb +49 -0
  120. data/lib/hamlit/string_interpolation.rb +69 -0
  121. data/lib/hamlit/template.rb +8 -0
  122. data/lib/hamlit/utils.rb +9 -0
  123. data/lib/hamlit/version.rb +1 -1
  124. metadata +116 -324
  125. data/.rspec +0 -2
  126. data/benchmarks/benchmark.rb +0 -110
  127. data/benchmarks/view.slim +0 -17
  128. data/doc/README.md +0 -19
  129. data/doc/engine/indent.md +0 -48
  130. data/doc/engine/new_attribute.md +0 -77
  131. data/doc/engine/old_attributes.md +0 -198
  132. data/doc/engine/silent_script.md +0 -97
  133. data/doc/engine/tag.md +0 -48
  134. data/doc/engine/text.md +0 -64
  135. data/doc/faml/README.md +0 -16
  136. data/doc/faml/engine/indent.md +0 -48
  137. data/doc/faml/engine/old_attributes.md +0 -111
  138. data/doc/faml/engine/silent_script.md +0 -97
  139. data/doc/faml/engine/text.md +0 -59
  140. data/doc/faml/filters/erb.md +0 -24
  141. data/doc/faml/filters/javascript.md +0 -27
  142. data/doc/faml/filters/less.md +0 -57
  143. data/doc/faml/filters/plain.md +0 -25
  144. data/doc/filters/erb.md +0 -31
  145. data/doc/filters/javascript.md +0 -83
  146. data/doc/filters/less.md +0 -57
  147. data/doc/filters/markdown.md +0 -31
  148. data/doc/filters/plain.md +0 -25
  149. data/doc/haml/README.md +0 -15
  150. data/doc/haml/engine/new_attribute.md +0 -77
  151. data/doc/haml/engine/old_attributes.md +0 -142
  152. data/doc/haml/engine/tag.md +0 -48
  153. data/doc/haml/engine/text.md +0 -29
  154. data/doc/haml/filters/erb.md +0 -26
  155. data/doc/haml/filters/javascript.md +0 -76
  156. data/doc/haml/filters/markdown.md +0 -31
  157. data/lib/hamlit/attribute.rb +0 -78
  158. data/lib/hamlit/compilers/attributes.rb +0 -108
  159. data/lib/hamlit/compilers/comment.rb +0 -13
  160. data/lib/hamlit/compilers/doctype.rb +0 -39
  161. data/lib/hamlit/compilers/filter.rb +0 -53
  162. data/lib/hamlit/compilers/new_attribute.rb +0 -115
  163. data/lib/hamlit/compilers/old_attribute.rb +0 -241
  164. data/lib/hamlit/compilers/runtime_attribute.rb +0 -58
  165. data/lib/hamlit/compilers/script.rb +0 -31
  166. data/lib/hamlit/compilers/strip.rb +0 -19
  167. data/lib/hamlit/compilers/text.rb +0 -111
  168. data/lib/hamlit/concerns/attribute_builder.rb +0 -22
  169. data/lib/hamlit/concerns/balanceable.rb +0 -68
  170. data/lib/hamlit/concerns/deprecation.rb +0 -20
  171. data/lib/hamlit/concerns/error.rb +0 -31
  172. data/lib/hamlit/concerns/escapable.rb +0 -17
  173. data/lib/hamlit/concerns/included.rb +0 -28
  174. data/lib/hamlit/concerns/indentable.rb +0 -117
  175. data/lib/hamlit/concerns/lexable.rb +0 -32
  176. data/lib/hamlit/concerns/line_reader.rb +0 -62
  177. data/lib/hamlit/concerns/registerable.rb +0 -24
  178. data/lib/hamlit/concerns/string_interpolation.rb +0 -48
  179. data/lib/hamlit/concerns/whitespace.rb +0 -91
  180. data/lib/hamlit/filters/tilt.rb +0 -41
  181. data/lib/hamlit/parsers/attribute.rb +0 -71
  182. data/lib/hamlit/parsers/comment.rb +0 -30
  183. data/lib/hamlit/parsers/doctype.rb +0 -18
  184. data/lib/hamlit/parsers/filter.rb +0 -18
  185. data/lib/hamlit/parsers/multiline.rb +0 -58
  186. data/lib/hamlit/parsers/script.rb +0 -126
  187. data/lib/hamlit/parsers/tag.rb +0 -83
  188. data/lib/hamlit/parsers/text.rb +0 -28
  189. data/lib/hamlit/temple.rb +0 -9
  190. data/release +0 -6
  191. data/spec/Rakefile +0 -72
  192. data/spec/hamlit/engine/comment_spec.rb +0 -56
  193. data/spec/hamlit/engine/doctype_spec.rb +0 -19
  194. data/spec/hamlit/engine/error_spec.rb +0 -135
  195. data/spec/hamlit/engine/indent_spec.rb +0 -42
  196. data/spec/hamlit/engine/multiline_spec.rb +0 -44
  197. data/spec/hamlit/engine/new_attribute_spec.rb +0 -110
  198. data/spec/hamlit/engine/old_attributes_spec.rb +0 -404
  199. data/spec/hamlit/engine/script_spec.rb +0 -116
  200. data/spec/hamlit/engine/silent_script_spec.rb +0 -213
  201. data/spec/hamlit/engine/tag_spec.rb +0 -295
  202. data/spec/hamlit/engine/text_spec.rb +0 -239
  203. data/spec/hamlit/engine_spec.rb +0 -58
  204. data/spec/hamlit/filters/coffee_spec.rb +0 -60
  205. data/spec/hamlit/filters/css_spec.rb +0 -33
  206. data/spec/hamlit/filters/erb_spec.rb +0 -16
  207. data/spec/hamlit/filters/javascript_spec.rb +0 -82
  208. data/spec/hamlit/filters/less_spec.rb +0 -37
  209. data/spec/hamlit/filters/markdown_spec.rb +0 -30
  210. data/spec/hamlit/filters/plain_spec.rb +0 -15
  211. data/spec/hamlit/filters/ruby_spec.rb +0 -24
  212. data/spec/hamlit/filters/sass_spec.rb +0 -33
  213. data/spec/hamlit/filters/scss_spec.rb +0 -37
  214. data/spec/hamlit/haml_spec.rb +0 -910
  215. data/spec/rails/.gitignore +0 -18
  216. data/spec/rails/.rspec +0 -2
  217. data/spec/rails/Gemfile +0 -19
  218. data/spec/rails/README.rdoc +0 -28
  219. data/spec/rails/Rakefile +0 -6
  220. data/spec/rails/app/assets/images/.keep +0 -0
  221. data/spec/rails/app/assets/javascripts/application.js +0 -15
  222. data/spec/rails/app/assets/stylesheets/application.css +0 -15
  223. data/spec/rails/app/controllers/application_controller.rb +0 -8
  224. data/spec/rails/app/controllers/concerns/.keep +0 -0
  225. data/spec/rails/app/controllers/users_controller.rb +0 -23
  226. data/spec/rails/app/helpers/application_helper.rb +0 -2
  227. data/spec/rails/app/mailers/.keep +0 -0
  228. data/spec/rails/app/models/.keep +0 -0
  229. data/spec/rails/app/models/concerns/.keep +0 -0
  230. data/spec/rails/app/views/application/index.html.haml +0 -18
  231. data/spec/rails/app/views/layouts/application.html.haml +0 -12
  232. data/spec/rails/app/views/users/capture.html.haml +0 -5
  233. data/spec/rails/app/views/users/capture_haml.html.haml +0 -5
  234. data/spec/rails/app/views/users/form.html.haml +0 -2
  235. data/spec/rails/app/views/users/helpers.html.haml +0 -10
  236. data/spec/rails/app/views/users/index.html.haml +0 -9
  237. data/spec/rails/app/views/users/inline.html.haml +0 -6
  238. data/spec/rails/app/views/users/old_attributes.html.haml +0 -5
  239. data/spec/rails/app/views/users/safe_buffer.html.haml +0 -4
  240. data/spec/rails/app/views/users/whitespace.html.haml +0 -4
  241. data/spec/rails/bin/bundle +0 -3
  242. data/spec/rails/bin/rails +0 -8
  243. data/spec/rails/bin/rake +0 -8
  244. data/spec/rails/bin/setup +0 -29
  245. data/spec/rails/bin/spring +0 -15
  246. data/spec/rails/config.ru +0 -4
  247. data/spec/rails/config/application.rb +0 -34
  248. data/spec/rails/config/boot.rb +0 -3
  249. data/spec/rails/config/database.yml +0 -25
  250. data/spec/rails/config/environment.rb +0 -5
  251. data/spec/rails/config/environments/development.rb +0 -41
  252. data/spec/rails/config/environments/production.rb +0 -79
  253. data/spec/rails/config/environments/test.rb +0 -42
  254. data/spec/rails/config/initializers/assets.rb +0 -11
  255. data/spec/rails/config/initializers/backtrace_silencers.rb +0 -7
  256. data/spec/rails/config/initializers/cookies_serializer.rb +0 -3
  257. data/spec/rails/config/initializers/filter_parameter_logging.rb +0 -4
  258. data/spec/rails/config/initializers/inflections.rb +0 -16
  259. data/spec/rails/config/initializers/mime_types.rb +0 -4
  260. data/spec/rails/config/initializers/session_store.rb +0 -3
  261. data/spec/rails/config/initializers/wrap_parameters.rb +0 -14
  262. data/spec/rails/config/locales/en.yml +0 -24
  263. data/spec/rails/config/routes.rb +0 -16
  264. data/spec/rails/config/secrets.yml +0 -22
  265. data/spec/rails/db/schema.rb +0 -16
  266. data/spec/rails/db/seeds.rb +0 -7
  267. data/spec/rails/lib/assets/.keep +0 -0
  268. data/spec/rails/lib/tasks/.keep +0 -0
  269. data/spec/rails/log/.keep +0 -0
  270. data/spec/rails/public/404.html +0 -67
  271. data/spec/rails/public/422.html +0 -67
  272. data/spec/rails/public/500.html +0 -66
  273. data/spec/rails/public/favicon.ico +0 -0
  274. data/spec/rails/public/robots.txt +0 -5
  275. data/spec/rails/spec/hamlit_spec.rb +0 -123
  276. data/spec/rails/spec/rails_helper.rb +0 -56
  277. data/spec/rails/spec/spec_helper.rb +0 -91
  278. data/spec/rails/vendor/assets/javascripts/.keep +0 -0
  279. data/spec/rails/vendor/assets/stylesheets/.keep +0 -0
  280. data/spec/spec_helper.rb +0 -36
  281. data/spec/spec_helper/document_generator.rb +0 -93
  282. data/spec/spec_helper/render_helper.rb +0 -120
  283. data/spec/spec_helper/test_case.rb +0 -55
File without changes
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-agent: *
5
- # Disallow: /
@@ -1,123 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe 'Hamlit rails integration', type: :request do
4
- it 'renders views' do
5
- get root_path
6
- expect(response).to be_ok
7
- expect(response).to render_template('application/index')
8
- expect(response).to render_template('layouts/application')
9
- expect(response.body).to include('<span>Hamlit</span>')
10
- end
11
-
12
- it 'renders params' do
13
- get users_path(q: 'hello')
14
- expect(response.body).to include('<span>hello</span>')
15
- end
16
-
17
- it 'renders instance variable' do
18
- get users_path
19
- expect(response.body).to include('<p>k0kubun</p>')
20
- end
21
-
22
- it 'does not escape the object whose to_s returns SafeBuffer' do
23
- get safe_buffer_users_path
24
- expect(response.body).to include('<safe>')
25
- end
26
-
27
- it 'renders a complex old attributes' do
28
- get old_attributes_users_path
29
- expect(response.body).to include("<a value='foo 1'></a>")
30
- expect(response.body).to include("<span data-value='foo 2'></span>")
31
- expect(response.body).to include("<div class='foo' data-value='foo 3'></div>")
32
- expect(response.body).to include("<a data-value='foo 4'></a>")
33
- expect(response.body).to include("<a data-value='[{:count=&gt;1}]'></a>")
34
- end
35
-
36
- it 'renders multi-line script inside a tag' do
37
- get inline_users_path
38
- expect(response.body).to include('<span><a data-url="2" href="#">1</a></span>')
39
- expect(response.body).to include('<span><a data-url="4" href="#">3</a></span>')
40
- expect(response.body).to include('<span><a data-url="6" href="#">5</a></span>')
41
- expect(response.body).to include('<span><a data-url="6" href="#">5</a></span>')
42
- end
43
-
44
- describe 'escaping' do
45
- it 'escapes script' do
46
- get users_path(q: '<script>alert("a");</script>')
47
- expect(response.body).to include(
48
- '<span>&lt;script&gt;alert(&quot;a&quot;);&lt;/script&gt;</span>',
49
- )
50
- end
51
-
52
- it 'escapes block script' do
53
- get users_path(q: '<>')
54
- expect(response.body).to include(<<-HTML.strip_heredoc)
55
- <i>
56
- &lt;&gt;
57
- &lt;&gt;</i>
58
- HTML
59
- end
60
- end
61
-
62
- describe 'rails helpers' do
63
- it 'renders rails helper' do
64
- get users_path
65
- expect(response.body).to include('<a href="/">root</a>')
66
- end
67
-
68
- it 'allows capture method to work' do
69
- get capture_users_path
70
- expect(response.body).to include(<<-HTML.strip_heredoc)
71
- <div class='capture'><span>
72
- <p>Capture</p>
73
- </span>
74
- </div>
75
- HTML
76
- end
77
-
78
- it 'renders haml tags in the form block' do
79
- get form_users_path
80
- expect(response.body).to include('row')
81
- end
82
-
83
- it 'renders whitespace removal inside #capture' do
84
- get whitespace_users_path
85
- expect(response.body).to include('<a href="#">foo</a>')
86
- end
87
- end
88
-
89
- describe 'haml helpers' do
90
- it 'accepts find_and_preserve' do
91
- get helpers_users_path
92
- expect(response.body).to include(<<-HTML.strip_heredoc)
93
- Foo
94
- <pre>Bar&#x000A;Baz</pre>
95
- HTML
96
- end
97
-
98
- it 'accepts capture_haml' do
99
- get capture_users_path
100
- expect(response.body).to include(<<-HTML.strip_heredoc)
101
- <div class='capture'><span>
102
- <p>Capture</p>
103
- </span>
104
- </div>
105
- HTML
106
- end
107
-
108
- it 'renders succeed' do
109
- get helpers_users_path
110
- expect(response.body).to include('<i>succeed</i>&amp;')
111
- end
112
-
113
- it 'renders precede' do
114
- get helpers_users_path
115
- expect(response.body).to include('&amp;<i>precede</i>')
116
- end
117
-
118
- it 'renders surround' do
119
- get helpers_users_path
120
- expect(response.body).to include('&lt;<i>surround</i>&gt;')
121
- end
122
- end
123
- end
@@ -1,56 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV['RAILS_ENV'] ||= 'test'
3
- require 'spec_helper'
4
- require File.expand_path('../../config/environment', __FILE__)
5
- require 'rspec/rails'
6
- # Add additional requires below this line. Rails is not loaded until this point!
7
-
8
- # Requires supporting ruby files with custom matchers and macros, etc, in
9
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
10
- # run as spec files by default. This means that files in spec/support that end
11
- # in _spec.rb will both be required and run as specs, causing the specs to be
12
- # run twice. It is recommended that you do not name files matching this glob to
13
- # end with _spec.rb. You can configure this pattern with the --pattern
14
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
15
- #
16
- # The following line is provided for convenience purposes. It has the downside
17
- # of increasing the boot-up time by auto-requiring all files in the support
18
- # directory. Alternatively, in the individual `*_spec.rb` files, manually
19
- # require only the support files necessary.
20
- #
21
- # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
22
-
23
- # Checks for pending migrations before tests are run.
24
- # If you are not using ActiveRecord, you can remove this line.
25
- ActiveRecord::Migration.maintain_test_schema!
26
-
27
- RSpec.configure do |config|
28
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
29
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
30
-
31
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
32
- # examples within a transaction, remove the following line or assign false
33
- # instead of true.
34
- config.use_transactional_fixtures = true
35
-
36
- # RSpec Rails can automatically mix in different behaviours to your tests
37
- # based on their file location, for example enabling you to call `get` and
38
- # `post` in specs under `spec/controllers`.
39
- #
40
- # You can disable this behaviour by removing the line below, and instead
41
- # explicitly tag your specs with their type, e.g.:
42
- #
43
- # RSpec.describe UsersController, :type => :controller do
44
- # # ...
45
- # end
46
- #
47
- # The different available types are documented in the features, such as in
48
- # https://relishapp.com/rspec/rspec-rails/docs
49
- config.infer_spec_type_from_file_location!
50
- end
51
-
52
- # Require factories
53
- Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f }
54
-
55
- # Require support files
56
- Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
@@ -1,91 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause
4
- # this file to always be loaded, without a need to explicitly require it in any
5
- # files.
6
- #
7
- # Given that it is always loaded, you are encouraged to keep this file as
8
- # light-weight as possible. Requiring heavyweight dependencies from this file
9
- # will add to the boot time of your test suite on EVERY test run, even for an
10
- # individual file that may not need all of that loaded. Instead, consider making
11
- # a separate helper file that requires the additional dependencies and performs
12
- # the additional setup, and require it from the spec files that actually need
13
- # it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- end
33
-
34
- # rspec-mocks config goes here. You can use an alternate test double
35
- # library (such as bogus or mocha) by changing the `mock_with` option here.
36
- config.mock_with :rspec do |mocks|
37
- # Prevents you from mocking or stubbing a method that does not exist on
38
- # a real object. This is generally recommended, and will default to
39
- # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
41
- end
42
-
43
- # The settings below are suggested to provide a good initial experience
44
- # with RSpec, but feel free to customize to your heart's content.
45
- =begin
46
- # These two settings work together to allow you to limit a spec run
47
- # to individual examples or groups you care about by tagging them with
48
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
- # get run.
50
- config.filter_run :focus
51
- config.run_all_when_everything_filtered = true
52
-
53
- # Limits the available syntax to the non-monkey patched syntax that is
54
- # recommended. For more details, see:
55
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
- config.disable_monkey_patching!
59
-
60
- # This setting enables warnings. It's recommended, but in some cases may
61
- # be too noisy due to issues in dependencies.
62
- config.warnings = true
63
-
64
- # Many RSpec users commonly either run the entire suite or an individual
65
- # file, and it's useful to allow more verbose output when running an
66
- # individual spec file.
67
- if config.files_to_run.one?
68
- # Use the documentation formatter for detailed output,
69
- # unless a formatter has already been configured
70
- # (e.g. via a command-line flag).
71
- config.default_formatter = 'doc'
72
- end
73
-
74
- # Print the 10 slowest examples and example groups at the
75
- # end of the spec run, to help surface which specs are running
76
- # particularly slow.
77
- config.profile_examples = 10
78
-
79
- # Run specs in random order to surface order dependencies. If you find an
80
- # order dependency and want to debug it, you can fix the order by providing
81
- # the seed, which is printed after each run.
82
- # --seed 1234
83
- config.order = :random
84
-
85
- # Seed global randomization in this process using the `--seed` CLI option.
86
- # Setting this allows you to use `--seed` to deterministically reproduce
87
- # test failures related to randomization by passing the same `--seed` value
88
- # as the one that triggered the failure.
89
- Kernel.srand config.seed
90
- =end
91
- end
File without changes
File without changes
data/spec/spec_helper.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'coveralls'
2
- require 'simplecov'
3
- require 'unindent'
4
- require_relative 'spec_helper/document_generator'
5
- require_relative 'spec_helper/render_helper'
6
- require_relative 'spec_helper/test_case'
7
-
8
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
- SimpleCov::Formatter::HTMLFormatter,
10
- Coveralls::SimpleCov::Formatter
11
- ]
12
- SimpleCov.start
13
-
14
- RSpec.configure do |config|
15
- config.include RenderHelper
16
-
17
- config.expect_with :rspec do |expectations|
18
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
19
- end
20
-
21
- config.mock_with :rspec do |mocks|
22
- mocks.verify_partial_doubles = true
23
- end
24
-
25
- config.around(:each, skipdoc: true) do |example|
26
- TestCase.skipdoc do
27
- example.run
28
- end
29
- end
30
-
31
- config.after(:suite) do
32
- if DocumentGenerator.generate_docs?
33
- DocumentGenerator.generate_docs!
34
- end
35
- end
36
- end
@@ -1,93 +0,0 @@
1
- require 'singleton'
2
-
3
- class DocumentGenerator
4
- class << self
5
- def incompatibilities
6
- @incompatibilities ||= []
7
- end
8
-
9
- def generate_docs!
10
- prepare_dirs!
11
-
12
- [nil, 'haml', 'faml'].each do |impl|
13
- generate_toc!(impl)
14
- generate_doc!(impl)
15
- end
16
- end
17
-
18
- def generate_docs?
19
- ENV['AUTODOC']
20
- end
21
-
22
- def register_test!(test)
23
- incompatibilities << test unless @skipdoc
24
- end
25
-
26
- def skipdoc(&block)
27
- @skipdoc = true
28
- block.call
29
- ensure
30
- @skipdoc = false
31
- end
32
-
33
- private
34
-
35
- def generate_doc!(impl)
36
- incompatibilities_for(impl).group_by(&:doc_path).each do |path, tests|
37
- doc = tests.sort_by(&:lineno).map { |t| t.document(impl) }.join("\n")
38
- full_path = File.join(*[doc_dir, impl, path].compact)
39
- File.write(full_path, doc)
40
- end
41
- end
42
-
43
- def generate_toc!(impl = nil)
44
- path = File.join(*[doc_dir, impl, 'README.md'].compact)
45
- File.write(path, table_of_contents_for(impl))
46
- end
47
-
48
- def table_of_contents_for(impl = nil)
49
- toc = "# Hamlit incompatibilities\nThis is a document generated from RSpec test cases. "
50
- toc << "\n#{target_description(impl)}"
51
-
52
- incompatibilities_for(impl).group_by(&:dir).each do |dir, tests|
53
- toc << "\n\n## #{dir}\n"
54
- tests.map { |t| [t.spec_path, t.doc_path] }.uniq.each do |spec_path, doc_path|
55
- toc << "- [#{spec_path}](#{doc_path})\n"
56
- end
57
- end
58
- toc
59
- end
60
-
61
- def incompatibilities_for(impl)
62
- return incompatibilities unless impl
63
- incompatibilities.select { |t| t.send(:"#{impl}_html") != t.hamlit_html }
64
- end
65
-
66
- def target_description(impl)
67
- case impl
68
- when 'haml'
69
- 'Showing incompatibilities against [Haml](https://github.com/haml/haml).'
70
- when 'faml'
71
- 'Showing incompatibilities against [Faml](https://github.com/eagletmt/faml).'
72
- else
73
- 'Showing incompatibilities against [Haml](https://github.com/haml/haml) and [Faml](https://github.com/eagletmt/faml).'
74
- end
75
- end
76
-
77
- def prepare_dirs!
78
- system("rm -rf #{doc_dir}")
79
- incompatibilities.map(&:dir).uniq.each do |dir|
80
- system("mkdir -p #{File.join(doc_dir, dir)}")
81
- end
82
- %w[haml faml].each do |impl|
83
- incompatibilities.map(&:dir).uniq.each do |dir|
84
- system("mkdir -p #{File.join(doc_dir, impl, dir)}")
85
- end
86
- end
87
- end
88
-
89
- def doc_dir
90
- @doc_dir ||= File.expand_path('./doc')
91
- end
92
- end
93
- end
@@ -1,120 +0,0 @@
1
- require 'haml'
2
- require 'faml'
3
- require 'hamlit'
4
- require 'unindent'
5
-
6
- module RenderHelper
7
- DEFAULT_OPTIONS = { ugly: true, escape_html: true }.freeze
8
-
9
- def parse_string(str)
10
- Hamlit::Parser.new.call(str)
11
- end
12
-
13
- def render_string(str, options = {})
14
- eval Hamlit::Engine.new(options).call(str)
15
- end
16
-
17
- def assert_render(haml, html, options = {})
18
- errs = array_wrap(options.delete(:error_with) || [])
19
- impls = array_wrap(options.delete(:compatible_only) || [:haml, :faml] - errs)
20
- fails = [:haml, :faml] - impls - errs
21
-
22
- test = TestCase.new
23
- test.src_haml = haml.unindent
24
- test.hamlit_html = html.unindent
25
-
26
- expect(render_string(test.src_haml, options)).to eq(test.hamlit_html)
27
- impls.each { |i| expect_compatibility(i, test, options) }
28
- errs.each { |i| expect_compatibility(i, test, options, type: :error) }
29
- fails.each { |i| expect_compatibility(i, test, options, type: :failure) }
30
-
31
- if DocumentGenerator.generate_docs? && (errs.any? || fails.any?)
32
- write_caller!(test)
33
- DocumentGenerator.register_test!(test)
34
- end
35
- end
36
-
37
- def assert_parse(haml, &block)
38
- haml = haml.unindent
39
- ast = block.call
40
-
41
- expect(parse_string(haml)).to eq(ast)
42
- end
43
-
44
- def assert_compile(before, after)
45
- result = described_class.new.call(before)
46
- expect(result).to eq(after)
47
- end
48
-
49
- private
50
-
51
- def write_caller!(test)
52
- example = RSpec.current_example
53
- test.lineno = example.metadata[:line_number]
54
- test.dir, test.file = example.file_path.gsub(%r{^.+spec/hamlit/}, '').split('/')
55
- end
56
-
57
- def expect_compatibility(impl, test, options, type: :success)
58
- case impl
59
- when :haml
60
- expect_haml(impl, test, options, type)
61
- when :faml
62
- expect_faml(impl, test, options, type)
63
- end
64
- end
65
-
66
- def expect_haml(impl, test, options, type)
67
- expect_implementation(impl, test, options, type) do |test, options|
68
- options = DEFAULT_OPTIONS.merge(options)
69
- Haml::Engine.new(test.src_haml, options).render(Object.new, {})
70
- end
71
- end
72
-
73
- def expect_faml(impl, test, options, type)
74
- expect_implementation(impl, test, options, type) do |test, options|
75
- options = options.dup
76
- options.delete(:escape_html)
77
- eval Faml::Engine.new(options).call(test.src_haml)
78
- end
79
- end
80
-
81
- def expect_implementation(impl, test, options, type, &block)
82
- if type == :error
83
- expect_any_error { block.call(test, options) }
84
- begin
85
- block.call(test, options)
86
- rescue Exception => e
87
- err = "#{e.class}: #{e.message}"
88
- test.send(:"#{impl}_html=", err)
89
- end
90
- return
91
- end
92
-
93
- result = block.call(test, options)
94
- test.send(:"#{impl}_html=", result)
95
-
96
- case type
97
- when :success
98
- expect(test.hamlit_html).to eq(result)
99
- when :failure
100
- expect(test.hamlit_html).to_not eq(result)
101
- end
102
- end
103
-
104
- def expect_any_error(&block)
105
- origin = RSpec::Expectations.configuration.warn_about_potential_false_positives?
106
- RSpec::Expectations.configuration.warn_about_potential_false_positives = false
107
- expect { block.call(test, options) }.to raise_error
108
- ensure
109
- RSpec::Expectations.configuration.warn_about_potential_false_positives = origin
110
- end
111
-
112
- def array_wrap(arr)
113
- return arr if arr.is_a?(Array)
114
- [arr]
115
- end
116
-
117
- def tests
118
- @tests ||= []
119
- end
120
- end