padrino-helpers 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9de9c68240b6a030c87053b1f781ef7152ef5bfc
4
- data.tar.gz: a9a5d042cd4ed7d6dd52d9977b4421c0a40389e2
3
+ metadata.gz: febadf7b3fad75194b40771bb1d5c414303b6786
4
+ data.tar.gz: 3e5d9099e89fa2d58a149b09c54f993ff7a14c53
5
5
  SHA512:
6
- metadata.gz: f0d72f6b0c05eaae7fb28d4fd7c85d7d76a9e2e7a7ef719f42040b0148cdbfb19ccdd3f790ef592328ec341edaf15acf74cda7b6e24b21aa4ce25beaa2af44fa
7
- data.tar.gz: 97eb607b9c2caf7c9242c39afa18ceac5f63e7306d46c0e01d3041e93bf3008fef4e0a7b7f03bfc5ba9624b3cb6a7bd2fc9520e63cc9a85396af7d52c621e347
6
+ metadata.gz: 56a145692e0257c6c8d938da7218807ee0ea528c8ff2b3b29ededf270faabed6a30bbd8e690d1326ce9f9745203634948ae756fbff06ce11c1c9a5304051cea4
7
+ data.tar.gz: 7650154ec4c435655aa9e2414b71c00f9aaec7516c8d875855689b51e9f55c274b6d3080ad4f8174c4ecf85731dbe2143239209d488e09f0e68aec79db39f792
@@ -45,17 +45,20 @@ module Padrino
45
45
  def registered(app)
46
46
  app.register Padrino::Rendering
47
47
  app.set :default_builder, 'StandardFormBuilder'
48
- app.helpers Padrino::Helpers::OutputHelpers
49
- app.helpers Padrino::Helpers::TagHelpers
50
- app.helpers Padrino::Helpers::AssetTagHelpers
51
- app.helpers Padrino::Helpers::FormHelpers
52
- app.helpers Padrino::Helpers::FormatHelpers
53
- app.helpers Padrino::Helpers::RenderHelpers
54
- app.helpers Padrino::Helpers::NumberHelpers
55
- app.helpers Padrino::Helpers::TranslationHelpers
56
- app.helpers Padrino::Helpers::Breadcrumbs
48
+ included(app)
49
+ end
50
+
51
+ def included(base)
52
+ base.send :include, Padrino::Helpers::OutputHelpers
53
+ base.send :include, Padrino::Helpers::TagHelpers
54
+ base.send :include, Padrino::Helpers::AssetTagHelpers
55
+ base.send :include, Padrino::Helpers::FormHelpers
56
+ base.send :include, Padrino::Helpers::FormatHelpers
57
+ base.send :include, Padrino::Helpers::RenderHelpers
58
+ base.send :include, Padrino::Helpers::NumberHelpers
59
+ base.send :include, Padrino::Helpers::TranslationHelpers
60
+ base.send :include, Padrino::Helpers::Breadcrumbs
57
61
  end
58
- alias :included :registered
59
62
  end
60
63
  end
61
64
  end
@@ -52,10 +52,6 @@ module Padrino
52
52
  # @param [Hash] options The html options.
53
53
  # @param [Proc] block The link content.
54
54
  #
55
- # @option options [String] :anchor
56
- # The anchor for the link (i.e #something).
57
- # @option options [String] :fragment
58
- # Synonym for anchor.
59
55
  # @option options [Boolean] :if
60
56
  # If true, the link will appear, otherwise not.
61
57
  # @option options [Boolean] :unless
@@ -80,17 +76,14 @@ module Padrino
80
76
  #
81
77
  def link_to(*args, &block)
82
78
  options = args.extract_options!
83
- fragment = options.delete(:anchor).to_s if options[:anchor]
84
- fragment = options.delete(:fragment).to_s if options[:fragment]
85
79
  name = block_given? ? '' : args.shift
