brakeman 7.1.2 → 8.0.0

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +11 -0
  3. data/README.md +1 -1
  4. data/bundle/load.rb +2 -2
  5. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/CHANGELOG +111 -0
  6. data/bundle/ruby/3.2.0/gems/{erubis-2.7.0 → erubi-1.13.1}/MIT-LICENSE +1 -0
  7. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/README.rdoc +151 -0
  8. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_block.rb +91 -0
  9. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_end.rb +58 -0
  10. data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi.rb +299 -0
  11. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/asciidoc.rb +12 -5
  12. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/babel.rb +5 -0
  13. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/builder.rb +4 -0
  14. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/coffee.rb +14 -4
  15. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/commonmarker.rb +41 -0
  16. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/csv.rb +63 -0
  17. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/erb.rb +130 -0
  18. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/erubi.rb +41 -8
  19. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/etanni.rb +7 -0
  20. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/haml.rb +67 -1
  21. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/kramdown.rb +59 -0
  22. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/liquid.rb +93 -0
  23. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/livescript.rb +11 -4
  24. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/mapping.rb +8 -8
  25. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/markaby.rb +11 -2
  26. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/nokogiri.rb +13 -2
  27. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/pandoc.rb +81 -0
  28. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/pipeline.rb +6 -1
  29. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/plain.rb +5 -1
  30. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/prawn.rb +17 -6
  31. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/radius.rb +96 -0
  32. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdiscount.rb +82 -0
  33. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdoc.rb +33 -0
  34. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcarpet.rb +73 -0
  35. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcloth.rb +40 -0
  36. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rst-pandoc.rb +33 -0
  37. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/sass.rb +16 -3
  38. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/slim.rb +18 -0
  39. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/string.rb +10 -2
  40. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/template.rb +5 -5
  41. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/typescript.rb +5 -0
  42. data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/yajl.rb +91 -0
  43. data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt.rb +1 -2
  44. data/lib/brakeman/app_tree.rb +7 -2
  45. data/lib/brakeman/checks/check_model_attributes.rb +1 -1
  46. data/lib/brakeman/checks/check_render.rb +1 -27
  47. data/lib/brakeman/checks/check_render_rce.rb +43 -0
  48. data/lib/brakeman/checks/check_session_settings.rb +1 -1
  49. data/lib/brakeman/checks.rb +31 -25
  50. data/lib/brakeman/commandline.rb +6 -1
  51. data/lib/brakeman/file_parser.rb +3 -2
  52. data/lib/brakeman/logger.rb +264 -0
  53. data/lib/brakeman/options.rb +0 -9
  54. data/lib/brakeman/parsers/rails_erubi.rb +82 -0
  55. data/lib/brakeman/parsers/template_parser.rb +7 -15
  56. data/lib/brakeman/processor.rb +2 -2
  57. data/lib/brakeman/processors/controller_alias_processor.rb +1 -1
  58. data/lib/brakeman/processors/controller_processor.rb +3 -3
  59. data/lib/brakeman/processors/{erubis_template_processor.rb → erubi_template_procesor.rb} +3 -3
  60. data/lib/brakeman/processors/lib/rails2_config_processor.rb +4 -3
  61. data/lib/brakeman/processors/lib/rails2_route_processor.rb +1 -1
  62. data/lib/brakeman/processors/lib/render_helper.rb +1 -1
  63. data/lib/brakeman/processors/lib/render_path.rb +1 -1
  64. data/lib/brakeman/processors/model_processor.rb +1 -1
  65. data/lib/brakeman/report/ignore/config.rb +1 -1
  66. data/lib/brakeman/scanner.rb +25 -49
  67. data/lib/brakeman/tracker/collection.rb +12 -2
  68. data/lib/brakeman/tracker/config.rb +17 -13
  69. data/lib/brakeman/tracker/constants.rb +17 -2
  70. data/lib/brakeman/tracker/controller.rb +1 -1
  71. data/lib/brakeman/tracker.rb +7 -15
  72. data/lib/brakeman/version.rb +1 -1
  73. data/lib/brakeman.rb +89 -49
  74. metadata +51 -80
  75. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/CHANGES.txt +0 -828
  76. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/README.txt +0 -102
  77. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis +0 -3468
  78. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis-run.rb +0 -132
  79. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/inline-require +0 -179
  80. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/context.rb +0 -83
  81. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/converter.rb +0 -357
  82. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ec.rb +0 -117
  83. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ecpp.rb +0 -113
  84. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejava.rb +0 -110
  85. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejavascript.rb +0 -119
  86. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/enhanced.rb +0 -126
  87. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eperl.rb +0 -95
  88. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ephp.rb +0 -99
  89. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eruby.rb +0 -125
  90. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/escheme.rb +0 -114
  91. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/optimized.rb +0 -127
  92. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine.rb +0 -120
  93. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/enhancer.rb +0 -723
  94. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/error.rb +0 -23
  95. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb +0 -88
  96. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/generator.rb +0 -85
  97. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helper.rb +0 -47
  98. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_form_helper.rb +0 -197
  99. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_helper.rb +0 -353
  100. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/local-setting.rb +0 -9
  101. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/main.rb +0 -516
  102. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/preprocessing.rb +0 -58
  103. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/tiny.rb +0 -144
  104. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/util.rb +0 -22
  105. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis.rb +0 -73
  106. data/bundle/ruby/3.2.0/gems/erubis-2.7.0/setup.rb +0 -1331
  107. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/creole.rb +0 -16
  108. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/csv.rb +0 -53
  109. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/erb.rb +0 -65
  110. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/kramdown.rb +0 -13
  111. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/liquid.rb +0 -37
  112. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/pandoc.rb +0 -39
  113. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/radius.rb +0 -41
  114. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdiscount.rb +0 -23
  115. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdoc.rb +0 -11
  116. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcarpet.rb +0 -31
  117. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcloth.rb +0 -13
  118. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rst-pandoc.rb +0 -10
  119. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/slim.rb +0 -5
  120. data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/yajl.rb +0 -81
  121. data/lib/brakeman/parsers/erubis_patch.rb +0 -11
  122. data/lib/brakeman/parsers/rails2_erubis.rb +0 -9
  123. data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +0 -52
  124. data/lib/brakeman/parsers/rails3_erubis.rb +0 -85
  125. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/COPYING +0 -0
  126. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_emacs_org.rb +0 -0
  127. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_handlebars.rb +0 -0
  128. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_jbuilder.rb +0 -0
  129. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_org.rb +0 -0
  130. /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/cli.rb +0 -0
