express_templates 0.11.1 → 0.11.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: 77351e951a43fa098f87369232be07e4c7557a08
4
- data.tar.gz: e58f2909cae09e642f7e3411fa047acc43f8b0d9
3
+ metadata.gz: e8864575cad4427903f6f29d98dd7c4b6853033a
4
+ data.tar.gz: e75fa4c6ca726c66a7cc18797a9c00c54bfd40b4
5
5
  SHA512:
6
- metadata.gz: 3891a36f53ab4f754338f3d6b0ef2174fa228e2cf58b7f7afd9675df6d79f3b7365c8ab40ac492cdd183a0f729d53ec82e9831c89b407049679de949ec43f1a3
7
- data.tar.gz: 52a0c2d8747cb396134ca8df04b7c53779d7ea5e975e740b54018b50c3e39b76aca1b889e7e62bd47f4feed5b006147f57b0caaa589be51d75a7d6aa010d0823
6
+ metadata.gz: 927d0c3eb74ccdb049b95ed85ed783243b6ad5c0ce5beb379f07a33ddf8e91c297af95fdb5c7c7c075d0b0e134a05e24f9b58c83d999e1f2a6a9d7a146776900
7
+ data.tar.gz: b21f56f1b31bda2a10b761674d534f5651cedf992765a369f3fee533244ccd7a70a0a9d7ded2541eb550a3de815146338bb05ce63f899a26454a87451195d546
@@ -1,26 +1,28 @@
1
1
  module ExpressTemplates
2
2
  module Components
3
- class All < Container
3
+ module Presenters
4
+ class All < Container
4
5
 
5
- has_argument :id, "Name of the collection", as: :collection_name, type: :symbol
6
+ has_argument :id, "Name of the collection", as: :collection_name, type: :symbol
6
7
 
7
- contains -> (&block) {
8
- prepended
9
- collection.each do |item|
10
- assigns[member_name.to_sym] = item
11
- block.call(self) if block
8
+ contains -> (&block) {
9
+ prepended
10
+ collection.each do |item|
11
+ assigns[member_name.to_sym] = item
12
+ block.call(self) if block
13
+ end
14
+ appended
15
+ }
16
+
17
+ def member_name
18
+ config[:collection_name].to_s.singularize.to_sym
12
19
  end
13
- appended
14
- }
15
20
 
16
- def member_name
17
- config[:collection_name].to_s.singularize.to_sym
18
- end
21
+ def collection
22
+ self.send(config[:collection_name])
23
+ end
19
24
 
20
- def collection
21
- self.send(config[:collection_name])
22
25
  end
23
-
24
26
  end
25
27
  end
26
28
  end
@@ -10,6 +10,7 @@ require 'express_templates/components/forms/form_component'
10
10
  require 'express_templates/components/forms/option_support'
11
11
  require 'express_templates/components/forms/submit'
12
12
  require 'express_templates/components/forms/select'
13
+ require 'express_templates/components/forms/country_select'
13
14
  require 'express_templates/components/forms/select_collection'
14
15
  require 'express_templates/components/forms/radio'
15
16
  require 'express_templates/components/forms/checkbox'
@@ -0,0 +1,23 @@
1
+ require 'countries'
2
+ require_relative 'select'
3
+
4
+ module ExpressTemplates
5
+ module Components
6
+ module Forms
7
+ class CountrySelect < Select
8
+
9
+ def select_options
10
+ country_options = ISO3166::Country.all.map {|country| [country.name.titleize, country.alpha2]}
11
+ us = country_options.delete(['United States', 'US'])
12
+ country_options.unshift us
13
+ helpers.options_for_select(country_options, selected_value)
14
+ end
15
+
16
+ def select_helper_options
17
+ add_select2_class( input_attributes.merge(include_blank: false, prompt: "-- Please Select --" ) )
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,85 +1,87 @@
1
1
  module ExpressTemplates
