sequent-sinatra 0.1.5 → 0.1.6

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
- SHA1:
3
- metadata.gz: 97c87c781855a940c9c66574a9f68342d159ea66
4
- data.tar.gz: 287e0f1e73c596ef6a814df83831bf8f6ce13e8d
2
+ SHA256:
3
+ metadata.gz: 4e8b3cbd50679e6f42d91f38e4f470d13a303c392dea54ce26cb5e8f3ad13450
4
+ data.tar.gz: 17ce0801d05b66d645dfeb3d187f7adad57b87e7f18cb27aaf2310d99c564fad
5
5
  SHA512:
6
- metadata.gz: 00a7d067aeb7a22595443ffd3303f6ca8f57cb3d7d1941d2ff5289f064c3c8b44a09da57372274b9310c862291c04e86cda0d9d9a2bad5c7a10ce35f44da846c
7
- data.tar.gz: 59a215973ffc08a03604ad3981ba4b430e4f416c662c7d1900e4ece04b58a0227ddf1b590fcae4c48ad13469e000d1d611d24c3d5144f2e82f93c5e3726e9aa3
6
+ metadata.gz: 20e726ce805af874678c436b2b03441eba03ec090312404acdd652e2fd2e50131d5efc8dd5f5366e45775dc3e0929d1a14d44843185bb54f724754da10d7c7f8
7
+ data.tar.gz: 541cd0f638019aaac3c0b0fae67d94d7257a1c2a005809a5fdb596ba71bfc2f32f0437007b310b3e6447c9833028ac8b8381ed5cbe7dd2ff3df7020792e7939b
@@ -11,17 +11,20 @@ module Sequent
11
11
  # Parameters
12
12
  # +field+ the name of the attribute within the current object.
13
13
  # +options+ Hash with optional attributes.
14
- # :value - the default checked value if the current object has none
14
+ # :default - the default checked value if the current object has none
15
15
  # :class - the css class
16
16
  def raw_checkbox(field, options={})
17
- id = calculate_id(field)
18
- value = param_or_default(field, options[:value]) || id
17
+ id = options[:id] || calculate_id(field)
18
+ value = param_or_default(field, options.delete(:default), options) || id
19
19
  values = [value].compact
20
+ field_value = param_or_default(field, false)
21
+ checked = options.has_key?(:checked) ? options[:checked] : values.include?(field_value)
22
+ checked = checked ? "checked" : nil
20
23
  single_tag :input, options.merge(
21
24
  :type => "checkbox",
22
25
  :id => id,
23
26
  :name => calculate_name(field),
24
- :value => value, checked: (values.include?(@values[field.to_s])) ? "checked" : nil
27
+ :value => value, checked: checked
25
28
  )
26
29
  end
27
30
 
@@ -31,19 +34,31 @@ module Sequent
31
34
  # Parameters
32
35
  # +field+ the name of the attribute within the current object.
33
36
  # +options+ Hash with optional attributes.
34
- # :value - the default value if the current object has none
37
+ # :default - the default value if the current object has none
35
38
  # :class - the css class
36
39
  def raw_input(field, options={})
37
40
  raw_field(field, "text", options)
38
41
  end
39
42
 
43
+ ##
44
+ # Creates a <input type=email>
45
+ #
46
+ # Parameters
47
+ # +field+ the name of the attribute within the current object.
48
+ # +options+ Hash with optional attributes.
49
+ # :default - the default value if the current object has none
50
+ # :class - the css class
51
+ def raw_email(field, options={})
52
+ raw_field(field, "email", options)
53
+ end
54
+
40
55
  ##
41
56
  # Creates a <input type=password>
42
57
  #
43
58
  # Parameters
44
59
  # +field+ the name of the attribute within the current object.
45
60
  # +options+ Hash with optional attributes.
46
- # :value - the default value if the current object has none
61
+ # :default - the default value if the current object has none
47
62
  # :class - the css class
48
63
  def raw_password(field, options={})
49
64
  raw_field(field, "password", options)
@@ -55,14 +70,14 @@ module Sequent
55
70
  # Parameters
56
71
  # +field+ the name of the attribute within the current object.
57
72
  # +options+ Hash with optional attributes.
58
- # :value - the default value if the current object has none
73
+ # :default - the default value if the current object has none
59
74
  # :class - the css class
60
75
  # :rows - the number of rows of the textarea, default 3
61
76
  def raw_textarea(field, options={})
62
- value = param_or_default(field, options[:value])
63
-
77
+ value = param_or_default(field, options.delete(:default), options)
78
+ id = options[:id] || calculate_id(field)
64
79
  with_closing_tag :textarea, value, {rows: "3"}.merge(options.merge(
65
- :id => calculate_id(field),
80
+ :id => id,
66
81
  :name => calculate_name(field)
67
82
  ))
68
83
  end
@@ -73,7 +88,7 @@ module Sequent
73
88
  # Parameters
74
89
  # +field+ the name of the attribute within the current object.
75
90
  # +options+ Hash with optional attributes.
76
- # :value - the default value if the current object has none
91
+ # :default - the default value if the current object has none
77
92
  # :class - the css class
78
93
  def raw_hidden(field, options={})
79
94
  raw_field(field, "hidden", options)
@@ -86,11 +101,12 @@ module Sequent
86
101
  # +field+ the name of the attribute within the current object.
87
102
  # +values+ an array of pairs (arrays) of [value, text_to_display]
88
103
  # +options+ Hash with optional attributes.
89
- # :value - the default value if the current object has none
104
+ # :default - the default value if the current object has none
90
105
  # :class - the css class