@@ -1,4 +1,70 @@
1
1
  # frozen_string_literal: true
2
+
3
+ # = Haml (<tt>haml</tt>)
4
+ #
5
+ # {Haml}[https://haml.info] is a markup language that’s used to cleanly and simply describe
6
+ # the HTML of any web document without the use of inline code. Haml functions as
7
+ # a replacement for inline page templating systems such as PHP, ASP, and ERB, the
8
+ # templating language used in most Ruby on Rails applications. However, Haml
9
+ # avoids the need for explicitly coding HTML into the template, because it itself
10
+ # is a description of the HTML, with some code to generate dynamic content.
11
+ # ({more}[http://haml.info/about.html)]
12
+ #
13
+ # === Example
14
+ #
15
+ # %html
16
+ # %head
17
+ # %title= @title
18
+ # %body
19
+ # %h1
20
+ # Hello
21
+ # = world + '!'
22
+ #
23
+ # === Usage
24
+ #
25
+ # The <tt>Tilt::HamlTemplate</tt> class is registered for all files ending in <tt>.haml</tt>
26
+ # by default. Haml templates support custom evaluation scopes and locals:
27
+ #
28
+ # >> require 'haml'
29
+ # >> template = Tilt.new('hello.haml')
30
+ # => #<Tilt::HamlTemplate @file='hello.haml'>
31
+ # >> @title = "Hello Haml!"
32
+ # >> template.render(self, :world => 'Haml!')
33
+ # => "
34
+ # <html>
35
+ # <head>
36
+ # <title>Hello Haml!</title>
37
+ # </head>
38
+ # <body>
39
+ # <h1>Hello Haml!</h1>
40
+ # </body>
41
+ # </html>"
42
+ #
43
+ # Or, use the <tt>Tilt::HamlTemplate</tt> class directly to process strings:
44
+ #
45
+ # >> require 'haml'
46
+ # >> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
47
+ # => #<Tilt::HamlTemplate @file=nil ...>
48
+ # >> template.render
49
+ # => "<h1>Hello Haml!</h1>"
50
+ #
51
+ # __NOTE:__ It's suggested that your program <tt>require 'haml'</tt> at load time when
52
+ # using this template engine within a threaded environment.
53
+ #
54
+ # === Options
55
+ #
56
+ # Please see the {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options] for all available options.
57
+ #
58
+ # === See also
59
+ #
60
+ # * {#haml.docs}[http://haml.info/docs.html]
61
+ # * {Haml Tutorial}[http://haml.info/tutorial.html]
62
+ # * {Haml Reference}[http://haml.info/docs/yardoc/file.HAML_REFERENCE.html]
63
+ #
64
+ # === Related module
65
+ #
66
+ # * Tilt::HamlTemplate
67
+
2
68
  require_relative 'template'