86
- if url = args.first
87
- url << '#' << fragment if fragment
88
- else
89
- url = '#'
90
- url << fragment if fragment
80
+ href = args.first
81
+ if fragment = options[:fragment] || options[:anchor]
82
+ warn 'Options :anchor and :fragment are deprecated for #link_to. Please use :fragment for #url'
83
+ href << '#' << fragment.to_s
91
84
  end
92
- options.reverse_merge!(:href => url)
93
- return name unless parse_conditions(url, options)
85
+ options.reverse_merge!(:href => href || '#')
86
+ return name unless parse_conditions(href, options)
94
87
  block_given? ? content_tag(:a, options, &block) : content_tag(:a, name, options)
95
88
  end
96
89
 
@@ -147,7 +140,7 @@ module Padrino
147
140
  #
148
141
  def mail_to(email, caption=nil, mail_options={})
149
142
  html_options = mail_options.slice!(:cc, :bcc, :subject, :body)
150
- mail_query = Rack::Utils.build_query(mail_options).gsub(/\+/, '%20').gsub('%40', '@').gsub('&', '&amp;')
143
+ mail_query = Rack::Utils.build_query(mail_options).gsub(/\+/, '%20').gsub('%40', '@')
151
144
  mail_href = "mailto:#{email}"; mail_href << "?#{mail_query}" if mail_query.present?
152
145
  link_to((caption || email), mail_href, html_options)
153
146
  end
@@ -35,6 +35,7 @@ module Padrino
35
35
  end
36
36
 
37
37
  def label(field, options={}, &block)