2
2
  module Components
3
- #
4
- # Create an html <tt>table</tt> or <tt>ol</tt> (ordered list) for
5
- # a model object representing a tree of similar objects.
6
- #
7
- # The objects must respond to <tt>:children</tt>.
8
- #
9
- # The block is passed a NodeBuilder which may accept field names.
10
- #
11
- # Example:
12
- #
13
- # ```ruby
14
- # tree_for(:roles) { |role|
15
- # role.name
16
- # }
17
- # ```
18
- #
19
- # If the view has an @roles variable with a Role having children,
20
- # this will turn into markup such as the following:
21
- #
22
- # <ul id="roles" class="roles tree">
23
- # <li>SuperAdmin
24
- # <ul>
25
- # <li>Admin
26
- # <ul>
27
- # <li>Publisher
28
- # <ul>
29
- # <li>Author</li>
30
- # </ul>
31
- # </li>
32
- # <li>Auditor</li>
33
- # </ul>
34
- # </li>
35
- # </ul>
36
- # </li>
37
- # </ul>
38
- #
3
+ module Presenters
4
+ #
5
+ # Create an html <tt>table</tt> or <tt>ol</tt> (ordered list) for
6
+ # a model object representing a tree of similar objects.
7
+ #
8
+ # The objects must respond to <tt>:children</tt>.
9
+ #
10
+ # The block is passed a NodeBuilder which may accept field names.
11
+ #
12
+ # Example:
13
+ #
14
+ # ```ruby
15
+ # tree_for(:roles) { |role|
16
+ # role.name
17
+ # }
18
+ # ```
19
+ #
20
+ # If the view has an @roles variable with a Role having children,
21
+ # this will turn into markup such as the following:
22
+ #
23
+ # <ul id="roles" class="roles tree">
24
+ # <li>SuperAdmin
25
+ # <ul>
26
+ # <li>Admin
27
+ # <ul>
28
+ # <li>Publisher
29
+ # <ul>
30
+ # <li>Author</li>
31
+ # </ul>
32
+ # </li>
33
+ # <li>Auditor</li>
34
+ # </ul>
35
+ # </li>
36
+ # </ul>
37
+ # </li>
38
+ # </ul>
39
+ #
39
40
 
40
- class TreeFor < Configurable
41
+ class TreeFor < Configurable
41
42
 
42
- tag :ul
43
+ tag :ul
43
44
 
44
- has_attributes :class => 'tree'
45
- has_option :root, "Root of the tree. Defaults to collection with the same as the id.", type: :proc
45
+ has_attributes :class => 'tree'
46
+ has_option :root, "Root of the tree. Defaults to collection with the same as the id.", type: :proc
46
47
 
47
- contains -> (&customize_block) {
48
- @customize_block = customize_block
49
- list_items(root_node)
50
- }
48
+ contains -> (&customize_block) {
49
+ @customize_block = customize_block
50
+ list_items(root_node)
51
+ }
51
52
 
52
- before_build -> {
53
- add_class config[:id]
54
- }
53
+ before_build -> {
54
+ add_class config[:id]
55
+ }
55
56
 
56
- def root_node
57
- if config[:root] && config[:root].respond_to?(:call)
58
- config[:root].call
59
- else
60
- send(config[:id])
57
+ def root_node
58
+ if config[:root] && config[:root].respond_to?(:call)
59
+ config[:root].call
60
+ else
61
+ send(config[:id])
62
+ end
61
63
  end
62
- end
63
64
 
64
- def list_items(nodes)
65
- nodes.each do |node|
66
- list_item(node)
65
+ def list_items(nodes)
66
+ nodes.each do |node|
67
+ list_item(node)
68
+ end
67
69
  end
68
- end
69
70
 