3
69
  require 'haml'
4
70
 
@@ -12,7 +78,7 @@ module Tilt
12
78
  class HamlTemplate < Template
13
79
  self.default_mime_type = 'text/html'
14
80
 
15
- # `Gem::Version.correct?` may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
81
+ # <tt>Gem::Version.correct?</tt> may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct.
16
82
  if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2')
17
83
  def prepare
18
84
  @options[:filename] = eval_file
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
4
+ #
5
+ # Markdown is a lightweight markup language, created by John Gruber
6
+ # and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
7
+ # is used. Marking up plain text with Markdown markup is easy and Markdown
8
+ # formatted texts are readable.
9
+ #
10
+ # === Example
11
+ #
12
+ # Hello Markdown Templates
13
+ # ========================
14
+ #
15
+ # Hello World. This is a paragraph.
16
+ #
17
+ # === Usage
18
+ #
19
+ # To wrap a Markdown formatted document with a layout:
20
+ #
21
+ # layout = Tilt['erb'].new do
22
+ # "<!doctype html><title></title><%= yield %>"
23
+ # end
24
+ # data = Tilt['md'].new { "# hello tilt" }
25
+ # layout.render { data.render }
26
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
27
+ #
28
+ # === Options
29
+ #
30
+ # Every implementation of Markdown *should* support these options, but there are
31
+ # some known problems with the Kramdown engine.
32
+ #
33
+ # ==== <tt>:smartypants => true|false</tt>
34
+ #
35
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
36
+ #
37
+ # In Kramdown this option only applies to smart quotes. It will apply a
38
+ # subset of Smarty Pants (e.g. <tt>...</tt> to <tt>…</tt>) regardless of any option.
39
+ #
40
+ # ==== <tt>:escape_html => true|false</tt>
41
+ #
42
+ # Kramdown doesn't support this option.
43
+ #
44
+ # === See also
45
+ #
46
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
47
+ # * {Kramdown Markdown implementation}[https://kramdown.gettalong.org]
48
+
49
+ require_relative 'template'
50
+ require 'kramdown'
51
+
52
+ dumb_quotes = [39, 39, 34, 34].freeze
53
+
54
+ Tilt::KramdownTemplate = Tilt::StaticTemplate.subclass do
55
+ # dup as Krawmdown modifies the passed option with map!
56
+ @options[:smart_quotes] = dumb_quotes.dup unless @options[:smartypants]
57
+
58
+ Kramdown::Document.new(@data, @options).to_html
59
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Liquid (<tt>liquid</tt>)
4
+ #
5
+ # Liquid is designed to be a *safe* template system and therefore
6
+ # does not provide direct access to execuatable scopes. In order to
7
+ # support a +scope+, the +scope+ must be able to represent itself
8
+ # as a hash by responding to #to_h. If the +scope+ does not respond
9
+ # to #to_h it will be ignored.
10
+ #
11
+ # LiquidTemplate does not support yield blocks.
12
+ #
13
+ # === Example
14
+ #
15
+ # <html>
16
+ # <head>
17
+ # <title>{{ title }}</title>
18
+ # </head>
19
+ # <body>
20
+ # <h1>Hello {{ world }}!</h1>
21
+ # </body>
22
+ # </html>
23
+ #
24
+ # === Usage
25
+ #
26
+ # <tt>Tilt::LiquidTemplate</tt> is registered for all files ending in <tt>.liquid</tt> by
27
+ # default. Liquid templates support locals and objects that respond to
28
+ # <tt>#to_h</tt> as scopes:
29
+ #
30
+ # >> require 'liquid'
31
+ # >> require 'tilt'
32
+ # >> template = Tilt.new('hello.liquid')
33
+ # => #<Tilt::LiquidTemplate @file='hello.liquid'>
34
+ # >> scope = { :title => "Hello Liquid Templates" }
35
+ # >> template.render(nil, :world => "Liquid")
36
+ # => "
37
+ # <html>
38
+ # <head>
39
+ # <title>Hello Liquid Templates</title>
40
+ # </head>
41
+ # <body>
42
+ # <h1>Hello Liquid!</h1>
43
+ # </body>
44
+ # </html>"
45
+ #
46
+ # Or, use <tt>Tilt::LiquidTemplate</tt> directly to process strings:
47
+ #
48
+ # >> require 'liquid'
49
+ # >> template = Tilt::LiquidTemplate.new { "<h1>Hello Liquid!</h1>" }
50
+ # => #<Tilt::LiquidTemplate @file=nil ...>
51
+ # >> template.render
52
+ # => "<h1>Hello Liquid!</h1>"
53
+ #
54
+ # __NOTE:__ It's suggested that your program <tt>require 'liquid'</tt> at load
55
+ # time when using this template engine within a threaded environment.
56
+ #
57
+ # === See also
58
+ #
59
+ # * {Liquid}[http://liquidmarkup.org]
60
+ # * {Liquid for Programmers}[https://wiki.github.com/Shopify/liquid/liquid-for-programmers]
61
+ # * {Liquid Docs}[http://liquid.rubyforge.org/]
62
+ # * GitHub: {Shopify/liquid}[https://github.com/Shopify/liquid/]
63
+ #
64
+ # === Related module
65
+ #
66
+ # * Tilt::LiquidTemplate
67
+
68
+ require_relative 'template'
69
+ require 'liquid'
70
+
71
+ module Tilt
72
+ class LiquidTemplate < Template
73
+ def prepare
74
+ @options[:line_numbers] = true unless @options.has_key?(:line_numbers)
75
+ @engine = ::Liquid::Template.parse(@data, @options)
76
+ end
77
+
78
+ def evaluate(scope, locs)
79
+ locals = {}
80
+ if scope.respond_to?(:to_h)
81
+ scope.to_h.each{|k, v| locals[k.to_s] = v}
82
+ end
83
+ locs.each{|k, v| locals[k.to_s] = v}
84
+ locals['yield'] = block_given? ? yield : ''
85
+ locals['content'] = locals['yield']
86
+ @engine.render(locals)
87
+ end
88
+
89
+ def allows_script?
90
+ false
91
+ end
92
+ end
93
+ end
@@ -1,11 +1,18 @@
1
1
  # frozen_string_literal: true