91
106
  def raw_select(field, values, options={})
92
- value = param_or_default(field, options[:value])
107
+ value = param_or_default(field, options.delete(:default), options)
93
108
  content = ""
109
+ css_id = options[:id] || calculate_id(field)
94
110
  Array(values).each do |val|
95
111
  id, text = id_and_text_from_value(val)
96
112
  option_values = {value: id}
@@ -98,7 +114,32 @@ module Sequent
98
114
  option_values.merge!(disabled: "disabled") if options[:disable].try(:include?, id)
99
115
  content << tag(:option, text, option_values)
100
116
  end
101
- tag :select, content, options.merge(id: calculate_id(field), name: calculate_name(field))
117
+ tag :select, content, options.merge(id: css_id, name: calculate_name(field))
118
+ end
119
+
120
+ ##
121
+ # creates a <input type=radio>
122
+ #
123
+ # By default it will check the radio button who's value is present in the backing object
124
+ #
125
+ # Parameters
126
+ # +field+ the name of the attribute within the current object.
127
+ # +options+ Hash with optional attributes.
128
+ # :default - the value of the radio option
129
+ # :checked - does this radio need to be checked
130
+ # :class - the css class
131
+ def raw_radio(field, options = {})
132
+ raise "radio buttons need a value" unless options[:value]
133
+ id = options[:id] || calculate_id(field)
134
+ value = options.delete(:value)
135
+ checked = (value == @values[field.to_s] || options.include?(:checked))
136
+ single_tag :input, options.merge(
137
+ :type => "radio",
138
+ :id => id,
139
+ :name => calculate_name(field),
140
+ :value => value,
141
+ checked: checked ? "checked" : nil
142
+ )
102
143
  end
103
144
 
104
145
  def full_path(field)
@@ -112,7 +153,8 @@ module Sequent
112
153
  "#{reverse_names.first}#{reverse_names[1..-1].map { |n| n == '[]' ? n : "[#{n}]" }.join}"
113
154
  end
114
155
 
115
- def param_or_default(field, default)
156
+ def param_or_default(field, default, options = {})
157
+ return options[:value] if options.has_key?(:value)
116
158
  @values.nil? ? default : @values.has_key?(field.to_s) ? @values[field.to_s] || default : default
117
159
  end
118
160
 
@@ -160,21 +202,30 @@ module Sequent
160
202
  html_attrs.chop
161
203
  end
162
204
 
163
-
164
205
  def raw_field(field, field_type, options)
165
- value = param_or_default(field, options[:value])
206
+ value = param_or_default(field, options.delete(:default), options)
166
207
  if options[:formatter]
167
208
  value = self.send(options[:formatter], value)
168
209
  options.delete(:formatter)
169
210
  end
170
211
  #TODO use calculate_id
171
212
  id = options[:id] || calculate_id(field)
213
+ options.merge!(data_attributes(options.delete(:data)))
172
214
  single_tag :input, options.merge(
173
- :type => field_type,
174
- :id => id,
175
- :name => calculate_name(field),
176
- :value => value
177
- )
215
+ :type => field_type,
216
+ :id => id,
217
+ :name => calculate_name(field),
218
+ :value => value,
219
+ )
220
+ end
221
+
222
+ def data_attributes(data, prefix = 'data')
223
+ case data
224
+ when Hash
225
+ data.reduce({}) { |memo, (key, value)| memo.merge(data_attributes(value, "#{prefix}-#{key}")) }
226
+ else
227
+ { prefix.gsub('_', '-').to_sym => data }
228
+ end
178
229
  end
179
230
 
180
231
  def tree_in_names(field, postfix_method_name)
@@ -1,3 +1,3 @@
1
1
  module SequentSinatra
2
- VERSION='0.1.5'
2
+ VERSION='0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequent-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Vonk
@@ -12,34 +12,54 @@ bindir: bin
12
12
  cert_chain: []
13
13
  date: 2014-04-03 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '5.0'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '5.3'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '5.0'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.3'
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: sequent
17
37
  requirement: !ruby/object:Gem::Requirement
18
38
  requirements:
19
39
  - - "~>"
20
40
  - !ruby/object:Gem::Version
21
- version: '0.1'
41
+ version: '3.1'
22
42
  type: :runtime
23
43
  prerelease: false
24
44
  version_requirements: !ruby/object:Gem::Requirement
25
45
  requirements:
26
46
  - - "~>"
27
47
  - !ruby/object:Gem::Version
28
- version: '0.1'
48
+ version: '3.1'
29
49
  - !ruby/object:Gem::Dependency
30
50
  name: sinatra
31
51
  requirement: !ruby/object:Gem::Requirement
32
52
  requirements:
33
53
  - - "~>"
34
54
  - !ruby/object:Gem::Version
35
- version: '1.4'
55
+ version: '2.0'
36
56
  type: :runtime
37
57
  prerelease: false
38
58
  version_requirements: !ruby/object:Gem::Requirement
39
59
  requirements:
40
60
  - - "~>"
41
61
  - !ruby/object:Gem::Version
42
- version: '1.4'
62
+ version: '2.0'
43
63
  - !ruby/object:Gem::Dependency
44
64
  name: rack_csrf
45
65
  requirement: !ruby/object:Gem::Requirement
@@ -205,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
225
  version: '0'
206
226
  requirements: []
207
227
  rubyforge_project:
208
- rubygems_version: 2.4.5
228
+ rubygems_version: 2.7.6
209
229
  signing_key:
210
230
  specification_version: 4
211
231
  summary: Event sourcing framework for Ruby - Sinatra adapter