38
+ options[:id] ||= nil
38
39
  options[:caption] ||= I18n.t("#{model_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models) + ': '
39
40
  @template.label_tag(field_id(field), default_options(field, options), &block)
40
41
  end
@@ -102,7 +102,7 @@ module Padrino
102
102
  options[:method] = 'post'
103
103
  end
104
104
  inner_form_html = hidden_form_method_field(desired_method)
105
- inner_form_html << csrf_token_field if options[:protect_from_csrf]
105
+ inner_form_html << csrf_token_field if options.delete(:protect_from_csrf)
106
106
  concat_content content_tag(:form, inner_form_html << capture_html(&block), options)
107
107
  end
108
108
 
@@ -459,10 +459,12 @@ module Padrino
459
459
  # grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
460
460
  # select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
461
461
  #
462
- # # Optgroups can be generated using :grouped_options => (Hash or nested Array)
463
- # grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
464
- # grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
465
- # select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
462
+ # # Optgroups can be generated using the rails-style attribute hash.
463
+ # grouped_options = {
464
+ # "Friends" => ["Yoda", ["Obiwan", 2, {:magister => 'no'}], {:lame => 'yes'}],
465
+ # "Enemies" => [["Palpatine", "Palpatine", {:scary => 'yes', :old => 'yes'}], ["Darth Vader", 3, {:disabled => true}]]
466
+ # }
467
+ # select_tag(:name, :grouped_options => grouped_options)
466
468
  #
467
469
  # @param [String] name
468
470
  # The name of the input field.
@@ -12,7 +12,7 @@ module Padrino
12
12
  else
13
13
  options_for_select(extract_option_items!(options), state)
14
14
  end
15
- if prompt = options[:include_blank]
15
+ if prompt = options.delete(:include_blank)
16
16
  option_tags.unshift(blank_option(prompt))
17
17
  end
18
18
  option_tags
@@ -55,7 +55,7 @@ module Padrino
55
55
  def options_for_select(option_items, state = {})
56
56
  return [] if option_items.blank?
57
57
  option_items.map do |caption, value, attributes|
58
- html_attributes = { :value => value || caption }.merge(attributes||{})
58
+ html_attributes = { :value => value ||= caption }.merge(attributes||{})
59
59
  html_attributes[:selected] ||= option_is_selected?(value, caption, state[:selected])
60
60
  html_attributes[:disabled] ||= option_is_selected?(value, caption, state[:disabled])
61
61
  content_tag(:option, caption, html_attributes)
@@ -125,14 +125,20 @@ module Padrino
125
125
  # @overload content_for(key, content)
126
126
  # @param [Symbol] key Name of your key for the content yield.
127
127
  # @param [String] content Text to be stored for this key.
128
+ # @param [Hash] options Options associated with this method.
128
129
  # @overload content_for(key, &block)
129
130
  # @param [Symbol] key Name of your key for the content yield.
130
131
  # @param [Proc] block Block to be stored as content for this key.
132
+ # @param [Hash] options Options associated with this method.
133
+ #
134
+ # @option options [Boolean] :flush
135
+ # Specifies whether to replace the content.
131
136
  #
132
137
  # @example
133
138
  # content_for(:name) { ...content... }
134
139
  # content_for(:name) { |name| ...content... }
135
140
  # content_for(:name, "I'm Jeff")
141
+ # content_for(:name, :flush => true) { ...new content... }
136
142
  #
137
143
  def content_for(key, content = nil, options = {}, &block)
138
144
  options = content if content.is_a?(Hash)
@@ -298,26 +298,18 @@ module Padrino
298
298
  I18n.locale if defined?(I18n)
299
299
  end
300
300
 
301
- LAYOUT_EXTENSIONS = %w[.slim .erb .haml].freeze
302
-
303
301
  def resolve_layout(layout, options={})
304
302
  layouts_path = options[:layout_options] && options[:layout_options][:views] || options[:views] || settings.views || "./views"
305
303
  template_path = settings.fetch_layout_path(layout, layouts_path)
306
304
  rendering_options = [template_path, content_type || :html, locale]
307
305
 
308
- layout, engine =
309
- settings.cache_template_path(rendering_options) do
310
- template_candidates = glob_templates(layouts_path, template_path)
311
- selected_template = select_template(template_candidates, *rendering_options)
312
-
313
- fail TemplateNotFound, "Layout '#{template_path}' not found in '#{layouts_path}'" if !selected_template && layout.present?
314
- selected_template
315
- end
316
-
317
- is_included_extension = LAYOUT_EXTENSIONS.include?(File.extname(template_path.to_s))
318
- layout = false unless is_included_extension ? engine : engine == @current_engine
306
+ settings.cache_template_path(rendering_options) do
307
+ template_candidates = glob_templates(layouts_path, template_path)
308
+ selected_template = select_template(template_candidates, *rendering_options)
319
309
 
320
- [layout, engine]
310
+ fail TemplateNotFound, "Layout '#{template_path}' not found in '#{layouts_path}'" if !selected_template && layout.present?
311
+ selected_template
312
+ end
321
313
  end
322
314
 
323
315
  def with_layout(options)
@@ -344,7 +336,7 @@ module Padrino
344
336
  parts << "{,#{request.controller}}"
345
337
  end
346
338
  parts << template_path.chomp(File.extname(template_path)) + '.*'
347
- Dir.glob(File.join(parts)).sort.inject([]) do |all,file|
339
+ Dir.glob(File.join(parts)).inject([]) do |all,file|
348
340
  next all if IGNORE_FILE_PATTERN.any?{ |pattern| file.to_s =~ pattern }
349
341
  all << path_and_engine(file, views_path)
350
342
  end
@@ -373,6 +365,31 @@ module Padrino
373
365
  end
374
366
  end
375
367
 
376
- require 'padrino/rendering/extensions/haml'
377
- require 'padrino/rendering/extensions/erubis'
378
- require 'padrino/rendering/extensions/slim'
368
+ unless defined? Padrino::Rendering::HamlTemplate
369
+ begin
370
+ require 'haml'
371
+ require 'haml/helpers/xss_mods'
372
+ require 'haml/helpers/action_view_extensions'
373
+ rescue LoadError
374
+ else
375
+ require 'padrino/rendering/haml_template'
376
+ end
377
+ end
378
+
379
+ unless defined? Padrino::Rendering::ErubisTemplate
380
+ begin
381
+ require 'erubis'
382
+ rescue LoadError
383
+ else
384
+ require 'padrino/rendering/erubis_template'
385
+ end
386
+ end
387
+
388
+ unless defined? Padrino::Rendering::SlimTemplate
389
+ begin
390
+ require 'slim'
391
+ rescue LoadError
392
+ else
393
+ require 'padrino/rendering/slim_template'
394
+ end
395
+ end
@@ -0,0 +1,66 @@
1
+ module Padrino
2
+ module Rendering
3
+ ##
4
+ # SafeBufferEnhancer is an Erubis Enhancer that compiles templates that
5
+ # are fit for using ActiveSupport::SafeBuffer as a Buffer.
6
+ #
7
+ # @api private
8
+ module SafeBufferEnhancer
9
+ def add_expr_literal(src, code)
10
+ src << " #{@bufvar}.concat((" << code << ').to_s);'
11
+ end
12
+
13
+ def add_stmt(src, code)
14
+ code = code.sub('end', 'nil;end') if code =~ /\A\s*end\s*\Z/
15
+ src << code
16
+ src << ';' unless code[-1] == ?\n
17
+ end
18
+
19
+ def add_expr_escaped(src, code)
20
+ src << " #{@bufvar}.safe_concat " << code << ';'
21
+ end
22
+
23
+ def add_text(src, text)
24
+ src << " #{@bufvar}.safe_concat '" << escape_text(text) << "';" unless text.empty?
25
+ end
26
+ end
27
+
28
+ ##
29
+ # SafeBufferTemplate is the Eruby engine, augmented with SafeBufferEnhancer.
30
+ #
31
+ # @api private
32
+ class SafeEruby < ::Erubis::Eruby
33
+ include SafeBufferEnhancer
34
+ end
35
+
36
+ ##
37
+ # Modded ErubisTemplate that doesn't insist in an String as output
38
+ # buffer.
39
+ #
40
+ # @api private
41
+ class ErubisTemplate < Tilt::ErubisTemplate
42
+ def render(*args)
43
+ app = args.first
44
+ app_class = app.class
45
+ @is_padrino_app = (defined?(Padrino::Application) && app.kind_of?(Padrino::Application)) ||
46
+ (app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Rendering::SafeEruby)
47
+ super
48
+ end
49
+
50
+ ##
51
+ # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps.
52
+ #
53
+ def precompiled_preamble(locals)
54
+ original = super
55
+ return original unless @is_padrino_app
56
+ "__in_erb_template = true\n" << original.rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ Tilt.prefer(Padrino::Rendering::ErubisTemplate, :erb)
63
+
64
+ Padrino::Rendering.engine_configurations[:erb] = {
65
+ :engine_class => Padrino::Rendering::SafeEruby,
66
+ }
@@ -0,0 +1,26 @@
1
+ module Haml
2
+ module Helpers
3
+ include XssMods
4
+ include ActionViewExtensions
5
+ end
6
+
7
+ module Util
8
+ def self.rails_xss_safe?
9
+ true
10
+ end
11
+ end
12
+ end
13
+
14
+ module Padrino
15
+ module Rendering
16
+ class HamlTemplate < Tilt::HamlTemplate
17
+ include SafeTemplate
18
+ end
19
+ end
20
+ end
21
+
22
+ Tilt.prefer(Padrino::Rendering::HamlTemplate, :haml)
23
+
24
+ Padrino::Rendering.engine_configurations[:haml] = {
25
+ :escape_html => true,
26
+ }
@@ -0,0 +1,20 @@
1
+ module Padrino
2
+ module Rendering
3
+ class SlimTemplate < Slim::Template
4
+ include SafeTemplate
5
+
6
+ def precompiled_preamble(locals)
7
+ "__in_slim_template = true\n" << super
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ Tilt.prefer(Padrino::Rendering::SlimTemplate, :slim)
14
+
15
+ Padrino::Rendering.engine_configurations[:slim] = {
16
+ :generator => Temple::Generators::RailsOutputBuffer,
17
+ :buffer => "@_out_buf",
18
+ :use_html_safe => true,
19
+ :disable_capture => true,
20
+ }
@@ -102,6 +102,8 @@ describe "AssetTagHelpers" do
102
102
  it 'should not double-escape' do
103
103
  actual_link = link_to('test escape', '?a=1&b=2')
104
104
  assert_has_tag('a', :href => '?a=1&b=2') { actual_link }
105
+ assert_match %r{&amp;}, actual_link
106
+ refute_match %r{&amp;amp;}, actual_link
105
107
  end
106
108
 
107
109
  it 'should escape scary things' do
@@ -135,6 +137,13 @@ describe "AssetTagHelpers" do
135
137
  assert_match 'My&amp;Email', actual_html
136
138
  end
137
139
 
140
+ it 'should not double-escape ampersands in query' do
141
+ actual_html = mail_to('to@demo.com', "Email", :subject => 'Hi there', :bcc => 'bcc@test.com')
142
+ assert_has_tag(:a, :href => 'mailto:to@demo.com?bcc=bcc@test.com&subject=Hi%20there', :content => 'Email') { actual_html }
143
+ assert_match %r{&amp;}, actual_html
144
+ refute_match %r{&amp;amp;}, actual_html
145
+ end
146
+
138
147
  it 'should display mail link element in haml' do
139
148
  visit '/haml/mail_to'
140
149
  assert_have_selector 'p.simple a', :href => 'mailto:test@demo.com', :content => 'test@demo.com'
@@ -273,6 +273,7 @@ describe "FormBuilder" do
273
273
  it 'should display correct label html' do
274
274
  actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name: ")
275
275
  assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
276
+ assert_has_no_tag('label#user_first_name') { actual_html }
276
277
  end
277
278
 
278
279
  it 'should set specific content inside the label if a block was provided' do
@@ -97,6 +97,11 @@ describe "FormHelpers" do
97
97
  assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
98
98
  end
99
99
 
100
+ it 'should not include protect_from_csrf as an attribute of form element' do
101
+ actual_html = form_tag('/superadmindelete', :protect_from_csrf => true){ "Demo" }
102
+ assert_has_no_tag(:form, protect_from_csrf: "true"){ actual_html }
103
+ end
104
+
100
105
  it 'should display correct forms in erb' do
101
106
  visit '/erb/form_tag'
102
107
  assert_have_selector 'form.simple-form', :action => '/simple'
@@ -657,6 +662,13 @@ describe "FormHelpers" do
657
662
  assert_has_tag('select option:first-child', :value => "", :content => "") { actual_html }
658
663
  end
659
664
 
665
+ it 'should include blank as caption' do
666
+ opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
667
+ actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => 'Choose your destiny' )
668
+ assert_has_tag('select option:first-child', :value => "", :content => "Choose your destiny") { actual_html }
669
+ assert_has_no_tag('select[include_blank]') { actual_html }
670
+ end
671
+
660
672
  it 'should display select tag with grouped options for a nested array' do