2
- require_relative 'template'
3
- require 'livescript'
4
2
 
5
- # LiveScript template implementation. See:
6
- # http://livescript.net/
3
+ # = LiveScript
4
+ #
5
+ # LiveScript template implementation.
7
6
  #
8
7
  # LiveScript templates do not support object scopes, locals, or yield.
8
+ #
9
+ # === See also
10
+ #
11
+ # * http://livescript.net
12
+
13
+ require_relative 'template'
14
+ require 'livescript'
15
+
9
16
  Tilt::LiveScriptTemplate = Tilt::StaticTemplate.subclass(mime_type: 'application/javascript') do
10
17
  LiveScript.compile(@data, @options)
11
18
  end
@@ -119,8 +119,8 @@ module Tilt
119
119
  # # => RDiscount::Template
120
120
  #
121
121
  # In the previous example we say that RDiscount has a *higher priority* than
122
- # Kramdown. Tilt will first try to `require "rdiscount/template"`, falling
123
- # back to `require "kramdown/template"`. If none of these are successful,
122
+ # Kramdown. Tilt will first try to <tt>require "rdiscount/template"</tt>, falling
123
+ # back to <tt>require "kramdown/template"</tt>. If none of these are successful,
124
124
  # the first error will be raised.
125
125
  class Mapping < BaseMapping
