clot_engine 1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/clot/base_drop.rb +2 -2
- data/lib/clot/form_for.rb +9 -20
- data/lib/clot/model_form_tags.rb +13 -82
- data/lib/clot/no_model_form_tags.rb +18 -11
- data/lib/clot/protected.rb +4 -4
- data/lib/clot/tag_helper.rb +23 -10
- metadata +3 -19
data/lib/clot/base_drop.rb
CHANGED
data/lib/clot/form_for.rb
CHANGED
@@ -20,7 +20,7 @@ module Clot
|
|
20
20
|
@attributes[key] = value
|
21
21
|
end
|
22
22
|
else
|
23
|
-
syntax_error tag_name, markup, tokens
|
23
|
+
syntax_error# tag_name, markup, tokens
|
24
24
|
end
|
25
25
|
super
|
26
26
|
end
|
@@ -81,7 +81,7 @@ module Clot
|
|
81
81
|
@attributes[key] = value
|
82
82
|
end
|
83
83
|
else
|
84
|
-
syntax_error tag_name, markup, tokens
|
84
|
+
syntax_error# tag_name, markup, tokens
|
85
85
|
end
|
86
86
|
super
|
87
87
|
end
|
@@ -91,7 +91,11 @@ module Clot
|
|
91
91
|
if @attributes.has_key?('url_helper')
|
92
92
|
Protected.config = context.registers[:controller]
|
93
93
|
@attributes['url'] = Protected.send(@attributes['url_helper'].to_sym) unless @attributes.has_key?('url_helper_params')
|
94
|
-
|
94
|
+
if params = context[@attributes['url_helper_params']]
|
95
|
+
arg = params.is_a?(String) ? params : params.source
|
96
|
+
@attributes['url'] = Protected.send(@attributes['url_helper'].to_sym, arg)
|
97
|
+
end
|
98
|
+
|
95
99
|
end
|
96
100
|
|
97
101
|
if @attributes.has_key?('html')
|
@@ -195,7 +199,6 @@ module Clot
|
|
195
199
|
@params = @_params.clone
|
196
200
|
@model = context[@params.shift]
|
197
201
|
|
198
|
-
result = ""
|
199
202
|
if @model and @model.respond_to?(:errors) and @model.errors.count > 0
|
200
203
|
@suffix = @model.errors.count > 1 ? "s" : ""
|
201
204
|
@default_message = @model.errors.count.to_s + " error#{@suffix} occurred while processing information"
|
@@ -210,25 +213,11 @@ module Clot
|
|
210
213
|
end
|
211
214
|
end
|
212
215
|
|
213
|
-
|
214
|
-
|
215
|
-
@model.errors.each do |attr, msg|
|
216
|
-
result += "<li>#{error_message(attr, msg)}</li>"
|
217
|
-
end if @model.respond_to? :errors
|
216
|
+
readable_errors = @model.errors.map{ |target, msg| "#{target}: #{msg}" }
|
218
217
|
|
219
|
-
|
218
|
+
{ :message => @default_message, :errors => readable_errors }.to_json
|
220
219
|
end
|
221
|
-
result
|
222
220
|
end
|
223
|
-
|
224
|
-
def error_message(attr, msg)
|
225
|
-
unless attr == :base
|
226
|
-
"#{attr} - #{msg}"
|
227
|
-
else
|
228
|
-
msg
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
221
|
end
|
233
222
|
|
234
223
|
end
|
data/lib/clot/model_form_tags.rb
CHANGED
@@ -3,7 +3,6 @@ module Clot
|
|
3
3
|
def set_primary_attributes(context)
|
4
4
|
@item = context['form_model']
|
5
5
|
if @item
|
6
|
-
|
7
6
|
@attribute_name = resolve_value(@params.shift,context)
|
8
7
|
@first_attr = context['form_class_name']
|
9
8
|
else
|
@@ -50,15 +49,9 @@ module Clot
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def render(context)
|
53
|
-
|
54
|
-
#if @errors.include? @attribute_name
|
55
|
-
# result = "<div class=\"fieldWithErrors\">#{result}</div>"
|
56
|
-
#end
|
57
|
-
result
|
52
|
+
super(context)
|
58
53
|
end
|
59
54
|
|
60
|
-
|
61
|
-
|
62
55
|
end
|
63
56
|
|
64
57
|
class FileField < FileFieldTag
|
@@ -99,84 +92,22 @@ module Clot
|
|
99
92
|
end
|
100
93
|
|
101
94
|
class CollectionSelect < ClotTag
|
102
|
-
|
103
|
-
|
104
|
-
super context
|
105
|
-
if @params[0] && ! @params[0].match(/:/)
|
106
|
-
@collection = resolve_value(@params.shift,context)
|
107
|
-
end
|
108
|
-
@default_id = 'id'
|
109
|
-
@default_name = 'name'
|
110
|
-
if @params[0] && ! @params[0].match(/:/)
|
111
|
-
@default_id = resolve_value(@params.shift,context)
|
112
|
-
end
|
113
|
-
if @params[0] && ! @params[0].match(/:/)
|
114
|
-
@default_name = resolve_value(@params.shift,context)
|
115
|
-
end
|
116
|
-
end
|
95
|
+
# usage:
|
96
|
+
# {% collection_select "order[bill_address_attributes]" method:"country_id", collection:available_countries, value_method:'id', text_method:'name', html_options:"{class:'large-field'}" %}
|
117
97
|
|
118
|
-
def
|
119
|
-
|
120
|
-
item_string = item
|
121
|
-
value_string = ""
|
122
|
-
|
123
|
-
# this line below is for BSON::ObjectId which doesn't respond to :id, but does :_id
|
124
|
-
@default_id = "_id" if @default_id == 'id' and item.respond_to?(:_id)
|
125
|
-
|
126
|
-
# @item = NationSignupDrop
|
127
|
-
# item = NationPlan
|
128
|
-
|
129
|
-
attribute_names = @attribute_name.split('.')
|
130
|
-
|
131
|
-
if item.is_a?(String) || item.is_a?(Fixnum) || item.is_a?(Float)
|
132
|
-
if (@item[@attribute_name.to_sym].to_s == item.to_s) || (@item.respond_to?(@attribute_name.to_sym) && @item.send(@attribute_name.to_sym).to_s == item.to_s)
|
133
|
-
selection_string = ' selected="selected"'
|
134
|
-
end
|
135
|
-
else
|
136
|
-
item_string = item[@default_name.to_sym] || (@item.respond_to?(@attribute_name.to_sym) && @item.send(@default_name.to_sym))
|
137
|
-
value_string = %{ value="#{item[@default_id.to_sym]}"}
|
138
|
-
if @item.class.to_s == "NationSignupDrop" and attribute_names.size == 3 and attribute_names[0] == 'payment_profile' # this is a special case just for 3dna nation signup mongo stuff
|
139
|
-
if attribute_names[1] == 'billing_address'
|
140
|
-
if item[@default_id.to_sym].to_s == @item.source.payment_profile.billing_address[attribute_names[2].to_sym].to_s
|
141
|
-
selection_string = ' selected="selected"'
|
142
|
-
end
|
143
|
-
else
|
144
|
-
if item[@default_id.to_sym].to_s == @item.source.payment_profile[attribute_names[1].to_sym][attribute_names[2].to_sym].to_s
|
145
|
-
selection_string = ' selected="selected"'
|
146
|
-
end
|
147
|
-
end
|
148
|
-
elsif attribute_names.size == 3
|
149
|
-
if item[@default_id.to_sym].to_s == @item[attribute_names[0].to_sym][attribute_names[1].to_sym][attribute_names[2].to_sym].to_s
|
150
|
-
selection_string = ' selected="selected"'
|
151
|
-
end
|
152
|
-
elsif attribute_names.size == 2
|
153
|
-
if item[@default_id.to_sym].to_s == @item[attribute_names.first.to_sym][attribute_names.last.to_sym].to_s
|
154
|
-
selection_string = ' selected="selected"'
|
155
|
-
end
|
156
|
-
else
|
157
|
-
if item[@default_id.to_sym].to_s == @item[@attribute_name.to_sym].to_s
|
158
|
-
selection_string = ' selected="selected"'
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
"<option#{value_string}#{selection_string}>#{item_string}</option>"
|
164
|
-
end
|
98
|
+
def render(context)
|
99
|
+
super(context)
|
165
100
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
101
|
+
# collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
|
102
|
+
method = @attributes['method']
|
103
|
+
collection = @attributes['collection']
|
104
|
+
value_method = @attributes['value_method']
|
105
|
+
text_method = @attributes['text_method']
|
106
|
+
@attributes.has_key?('options') ? options = @attributes['options'] : options = {}
|
107
|
+
@attributes.has_key?('html_options') ? html_options = @attributes['html_options'] : html_options = {}
|
172
108
|
|
173
|
-
def render_string
|
174
|
-
@option_string = "#{@prompt_option}"
|
175
|
-
@collection.each do |item|
|
176
|
-
@option_string << gen_option(item)
|
177
|
-
end
|
178
109
|
|
179
|
-
|
110
|
+
context.registers[:action_view].collection_select(@form_object, method, collection, value_method, text_method, options, html_options)
|
180
111
|
end
|
181
112
|
end
|
182
113
|
|
@@ -46,24 +46,31 @@ module Clot
|
|
46
46
|
end
|
47
47
|
|
48
48
|
class ClotTag < Liquid::Tag
|
49
|
+
Syntax = /([^\s]+)\s+/
|
50
|
+
|
49
51
|
include AttributeSetter
|
50
52
|
include TagHelper
|
51
|
-
|
52
|
-
|
53
|
+
|
54
|
+
def initialize(tag_name, markup, tokens)
|
55
|
+
if markup =~ Syntax
|
56
|
+
@form_object = $1
|
57
|
+
@attributes = {}
|
58
|
+
markup.scan(Liquid::TagAttributes) do |key, value|
|
59
|
+
@attributes[key] = value
|
60
|
+
end
|
61
|
+
else
|
62
|
+
syntax_error tag_name, markup, tokens
|
63
|
+
end
|
53
64
|
super
|
54
65
|
end
|
55
66
|
|
56
67
|
def render(context)
|
57
|
-
|
58
|
-
|
59
|
-
instance_variables.map(&:to_sym).each do |var|
|
60
|
-
unless [:@_params, :@markup, :@tag_name].include? var
|
61
|
-
instance_variable_set var, nil #this is because the same parse tag is re-rendered
|
62
|
-
end
|
68
|
+
@attributes.each do |key, value|
|
69
|
+
@attributes[key] = resolve_value(value, context)
|
63
70
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
71
|
+
|
72
|
+
@form_object = context[@form_object].to_sym if context[@form_object].is_a?(String)
|
73
|
+
@form_object = context[@form_object].source if @form_object.nil? && context[@form_object].is_a?(Liquid::Drop)
|
67
74
|
end
|
68
75
|
|
69
76
|
end
|
data/lib/clot/protected.rb
CHANGED
@@ -5,9 +5,10 @@ module Protected
|
|
5
5
|
|
6
6
|
|
7
7
|
class << self
|
8
|
-
include
|
9
|
-
include Refinery::Core::Engine.routes.url_helpers
|
10
|
-
include
|
8
|
+
#include Spree::Core::Engine.routes.url_helpers
|
9
|
+
#include Refinery::Core::Engine.routes.url_helpers
|
10
|
+
#include Rails.application.routes.url_helpers
|
11
|
+
#include ActionView::Helpers::UrlHelper
|
11
12
|
|
12
13
|
def config=(controller)
|
13
14
|
@controller = controller
|
@@ -21,5 +22,4 @@ module Protected
|
|
21
22
|
@controller
|
22
23
|
end
|
23
24
|
end
|
24
|
-
|
25
25
|
end
|
data/lib/clot/tag_helper.rb
CHANGED
@@ -4,17 +4,30 @@ module Clot
|
|
4
4
|
params.split(",").map(&:strip)
|
5
5
|
end
|
6
6
|
|
7
|
-
def resolve_value(value,context)
|
7
|
+
def resolve_value(value, context)
|
8
8
|
case value
|
9
|
-
when
|
10
|
-
|
11
|
-
when /^(\
|
12
|
-
|
13
|
-
when /^
|
14
|
-
|
15
|
-
when /^
|
16
|
-
|
17
|
-
|
9
|
+
when Liquid::Drop then
|
10
|
+
value.source
|
11
|
+
when /^([\[])(.*)([\]])$/ then
|
12
|
+
array = $2.split " "; array.map { |item| resolve_value item, context }
|
13
|
+
when /^"(\{.*\})"$/ then
|
14
|
+
eval($1) # hash from string
|
15
|
+
when /^(["'])(.*)\1$/ then
|
16
|
+
$2
|
17
|
+
when /^(\d+[\.]\d+)$/ then
|
18
|
+
$1.to_f
|
19
|
+
when /^(\d+)$/ then
|
20
|
+
value.to_i
|
21
|
+
when /^true$/ then
|
22
|
+
true
|
23
|
+
when /^false$/ then
|
24
|
+
false
|
25
|
+
when /^nil$/ then
|
26
|
+
nil
|
27
|
+
when /^(.+)_path$/ then
|
28
|
+
"/#{$1}"
|
29
|
+
else
|
30
|
+
context[value]
|
18
31
|
end
|
19
32
|
end
|
20
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clot_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: mongo_mapper
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.12.0
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.12.0
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: Extensions for solidifying Liquid Templates
|
31
15
|
email:
|
32
16
|
- alexander.negoda@gmail.com
|