express_templates 0.11.6 → 0.11.7

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: 25344efbf662faf81ee38e848bbee57bcbff4bbe
4
- data.tar.gz: 58c5eadf5990d90c894c204578279c88f328a1ec
3
+ metadata.gz: de55b6283d4cd228ad658ff1829a4902589af9ed
4
+ data.tar.gz: 5299e6fa7ca41ccf78778c0ed61b5eb6ba0b070f
5
5
  SHA512:
6
- metadata.gz: 766f6ec66e155b356b621bd49b39bef4f9b2512912f574a94fbd69f564c8c2585324320f279c038bf034f6b74e98a01ab685cfdcc4d0871c24b7e423a440a8c4
7
- data.tar.gz: e47c8531c5ba75cb423b4efebf20139ea39e24b38c3a6c73518c54f210ab91cfa79a750098d32e959059ecdf28a464d1615b6bbb422c03319b232064affd971d
6
+ metadata.gz: bdf9b62c3e514c77747efa39d7f8b5c738a04ee536cf9868e14b88b40f594dd1fd39ebfc511732aff8cae1d2282961c002599135135358a7e66ae0744e96282b
7
+ data.tar.gz: abb4d01b06ca7435521c44aec3ec4a0c9a06c2ac298367f49588331ef05282fe4da5548d6768baab4d2c923809318814dc87f46696ee335714160102855e59d1
@@ -7,5 +7,6 @@ require 'express_templates/components/base'
7
7
  require 'express_templates/components/configurable'
8
8
  require 'express_templates/components/container'
9
9
  require 'express_templates/components/tree_for'
10
+ require 'express_templates/components/content_for'
10
11
  require 'express_templates/components/forms'
11
12
  require 'express_templates/components/all'
@@ -22,6 +22,8 @@ module ExpressTemplates
22
22
  # Options specified as required must be supplied.
23
23
  #
24
24
  # Default values may be supplied for options with a default: keyword.
25
+ # The value may be a proc. Useful for instances where you want a different
26
+ # value every time.
25
27
  #
26
28
  # Options may be passed as html attributes with attribute: true
27
29
  #
@@ -85,11 +87,12 @@ module ExpressTemplates
85
87
 
86
88
  def _set_defaults
87
89
  _default_options.each do |key, value|
90
+ default_value = value[:default].respond_to?(:call) ? value[:default].call : value[:default]
88
91
  if !!value[:attribute]
89
- set_attribute key, value[:default]
92
+ set_attribute key, default_value
90
93
  else
91
94
  if config[key].nil?
92
- config[key] = value[:default]
95
+ config[key] = default_value
93
96
  end
94
97
  end
95
98
  end
@@ -0,0 +1,29 @@
1
+ # Proxy component for content_for to prevent it from inserting the block's
2
+ # value into its location.
3
+ class ContentForProxy < Arbre::HTML::Tag
4
+ builder_method :content_for
5
+
6
+ def build(key, content = nil, &block)
7
+ @value = helpers.content_for(key, content, &block)
8
+ end
9
+
10
+ def to_s
11
+ @value
12
+ end
13
+ end
14
+
15
+ # Patch to #capture to support Arbre::Element
16
+ module ActionView
17
+ module Helpers
18
+ module CaptureHelper
19
+ def capture(*args)
20
+ value = nil
21
+ buffer = with_output_buffer { value = yield(*args) }
22
+ value = value.to_s if value.is_a? Arbre::Element
23
+ if string = buffer.presence || value and string.is_a?(String)
24
+ ERB::Util.html_escape string
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module ExpressTemplates
2
- VERSION = "0.11.6"
2
+ VERSION = "0.11.7"
3
3
  end
@@ -51,11 +51,24 @@ class ConfigurableTest < ActiveSupport::TestCase
51
51
  has_option :rows, 'Number of rows', type: :integer, default: 5, attribute: true
52
52
  end
53
53
 
54
+ class ConfigWithDefaultProcOption < ETCC
55
+ has_option(:rows, 'Number of rows', {
56
+ type: :integer,
57
+ default: -> { %w(some random word).sample },
58
+ attribute: true,
59
+ })
60
+ end
61
+
54
62
  test "default values are supported" do
55
63
  markup = render { config_with_default_option }
56
64
  assert_equal %Q(<div class="config-with-default-option" rows="5"></div>\n), markup
57
65
  end
58
66
 
67
+ test "default values which are procs are supported" do
68
+ markup = render { config_with_default_proc_option }
69
+ assert_match /(some|random|word)/, markup
70
+ end
71
+
59
72
  test "default values for attributes can be overridden" do
60
73
  markup = render { config_with_default_option(rows: 999) }
61
74
  assert_equal %Q(<div class="config-with-default-option" rows="999"></div>\n), markup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.6
4
+ version: 0.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
@@ -189,6 +189,7 @@ files:
189
189
  - lib/express_templates/components/capabilities/resourceful.rb
190
190
  - lib/express_templates/components/configurable.rb
191
191
  - lib/express_templates/components/container.rb
192
+ - lib/express_templates/components/content_for.rb
192
193
  - lib/express_templates/components/forms.rb
193
194
  - lib/express_templates/components/forms/basic_fields.rb
194
195
  - lib/express_templates/components/forms/checkbox.rb