126
126
  LOCK = Mutex.new
@@ -237,7 +237,7 @@ module Tilt
237
237
  # :templates=>['erb', 'scss'])
238
238
  def register_pipeline(ext, options=EMPTY_HASH)
239
239
  templates = options[:templates] || ext.split('.').reverse
240
- templates = templates.map{|t| [self[t], options[t] || EMPTY_HASH]}
240
+ templates = templates.map{|t| [self[t], t, options[t] || EMPTY_HASH]}
241
241
 
242
242
  klass = Class.new(Pipeline)
243
243
  klass.send(:const_set, :TEMPLATES, templates)
@@ -346,13 +346,13 @@ module Tilt
346
346
  end
347
347
 
348
348
  # The proper behavior (in MRI) for autoload? is to
349
- # return `false` when the constant/file has been
349
+ # return <tt>false</tt> when the constant/file has been
350
350
  # explicitly required.
351
351
  #
352
- # However, in JRuby it returns `true` even after it's
353
- # been required. In that case it turns out that `defined?`
354
- # returns `"constant"` if it exists and `nil` when it doesn't.
355
- # This is actually a second bug: `defined?` should resolve
352
+ # However, in JRuby it returns <tt>true</tt> even after it's
353
+ # been required. In that case it turns out that <tt>defined?</tt>
354
+ # returns <tt>"constant"</tt> if it exists and <tt>nil</tt> when it doesn't.
355
+ # This is actually a second bug: <tt>defined?</tt> should resolve
356
356
  # autoload (aka. actually try to require the file).
357
357
  #
358
358
  # We use the second bug in order to resolve the first bug.
@@ -1,10 +1,19 @@
1
1
  # frozen_string_literal: true
2
+
3
+ # = Markaby
4
+ #
5
+ # === See also
6
+ #
7
+ # * http://github.com/markaby/markaby
8
+ #
9
+ # === Related module
10
+ #
11
+ # * Tilt::MarkabyTemplate
12
+
2
13
  require_relative 'template'
3
14
  require 'markaby'
4
15
 
5
16
  module Tilt
6
- # Markaby
7
- # http://github.com/markaby/markaby
8
17
  class MarkabyTemplate < Template
9
18
  def self.builder_class
10
19
  @builder_class ||= Class.new(Markaby::Builder) do
@@ -1,10 +1,21 @@
1
1
  # frozen_string_literal: true
2
+
3
+ # = Nokogiri
4
+ #
5
+ # Nokogiri template implementation.
6
+ #
7
+ # === See also
8
+ #
9
+ # * http://nokogiri.org/
10
+ #
11
+ # === Related module
12
+ #
13
+ # * Tilt::NokogiriTemplate
14
+
2
15
  require_relative 'template'