661
673
  opts = [
662
674
  ["Friends",["Yoda",["Obiwan",2]]],
@@ -775,6 +787,13 @@ describe "FormHelpers" do
775
787
  assert_has_tag('select option', :content => 'Black', :value => 'black1', :selected => 'selected') { actual_html }
776
788
  end
777
789
 
790
+ it 'should not misselect options with default value' do
791
+ options = ['Green', 'Blue']
792
+ actual_html = select_tag(:favorite_color, :options => options, :selected => ['Green', ''])
793
+ assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
794
+ assert_has_tag('select option', :content => 'Green', :value => 'Green', :selected => 'selected') { actual_html }
795
+ end
796
+
778
797
  it 'should display options selected only for exact match' do
779
798
  options = [['One', '1'], ['1', '10'], ['Two', "-1"]]
780
799
  actual_html = select_tag(:range, :options => options, :selected => '-1')
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe "Padrino::Helpers" do
4
+ it 'should allow including without registering' do
5
+ class Foo
6
+ include Padrino::Helpers
7
+ end
8
+ assert_equal '<div>bar</div>', Foo.new.content_tag(:div, 'bar')
9
+ end
10
+ end
@@ -190,25 +190,6 @@ describe "Rendering" do
190
190
  assert_equal "bar layout bar", body
191
191
  end
192
192
 
193
- it 'should render correctly if layout was not found or not exist' do
194
- create_layout :application, "application layout for <%= yield %>"
195
- create_view :foo, "index", :format => :html
196
- create_view :foo, "xml.rss", :format => :rss
197
- mock_app do
198
- get("/foo", :provides => [:html, :rss]) { render('foo') }
199
- get("/baz", :provides => :js) { render(:erb, 'baz') }
200
- get("/bar") { render :haml, "haml" }
201
- end
202
- get "/foo"
203
- assert_equal "application layout for index", body
204
- get "/foo.rss"
205
- assert_equal "<rss/>", body.chomp
206
- get "/baz.js"
207
- assert_equal "baz", body
208
- get "/bar"
209
- assert_equal "haml", body.chomp
210
- end
211
-
212
193
  it 'should allow to render template with layout option that using other template engine.' do
213
194
  create_layout :"layouts/foo", "application layout for <%= yield %>", :format => :erb
214
195
  create_view :slim, "| slim", :format => :slim
@@ -246,6 +227,25 @@ describe "Rendering" do
246
227
  assert_equal "application layout for erb", body.chomp
247
228
  end
248
229
 
230
+ it 'should find a layout by symbol' do
231
+ create_layout :"layouts/bar", "application layout for <%= yield %>", :format => :erb
232
+ create_view :slim, "| slim", :format => :slim
233
+ create_view :haml, "haml", :format => :haml
234
+ create_view :erb, "erb", :format => :erb
235
+ mock_app do
236
+ layout :bar
237
+ get("/slim") { render("slim.slim") }
238
+ get("/haml") { render("haml.haml") }
239
+ get("/erb") { render("erb.erb") }
240
+ end
241
+ get "/slim"
242
+ assert_equal "application layout for slim", body.chomp
243
+ get "/haml"
244
+ assert_equal "application layout for haml", body.chomp
245
+ get "/erb"
246
+ assert_equal "application layout for erb", body.chomp
247
+ end
248
+
249
249
  describe 'for application render functionality' do
250
250
 
251
251
  it 'should work properly with logging and missing layout' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-04-04 00:00:00.000000000 Z
14
+ date: 2014-05-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.12.1
22
+ version: 0.12.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.1
29
+ version: 0.12.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -117,9 +117,9 @@ files:
117
117
  - lib/padrino-helpers/tag_helpers.rb
118
118
  - lib/padrino-helpers/translation_helpers.rb
119
119
  - lib/padrino/rendering.rb
120
- - lib/padrino/rendering/extensions/erubis.rb
121
- - lib/padrino/rendering/extensions/haml.rb
122
- - lib/padrino/rendering/extensions/slim.rb
120
+ - lib/padrino/rendering/erubis_template.rb
121
+ - lib/padrino/rendering/haml_template.rb
122
+ - lib/padrino/rendering/slim_template.rb
123
123
  - padrino-helpers.gemspec
124
124
  - test/fixtures/apps/.components
125
125
  - test/fixtures/apps/.gitignore
@@ -206,6 +206,7 @@ files:
206
206
  - test/test_form_builder.rb
207
207
  - test/test_form_helpers.rb
208
208
  - test/test_format_helpers.rb
209
+ - test/test_helpers.rb
209
210
  - test/test_locale.rb
210
211
  - test/test_number_helpers.rb
211
212
  - test/test_output_helpers.rb
@@ -324,6 +325,7 @@ test_files:
324
325
  - test/test_form_builder.rb
325
326
  - test/test_form_helpers.rb
326
327
  - test/test_format_helpers.rb
328
+ - test/test_helpers.rb
327
329
  - test/test_locale.rb
328
330
  - test/test_number_helpers.rb
329
331
  - test/test_output_helpers.rb
@@ -1,74 +0,0 @@
1
- begin
2
- require 'erubis'
3
-
4
- module Padrino
5
- module Erubis
6
- ##
7
- # SafeBufferEnhancer is an Erubis Enhancer that compiles templates that
8
- # are fit for using ActiveSupport::SafeBuffer as a Buffer.
9
- #
10
- # @api private
11
- module SafeBufferEnhancer
12
- def add_expr_literal(src, code)
13
- src << " #{@bufvar}.concat((" << code << ').to_s);'
14
- end
15
-
16
- def add_stmt(src, code)
17
- code = code.sub('end', 'nil;end') if code =~ /\A\s*end\s*\Z/
18
- src << code
19
- src << ';' unless code[-1] == ?\n
20
- end
21
-
22
- def add_expr_escaped(src, code)
23
- src << " #{@bufvar}.safe_concat " << code << ';'
24
- end
25
-
26
- def add_text(src, text)
27
- src << " #{@bufvar}.safe_concat '" << escape_text(text) << "';" unless text.empty?
28
- end
29
- end
30
-
31
- ##
32
- # SafeBufferTemplate is the classic Erubis template, augmented with
33
- # SafeBufferEnhancer.
34
- #
35
- # @api private
36
- class SafeBufferTemplate < ::Erubis::Eruby
37
- include SafeBufferEnhancer
38
- end
39
-
40
- ##
41
- # Modded ErubisTemplate that doesn't insist in an String as output
42
- # buffer.
43
- #
44
- # @api private
45
- class Template < Tilt::ErubisTemplate
46
- def render(*args)
47
- app = args.first
48
- app_class = app.class
49
- @is_padrino_app = (defined?(Padrino::Application) && app.kind_of?(Padrino::Application)) ||
50
- (app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Erubis::SafeBufferTemplate)
51
- super
52
- end
53
-
54
- ##
55
- # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps.
56
- #
57
- def precompiled_preamble(locals)
58
- original = super
59
- return original unless @is_padrino_app
60
- "__in_erb_template = true\n" << original.rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n"
61
- end
62
- end
63
- end
64
- end
65
-
66
- Tilt.prefer(Padrino::Erubis::Template, :erb)
67
-
68
- if defined? Padrino::Rendering
69
- Padrino::Rendering.engine_configurations[:erb] = {
70
- :engine_class => Padrino::Erubis::SafeBufferTemplate,
71
- }
72
- end
73
- rescue LoadError
74
- end
@@ -1,29 +0,0 @@
1
- begin
2
- require 'haml'
3
- require 'haml/helpers/xss_mods'
4
- require 'haml/helpers/action_view_extensions'
5
-
6
- module Haml
7
- module Helpers
8
- include XssMods
9
- include ActionViewExtensions
10
- end
11
-
12
- module Util
13
- def self.rails_xss_safe?
14
- true
15
- end
16
- end
17
- end
18
-
19
- if defined? Padrino::Rendering
20
- Padrino::Rendering.engine_configurations[:haml] = {
21
- :escape_html => true,
22
- }
23
-
24
- class Tilt::HamlTemplate
25
- include Padrino::Rendering::SafeTemplate
26
- end
27
- end
28
- rescue LoadError
29
- end
@@ -1,21 +0,0 @@
1
- begin
2
- require 'slim'
3
-
4
- if defined? Padrino::Rendering
5
- Padrino::Rendering.engine_configurations[:slim] = {
6
- :generator => Temple::Generators::RailsOutputBuffer,
7
- :buffer => "@_out_buf",
8
- :use_html_safe => true,
9
- :disable_capture => true,
10
- }
11
-
12
- class Slim::Template
13
- include Padrino::Rendering::SafeTemplate
14
-
15
- def precompiled_preamble(locals)
16
- "__in_slim_template = true\n" << super
17
- end
18
- end
19
- end
20
- rescue LoadError
21
- end