clot 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,233 @@
1
+ require 'clot/tag_helper'
2
+
3
+ module Clot
4
+ module AttributeSetter
5
+ def set_primary_attributes(context)
6
+ @id_string = @name_string = resolve_value(@params.shift,context)
7
+ if @params[0] && ! @params[0].match(/:/)
8
+ @value_string = resolve_value(@params.shift,context)
9
+ end
10
+ end
11
+
12
+ def personal_attributes(name,value)
13
+
14
+ end
15
+
16
+
17
+ def set_attributes(context)
18
+ set_primary_attributes(context)
19
+
20
+ @params.each do |pair|
21
+ pair.match /([^:]*):(.*)/
22
+ pair = [$1, $2]
23
+ value = resolve_value(pair[1],context)
24
+ if personal_attributes(pair[0], value)
25
+ next
26
+ end
27
+
28
+ case pair[0]
29
+ when "value" then
30
+ @value_string = value
31
+ when "type" then
32
+ @type = value
33
+ when "accept" then
34
+ @accept_string = %{accept="#{CGI::unescape value}" }
35
+ when "class" then
36
+ @class_string = %{class="#{value}" }
37
+ when "onchange" then
38
+ @onchange_string = %{onchange="#{value}" }
39
+ when "maxlength" then
40
+ @max_length_string = %{maxlength="#{value}" }
41
+ when "disabled" then
42
+ @disabled_string = %{disabled="#{if (value == true || value == "disabled") then 'disabled' end}" }
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ class ClotTag < Liquid::Tag
49
+ include AttributeSetter
50
+ include TagHelper
51
+ def initialize(name, params, tokens)
52
+ @_params = split_params(params)
53
+ super
54
+ end
55
+
56
+ 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
63
+ end
64
+ @params = @_params.clone
65
+ set_attributes(context)
66
+ render_string
67
+ end
68
+
69
+ end
70
+
71
+
72
+ class InputTag < ClotTag
73
+
74
+ def personal_attributes(name,value)
75
+ case name
76
+ when "size" then
77
+ @size_string = %{size="#{value}" }
78
+ when "width" then
79
+ @size_string = %{width="#{value}" }
80
+ end
81
+ end
82
+
83
+ def render_string
84
+ unless @value_string.nil?
85
+ @value_string = CGI::escapeHTML(@value_string.to_s)
86
+ @value_string = %{value="#{@value_string}" }
87
+ end
88
+ %{<input #{@accept_string}#{@disabled_string}#{@class_string}id="#{@id_string}" #{@max_length_string}name="#{@name_string}" #{@size_string}#{@onchange_string}type="#{@type}" #{@value_string}/>}
89
+ end
90
+ end
91
+
92
+ class HiddenFieldTag < InputTag
93
+
94
+ def render_string
95
+ @type = "hidden"
96
+ super
97
+ end
98
+ end
99
+
100
+ class PasswordFieldTag < InputTag
101
+
102
+ def render_string
103
+ @type = "password"
104
+ super
105
+ end
106
+ end
107
+
108
+ class TextFieldTag < InputTag
109
+
110
+ def render_string
111
+ @type ||= "text"
112
+ super
113
+ end
114
+ end
115
+
116
+ class FileFieldTag < InputTag
117
+
118
+ def render_string
119
+ @type = "file"
120
+ super
121
+ end
122
+ end
123
+
124
+ class TextAreaTag < ClotTag
125
+ def personal_attributes(name,value)
126
+
127
+ case name
128
+ when "cols" then
129
+ @col_string = %{cols="#{value}" }
130
+ when "rows" then
131
+ @row_string = %{ rows="#{value}"}
132
+ when "size" then
133
+ size_array = value.split /x/
134
+ @col_string = %{cols="#{size_array[0]}" }
135
+ @row_string = %{ rows="#{size_array[1]}"}
136
+ end
137
+ end
138
+
139
+ def render_string
140
+ %{<textarea #{@disabled_string}#{@class_string}#{@col_string}id="#{@id_string}" name="#{@name_string}"#{@row_string}>#{@value_string}</textarea>}
141
+ end
142
+ end
143
+
144
+ class SubmitTag < ClotTag
145
+
146
+ def personal_attributes(name,value)
147
+ case name
148
+ when "name" then
149
+ if value.nil? then @commit_name_string = '' end
150
+ when "disable_with" then
151
+ @onclick_string = %{onclick="this.disabled=true;this.value='#{value}';this.form.submit();" }
152
+ end
153
+ end
154
+
155
+ def set_primary_attributes(context)
156
+ @value_string = "Save changes"
157
+ @commit_name_string = 'name="commit" '
158
+ if @params[0] && ! @params[0].match(/:/)
159
+ @value_string = resolve_value @params.shift, context
160
+ end
161
+ end
162
+
163
+ def render_string
164
+ %{<input #{@class_string}#{@onclick_string}#{@disabled_string}type="submit" #{@commit_name_string}value="#{@value_string}" />}
165
+ end
166
+
167
+ end
168
+
169
+ class SelectTag < ClotTag
170
+
171
+ def personal_attributes(name,value)
172
+ case name
173
+ when 'multiple' then
174
+ @multiple_string = %{multiple="#{value == "true" ? "multiple" : ""}" }
175
+ when 'prompt' then
176
+ @prompt_option = %{<option value="">#{value}</option>}
177
+ end
178
+ end
179
+
180
+ def render_string
181
+ %{<select #{@disabled_string}#{@class_string}id="#{@id_string}" #{@multiple_string}name="#{@name_string}#{unless @multiple_string.nil? then '[]' end}">#{@prompt_option}#{@value_string}</select>}
182
+ end
183
+
184
+ end
185
+
186
+
187
+ class LabelTag < ClotTag
188
+ def render_string
189
+ @value_string ||= @name_string.humanize
190
+ %{<label #{@class_string}for="#{@id_string}">#{@value_string}</label>}
191
+ end
192
+
193
+ def personal_attributes(name,value)
194
+ case name
195
+ when 'value' then
196
+ @id_string << "_#{value}"
197
+ end
198
+ end
199
+
200
+ end
201
+
202
+ class CheckBoxTag < ClotTag
203
+ def personal_attributes(name,value)
204
+ case name
205
+ when 'collection' then
206
+ @checkbox_collection = value
207
+ when 'member' then
208
+ @checkbox_member = value
209
+ if (! @checkbox_collection.nil?) && @checkbox_collection.include?(@checkbox_member)
210
+ @checked_value = %{checked="checked" }
211
+ end
212
+ end
213
+ end
214
+
215
+
216
+ def set_primary_attributes(context)
217
+ super context
218
+ if @params[0] && ! @params[0].match(/:/)
219
+ checked = resolve_value @params.shift, context
220
+ if checked
221
+ @checked_value = %{checked="checked" }
222
+ end
223
+ end
224
+ end
225
+
226
+ def render_string
227
+ @value_string ||= 1
228
+ %{<input #{@disabled_string}#{@class_string}#{@checked_value}id="#{@id_string}" name="#{@name_string}" type="checkbox" value="#{@value_string}" />}
229
+ end
230
+ end
231
+
232
+
233
+ end
@@ -0,0 +1,22 @@
1
+ module Clot
2
+ module TagHelper
3
+ def split_params(params)
4
+ params.split(",").map(&:strip)
5
+ end
6
+
7
+ def resolve_value(value,context)
8
+ case value
9
+ when /^([\[])(.*)([\]])$/ then array = $2.split " "; array.map { |item| resolve_value item, context }
10
+ when /^(["'])(.*)\1$/ then $2
11
+ when /^(\d+[\.]\d+)$/ then $1.to_f
12
+ when /^(\d+)$/ then value.to_i
13
+ when /^true$/ then true
14
+ when /^false$/ then false
15
+ when /^nil$/ then nil
16
+ when /^(.+)_path$/ then "/#{$1}"
17
+ else context[value]
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ module Clot
2
+ module UrlFilters
3
+
4
+ # include ActionView::Helpers::TagHelper
5
+
6
+ #get url from object
7
+ def object_url(target, class_name = "")
8
+ if (class_name.blank?)
9
+ class_name = target.dropped_class.to_s.tableize
10
+ end
11
+ '/forms/' + class_name + "/" + target.id.to_s
12
+ end
13
+
14
+ #get url from object and nested object
15
+ def get_nested_url(target, nested_target, class_name = "", nested_class_name = "")
16
+ child_url = (nested_target.kind_of? String) ? nested_target : object_url(nested_target, nested_class_name)
17
+ object_url(target, class_name) + child_url
18
+ end
19
+
20
+ #get url from object and nested object
21
+ def get_nested_edit_url(target, nested_target, class_name = "", nested_class_name = "")
22
+ object_url(target, class_name) + object_url(nested_target, nested_class_name) + "/edit"
23
+ end
24
+
25
+ def stylesheet_url(sheetname)
26
+ url = "/stylesheets/" + sheetname + ".css"
27
+ url
28
+ end
29
+
30
+ def edit_link(obj, text="Edit")
31
+ url = ( obj.kind_of?( Liquid::Drop ) ? object_url( obj ) : obj )
32
+ "<a href=\"#{url}/edit\">#{text}</a>"
33
+ end
34
+
35
+ def delete_link(obj, text="Delete")
36
+ url = ( obj.kind_of?( Liquid::Drop ) ? object_url( obj ) : obj )
37
+ "<a href=\"#{url}/delete\">#{text}</a>"
38
+ end
39
+
40
+ def view_link(obj, text=nil)
41
+ url = ( obj.kind_of?( Liquid::Drop ) ? object_url( obj ) : obj )
42
+ "<a href=\"#{url}\">#{text ? text : url.capitalize}</a>"
43
+ end
44
+
45
+ def index_link(obj, text=nil)
46
+ url = ( obj.kind_of?( Liquid::Drop ) ? object_url( obj ) : obj )
47
+ "<a href=\"/#{url}\">#{text ? text : url.capitalize+' Index'}</a>"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,59 @@
1
+ module Clot
2
+ class Yield < Liquid::Tag
3
+ include Liquid
4
+
5
+ Syntax = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?/
6
+
7
+ def initialize(tag_name, markup, tokens)
8
+ @blocks = []
9
+ @naked_yield = false
10
+
11
+ if markup =~ Syntax
12
+
13
+ @template_name = $1
14
+ @variable_name = $3
15
+ @attributes = {}
16
+
17
+ markup.scan(TagAttributes) do |key, value|
18
+ @attributes[key] = value
19
+ end
20
+ elsif !( markup =~ /\w/ )
21
+ @naked_yield = true
22
+ else
23
+ raise SyntaxError.new("Syntax error in tag 'yield' - Valid syntax: yield '[template]' (with|for) [object|collection]")
24
+ end
25
+
26
+ super
27
+ end
28
+
29
+ def render(context)
30
+ if @naked_yield
31
+ return context['content_for_layout']
32
+ else
33
+ partial = Liquid::Template.load_theme(context, @template_name)
34
+ #source = Liquid::Template.file_system.read_template_file( "#{context['controller_name']}/#{context['action_name']}/#{@template_name}")
35
+ #partial = Liquid::Template.parse(source)
36
+
37
+ variable = context[@variable_name || @template_name[1..-2]]
38
+
39
+ context.stack do
40
+ @attributes.each do |key, value|
41
+ context[key] = context[value]
42
+ end
43
+
44
+ if variable.is_a?(Array)
45
+
46
+ variable.collect do |variable|
47
+ context[@template_name[1..-2]] = variable
48
+ partial.render(context)
49
+ end
50
+
51
+ else
52
+ context[@template_name[1..-2]] = variable
53
+ partial.render(context)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clot
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jim Gilliam, Alexander Negoda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
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
30
+ description: Extensions for solidifying Liquid Templates
31
+ email:
32
+ - alexander.negoda@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/clot/if_content_for.rb
38
+ - lib/clot/active_record/droppable.rb
39
+ - lib/clot/url_filters.rb
40
+ - lib/clot/no_model_form_tags.rb
41
+ - lib/clot/mongo_mapper/droppable.rb
42
+ - lib/clot/form_tag.rb
43
+ - lib/clot/date_tags.rb
44
+ - lib/clot/link_filters.rb
45
+ - lib/clot/tag_helper.rb
46
+ - lib/clot/model_form_tags.rb
47
+ - lib/clot/model_date_tags.rb
48
+ - lib/clot/content_for.rb
49
+ - lib/clot/form_for.rb
50
+ - lib/clot/base_drop.rb
51
+ - lib/clot/deprecated.rb
52
+ - lib/clot/yield.rb
53
+ - lib/clot/form_filters.rb
54
+ - lib/clot/nav_bar.rb
55
+ - lib/autotest/discover.rb
56
+ - lib/clot.rb
57
+ homepage: https://github.com/greendog/clots
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Clot
81
+ test_files: []