3
16
  require 'nokogiri'
4
17
 
5
18
  module Tilt
6
- # Nokogiri template implementation. See:
7
- # http://nokogiri.org/
8
19
  class NokogiriTemplate < Template
9
20
  DOCUMENT_HEADER = /\A<\?xml version=\"1\.0\"\?>\n?/
10
21
  self.default_mime_type = 'text/xml'
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Markdown (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
4
+ #
5
+ # {Markdown}[http://daringfireball.net/projects/markdown/syntax] is a
6
+ # lightweight markup language, created by John Gruber and Aaron Swartz.
7
+ # For any markup that is not covered by Markdown’s syntax, HTML is used.
8
+ # Marking up plain text with Markdown markup is easy and Markdown
9
+ # formatted texts are readable.
10
+ #
11
+ # === Example
12
+ #
13
+ # Hello Markdown Templates
14
+ # ========================
15
+ #
16
+ # Hello World. This is a paragraph.
17
+ #
18
+ # === Usage
19
+ #
20
+ # To wrap a Markdown formatted document with a layout:
21
+ #
22
+ # layout = Tilt['erb'].new do
23
+ # "<!doctype html><title></title><%= yield %>"
24
+ # end
25
+ # data = Tilt['md'].new { "# hello tilt" }
26
+ # layout.render { data.render }
27
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
28
+ #
29
+ # === Options
30
+ #
31
+ # ==== <tt>:smartypants => true|false</tt>
32
+ #
33
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
34
+ #
35
+ # ==== <tt>:escape_html => true|false</tt>
36
+ #
37
+ # Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
38
+ # literal text by escaping <tt><</tt> characters.
39
+ #
40
+ # === See also
41
+ #
42
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
43
+ # * {Pandoc}[http://pandoc.org]
44
+
45
+ require_relative 'template'
46
+ require 'pandoc-ruby'
47
+
48
+ Tilt::PandocTemplate = Tilt::StaticTemplate.subclass do
49
+ # turn options hash into an array
50
+ # Map tilt options to pandoc options
51
+ # Replace hash keys with value true with symbol for key
52
+ # Remove hash keys with value false
53
+ # Leave other hash keys untouched
54
+ pandoc_options = []
55
+ from = "markdown"
56
+ smart_extension = "-smart"
57
+ @options.each do |k,v|
58
+ case k
59
+ when :smartypants
60
+ smart_extension = "+smart" if v
61
+ when :escape_html
62
+ from = "markdown-raw_html" if v
63
+ when :commonmark
64
+ from = "commonmark" if v
65
+ when :markdown_strict
66
+ from = "markdown_strict" if v
67
+ else
68
+ case v
69
+ when true
70
+ pandoc_options << k
71
+ when false
72
+ # do nothing
73
+ else
74
+ pandoc_options << { k => v }
75
+ end
76
+ end
77
+ end
78
+ pandoc_options << { :f => from + smart_extension }
79
+
80
+ PandocRuby.new(@data, *pandoc_options).to_html.strip
81
+ end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'template'
3
4
 
4
5
  module Tilt
5
6
  # Superclass used for pipeline templates. Should not be used directly.
6
7
  class Pipeline < Template
7
8
  def prepare
8
- @pipeline = self.class::TEMPLATES.inject(proc{|*| data}) do |data, (klass, options)|
9
+ @pipeline = self.class::TEMPLATES.inject(proc{|*| data}) do |data, (klass, ext, options)|
9
10
  proc do |s,l,&sb|
11
+ options = options
12
+ if ext_opts = @options[ext]
13
+ options = options.merge(ext_opts)
14
+ end
10
15
  klass.new(file, line, options, &proc{|*| data.call(s, l, &sb)}).render(s, l, &sb)
11
16
  end
12
17
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
- require_relative 'template'
3
2
 
3
+ # = Plain
4
+ #
4
5
  # Raw text (no template functionality).
6
+
7
+ require_relative 'template'
8
+
5
9
  Tilt::PlainTemplate = Tilt::StaticTemplate.subclass{@data}
@@ -1,26 +1,37 @@
1
1
  # frozen_string_literal: true
2
+
3
+ # = Prawn
4
+ #
5
+ # Prawn template implementation.
6
+ #
7
+ # === See also
8
+ #
9
+ # * http://prawnpdf.org
10
+ #
11
+ # === Related module
12
+ #
13
+ # * Tilt::PrawnTemplate
14
+
2
15
  require_relative 'template'
3
16
  require 'prawn'
4
17
 
5
18
  module Tilt
6
- # Prawn template implementation. See: http://prawnpdf.org
7
19
  class PrawnTemplate < Template
8
20
  self.default_mime_type = 'application/pdf'
9
-
21
+
10
22
  def prepare
11
23
  @options[:page_size] = 'A4' unless @options.has_key?(:page_size)
12
24
  @options[:page_layout] = :portrait unless @options.has_key?(:page_layout)
13
- @engine = ::Prawn::Document.new(@options)
14
25
  end
15
-
26
+
16
27
  def evaluate(scope, locals, &block)
17
- pdf = @engine
28
+ pdf = ::Prawn::Document.new(@options)
18
29
  locals = locals.dup
19
30
  locals[:pdf] = pdf
20
31
  super
21
32
  pdf.render
22
33
  end
23
-
34
+
24
35
  def precompiled_template(locals)
25
36
  @data.to_str
26
37
  end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = Radius (<tt>radius</tt>)
4
+ #
5
+ # {Radius}[http://radius.rubyforge.org] is the template language used by {Radiant CMS}[http://radiantcms.org]. It is
6
+ # a tag language designed to be valid XML/HTML.
7
+ #
8
+ # === Example
9
+ #
10
+ # <html>
11
+ # <body>
12
+ # <h1><r:title /></h1>
13
+ # <ul class="<r:type />">
14
+ # <r:repeat times="3">
15
+ # <li><r:hello />!</li>
16
+ # </r:repeat>
17
+ # </ul>
18
+ # <r:yield />
19
+ # </body>
20
+ # </html>
21
+ #
22
+ # === Usage
23
+ #
24
+ # To render a template such as the one above.
25
+ #
26
+ # scope = OpenStruct.new
27
+ # scope.title = "Radius Example"
28
+ # scope.hello = "Hello, World!"
29
+ #
30
+ # require 'radius'
31
+ # template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
32
+ # template.render(scope, :type=>'hlist'){ "Jackpot!" }
33
+ #
34
+ # The result will be:
35
+ #
36
+ # <html>
37
+ # <body>
38
+ # <h1>Radius Example</h1>
39
+ # <ul class="hlist">
40
+ # <li>Hello, World!</li>
41
+ # <li>Hello, World!</li>
42
+ # <li>Hello, World!</li>
43
+ # </ul>
44
+ # Jackpot!
45
+ # </body>
46
+ # </html>
47
+ #
48
+ # === See also
49
+ #
50
+ # * {Radius}[http://radius.rubyforge.org]
51
+ # * {Radiant CMS}[http://radiantcms.org]
52
+ #
53
+ # === Related module
54
+ #
55
+ # * Tilt::RadiusTemplate
56
+
57
+ require_relative 'template'
58
+ require 'radius'
59
+
60
+ module Tilt
61
+ # Radius Template
62
+ # http://github.com/jlong/radius/
63
+ class RadiusTemplate < Template
64
+ class ContextClass < Radius::Context
65
+ attr_accessor :tilt_scope
66
+
67
+ def tag_missing(name, attributes)
68
+ tilt_scope.__send__(name)
69
+ end
70
+
71
+ def dup
72
+ i = super
73
+ i.tilt_scope = tilt_scope
74
+ i
75
+ end
76
+ end
77
+
78
+ def evaluate(scope, locals, &block)
79
+ context = ContextClass.new
80
+ context.tilt_scope = scope
81
+ context.define_tag("yield", &block) if block
82
+ locals.each do |tag, value|
83
+ context.define_tag(tag) do
84
+ value
85
+ end
86
+ end
87
+
88
+ @options[:tag_prefix] = 'r' unless @options.has_key?(:tag_prefix)
89
+ Radius::Parser.new(context, @options).parse(@data)
90
+ end
91
+
92
+ def allows_script?
93
+ false
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # = RDiscount (<tt>markdown</tt>, <tt>md</tt>, <tt>mkd</tt>)
4
+ #
5
+ # Markdown is a lightweight markup language, created by John Gruber
6
+ # and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
7
+ # is used. Marking up plain text with Markdown markup is easy and Markdown
8
+ # formatted texts are readable.
9
+ #
10
+ # RDiscount is a simple text filter. It does not support +scope+ or
11
+ # +locals+. The +:smart+ and +:filter_html+ options may be set true
12
+ # to enable those flags on the underlying RDiscount object.
13
+ #
14
+ # === Example
15
+ #
16
+ # Hello Markdown Templates
17
+ # ========================
18
+ #
19
+ # Hello World. This is a paragraph.
20
+ #
21
+ # === Usage
22
+ #
23
+ # To wrap a Markdown formatted document with a layout:
24
+ #
25
+ # layout = Tilt['erb'].new do
26
+ # "<!doctype html><title></title><%= yield %>"
27
+ # end
28
+ # data = Tilt['md'].new { "# hello tilt" }
29
+ # layout.render { data.render }
30
+ # # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
31
+ #
32
+ # === Options
33
+ #
34
+ # ==== <tt>:smartypants => true|false</tt>
35
+ #
36
+ # Set <tt>true</tt> to enable [Smarty Pants][smartypants] style punctuation replacement.
37
+ #
38
+ # ==== <tt>:escape_html => true|false</tt>
39
+ #
40
+ # Set <tt>true</tt> disallow raw HTML in Markdown contents. HTML is converted to
41
+ # literal text by escaping <tt><</tt> characters.
42
+ #
43
+ # === See also
44
+ #
45
+ # * {Markdown Syntax Documentation}[http://daringfireball.net/projects/markdown/syntax]
46
+ # * [Discount][discount]
47
+ # * {RDiscount}[http://github.com/rtomayko/rdiscount]
48
+ #
49
+ # -----------------------------------
50
+ #
51
+ # [Discount][discount] is an implementation of the Markdown markup language in C.
52
+ # [RDiscount][rdiscount] is a Ruby wrapper around Discount.
53
+ #
54
+ # All the documentation of {Markdown}[#markdown] applies in addition to the following:
55
+ #
56
+ # === Usage
57
+ #
58
+ # The <tt>Tilt::RDiscountTemplate</tt> class is registered for all files ending in
59
+ # <tt>.markdown</tt>, <tt>.md</tt> or <tt>.mkd</tt> by default with the highest priority. If you
60
+ # specifically want to use RDiscount, it's recommended to use <tt>#prefer</tt>:
61
+ #
62
+ # Tilt.prefer Tilt::RDiscountTemplate
63
+ #
64
+ # __NOTE:__ It's suggested that your program <tt>require 'rdiscount'</tt> at load time when
65
+ # using this template engine within a threaded environment.
66
+
67
+ require_relative 'template'
68
+ require 'rdiscount'
69
+
70
+ aliases = {
71
+ :escape_html => :filter_html,
72
+ :smartypants => :smart
73
+ }.freeze
74
+
75
+ _flags = [:smart, :filter_html, :smartypants, :escape_html].freeze
76
+
77
+ Tilt::RDiscountTemplate = Tilt::StaticTemplate.subclass do
78
+ flags = _flags.select { |flag| @options[flag] }.
79
+ map! { |flag| aliases[flag] || flag }
80
+
81
+ RDiscount.new(@data, *flags).to_html
82
+ end