70
- def list_item(node)
71
- li {
72
- if @customize_block
73
- @customize_block.call(node)
74
- else
75
- text_node "#{node.name}#{"\n" if node.children.any?}"
76
- end
77
- if node.children.any?
78
- ul {
79
- list_items(node.children)
80
- }
81
- end
82
- }
71
+ def list_item(node)
72
+ li {
73
+ if @customize_block
74
+ @customize_block.call(node)
75
+ else
76
+ text_node "#{node.name}#{"\n" if node.children.any?}"
77
+ end
78
+ if node.children.any?
79
+ ul {
80
+ list_items(node.children)
81
+ }
82
+ end
83
+ }
84
+ end
83
85
  end
84
86
  end
85
87
  end
@@ -10,9 +10,10 @@ module ExpressTemplates
10
10
  def call(template)
11
11
  # call ripper stuff method
12
12
 
13
- warn_contains_logic("(#{ExpressTemplates.compile(template)}).html_safe") # pass the source code
14
13
  # returns a string to be eval'd
15
- "(#{ExpressTemplates.compile(template)}).html_safe"
14
+ source = "(#{ExpressTemplates.compile(template)}).html_safe"
15
+ warn_contains_logic(source) # pass the source code
16
+ source
16
17
  end
17
18
 
18
19
  def warn_contains_logic(compiled_template)
@@ -1,3 +1,3 @@
1
1
  module ExpressTemplates
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+ require 'ostruct'
3
+ class CountrySelectTest < ActiveSupport::TestCase
4
+
5
+ def assigns
6
+ {person: ::Person.new}
7
+ end
8
+
9
+ def helpers
10
+ mock_action_view do
11
+ def people_path
12
+ '/people'
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+ test "country_select renders without an error" do
19
+ assert arbre {
20
+ express_form(:person) {
21
+ country_select :country_code
22
+ }
23
+ }
24
+ end
25
+
26
+ test "can change label for country_select" do
27
+ html = arbre {
28
+ express_form(:person) {
29
+ country_select :country_code, label: "Country"
30
+ }
31
+ }
32
+ assert_match(/<label.*Country<\/label>/, html)
33
+ end
34
+ end
data/test/test_helper.rb CHANGED
@@ -126,7 +126,7 @@ end
126
126
  end
127
127
  end
128
128
  class ::Person
129
- attr :id, :city, :subscribed, :preferred_email_format
129
+ attr :id, :city, :subscribed, :preferred_email_format, :country_code
130
130
  def initialize(id = 1, city = 'San Francisco')
131
131
  @id, @city = id, city
132
132
  end
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.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-02 00:00:00.000000000 Z
12
+ date: 2015-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: countries
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: rails
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,7 @@ files:
192
206
  - lib/express_templates/components/forms.rb
193
207
  - lib/express_templates/components/forms/basic_fields.rb
194
208
  - lib/express_templates/components/forms/checkbox.rb
209
+ - lib/express_templates/components/forms/country_select.rb
195
210
  - lib/express_templates/components/forms/express_form.rb
196
211
  - lib/express_templates/components/forms/form_component.rb
197
212
  - lib/express_templates/components/forms/option_support.rb
@@ -212,6 +227,7 @@ files:
212
227
  - test/components/configurable_test.rb
213
228
  - test/components/forms/basic_fields_test.rb
214
229
  - test/components/forms/checkbox_test.rb
230
+ - test/components/forms/country_select_test.rb
215
231
  - test/components/forms/express_form_test.rb
216
232
  - test/components/forms/radio_test.rb
217
233
  - test/components/forms/select_test.rb
@@ -291,6 +307,7 @@ test_files:
291
307
  - test/components/configurable_test.rb
292
308
  - test/components/forms/basic_fields_test.rb
293
309
  - test/components/forms/checkbox_test.rb
310
+ - test/components/forms/country_select_test.rb
294
311
  - test/components/forms/express_form_test.rb
295
312
  - test/components/forms/radio_test.rb
296
313
  - test/components/forms/select_test.rb