sinatra_more 0.0.11 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.13
@@ -8,7 +8,7 @@ class StandardFormBuilder < AbstractFormBuilder
8
8
  class_eval <<-EOF
9
9
  def #{field_type}_block(field, options={}, label_options={})
10
10
  label_options.reverse_merge!(:caption => options.delete(:caption)) if options[:caption]
11
- @template.content_block_tag(:p, :concat => false) do
11
+ @template.content_block_tag(:p) do
12
12
  html = label(field, label_options)
13
13
  html << #{field_type}(field, options)
14
14
  end
@@ -18,7 +18,7 @@ class StandardFormBuilder < AbstractFormBuilder
18
18
 
19
19
  # submit_block("Update")
20
20
  def submit_block(caption)
21
- @template.content_block_tag(:p, :concat => false) do
21
+ @template.content_block_tag(:p) do
22
22
  @template.submit_tag(caption)
23
23
  end
24
24
  end
@@ -3,7 +3,7 @@ module SinatraMore
3
3
  # Captures the html from a block of template code for erb or haml
4
4
  # capture_html(&block) => "...html..."
5
5
  def capture_html(*args, &block)
6
- if is_haml?
6
+ if self.respond_to?(:is_haml?) && is_haml?
7
7
  block_is_haml?(block) ? capture_haml(*args, &block) : block.call
8
8
  else
9
9
  capture_erb(*args, &block)
@@ -19,12 +19,26 @@ module SinatraMore
19
19
  @_out_buf << text
20
20
  end
21
21
  end
22
+
23
+ # Returns true if the block is from an ERB or HAML template; false otherwise.
24
+ # Used to determine if html should be returned or concatted to view
25
+ # block_is_template?(block)
26
+ def block_is_template?(block)
27
+ block && (block_is_erb?(block) || (self.respond_to?(:block_is_haml?) && block_is_haml?(block)))
28
+ end
22
29
 
23
30
  # Used to capture the html from a block of erb code
24
31
  # capture_erb(&block) => '...html...'
25
32
  def capture_erb(*args, &block)
26
33
  erb_with_output_buffer { block.call(*args) }
27
34
  end
35
+
36
+ # Used to determine if a block is called from ERB.
37
+ # NOTE: This doesn't actually work yet because the variable __in_erb_template
38
+ # hasn't been defined in ERB. We need to find a way to fix this.
39
+ def block_is_erb?(block)
40
+ block && eval('defined? __in_erb_template', block)
41
+ end
28
42
 
29
43
  # Used to direct the buffer for the erb capture
30
44
  def erb_with_output_buffer(buf = '') #:nodoc:
@@ -11,15 +11,12 @@ module SinatraMore
11
11
  # content_tag(:p, "hello", :class => 'light')
12
12
  # content_tag(:p, :class => 'dark') do ... end
13
13
  # parameters: content_tag(name, content=nil, options={})
14
- # options = { :concat => true/false }
15
14
  def content_tag(*args, &block)
16
15
  name = args.first
17
16
  options = args.extract_options!
18
- options.reverse_merge!(:concat => true) if block_given?
19
- should_concat = options.delete(:concat)
20
17
  tag_html = block_given? ? capture_html(&block) : args[1]
21
18
  tag_result = tag(name, options.merge(:content => tag_html))
22
- should_concat ? concat_content(tag_result) : tag_result
19
+ block_is_template?(block) ? concat_content(tag_result) : tag_result
23
20
  end
24
21
  alias content_block_tag content_tag
25
22
 
data/sinatra_more.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi