dryml 1.3.0.pre14 → 1.3.0.pre15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/dryml/helper.rb +4 -4
- data/lib/dryml.rb +17 -47
- metadata +7 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.0.
|
1
|
+
1.3.0.pre15
|
data/lib/dryml/helper.rb
CHANGED
@@ -31,7 +31,7 @@ module Dryml::Helper
|
|
31
31
|
end
|
32
32
|
res
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def first_item?
|
36
36
|
if scope.repeat_collection.respond_to? :each_pair
|
37
37
|
this == scope.repeat_collection.first.try.last
|
@@ -39,8 +39,8 @@ module Dryml::Helper
|
|
39
39
|
this == scope.repeat_collection.first
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
|
42
|
+
|
43
|
+
|
44
44
|
def last_item?
|
45
45
|
if scope.repeat_collection.respond_to? :each_pair
|
46
46
|
this == scope.repeat_collection.last.try.last
|
@@ -49,7 +49,7 @@ module Dryml::Helper
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
def param_name_for(path)
|
53
53
|
field_path = field_path.to_s.split(".") if field_path.is_one_of?(String, Symbol)
|
54
54
|
attrs = path.rest.map{|part| "[#{part.to_s.sub /\?$/, ''}]"}.join
|
55
55
|
"#{path.first}#{attrs}"
|
data/lib/dryml.rb
CHANGED
@@ -4,19 +4,16 @@
|
|
4
4
|
# Copyright:: Copyright (c) 2008
|
5
5
|
# License:: Distributes under the same terms as Ruby
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
# gem dependencies
|
10
7
|
require 'hobo_support'
|
11
8
|
require 'action_pack'
|
12
9
|
|
13
|
-
ActiveSupport::Dependencies.autoload_paths |= [
|
10
|
+
ActiveSupport::Dependencies.autoload_paths |= [File.dirname(__FILE__)]
|
14
11
|
|
15
12
|
# The Don't Repeat Yourself Markup Language
|
16
13
|
module Dryml
|
17
14
|
|
18
15
|
VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
|
19
|
-
@@root = Pathname.new File.expand_path(
|
16
|
+
@@root = Pathname.new File.expand_path('../..', __FILE__)
|
20
17
|
def self.root; @@root; end
|
21
18
|
|
22
19
|
class DrymlSyntaxError < RuntimeError; end
|
@@ -32,22 +29,15 @@ module Dryml
|
|
32
29
|
end
|
33
30
|
|
34
31
|
TagDef = Struct.new "TagDef", :name, :attrs, :proc
|
35
|
-
|
36
32
|
RESERVED_WORDS = %w{if for while do class else elsif unless case when module in}
|
37
|
-
|
38
33
|
ID_SEPARATOR = '; dryml-tag: '
|
39
34
|
APPLICATION_TAGLIB = { :src => "taglibs/application" }
|
40
35
|
CORE_TAGLIB = { :src => "core", :plugin => "dryml" }
|
41
|
-
|
42
36
|
DEFAULT_IMPORTS = defined?(ApplicationHelper) ? [ApplicationHelper] : []
|
43
|
-
|
44
37
|
@cache = {}
|
45
|
-
|
46
38
|
extend self
|
47
|
-
|
48
39
|
attr_accessor :last_if
|
49
40
|
|
50
|
-
|
51
41
|
def precompile_taglibs
|
52
42
|
Dir.chdir(Rails.root) do
|
53
43
|
Dir["app/views/taglibs/**/*.dryml"].each do |f|
|
@@ -56,7 +46,6 @@ module Dryml
|
|
56
46
|
end
|
57
47
|
end
|
58
48
|
|
59
|
-
|
60
49
|
def clear_cache
|
61
50
|
@cache = {}
|
62
51
|
end
|
@@ -66,7 +55,6 @@ module Dryml
|
|
66
55
|
renderer.render_tag(tag, options)
|
67
56
|
end
|
68
57
|
|
69
|
-
|
70
58
|
def empty_page_renderer(view)
|
71
59
|
page_renderer(view, page_tag_identifier(view.controller.controller_path))
|
72
60
|
end
|
@@ -87,10 +75,8 @@ module Dryml
|
|
87
75
|
end
|
88
76
|
end
|
89
77
|
|
90
|
-
|
91
78
|
def page_renderer(view, identifier, local_names=[], controller_path=nil)
|
92
79
|
controller_path ||= view.controller.controller_path
|
93
|
-
# prepare_view!(view)
|
94
80
|
if identifier =~ /#{ID_SEPARATOR}/
|
95
81
|
identifier = identifier.split(ID_SEPARATOR).first
|
96
82
|
@cache[identifier] ||= make_renderer_class("", "", local_names, taglibs_for(controller_path))
|
@@ -111,7 +97,6 @@ module Dryml
|
|
111
97
|
end
|
112
98
|
end
|
113
99
|
|
114
|
-
|
115
100
|
def get_field(object, field)
|
116
101
|
return nil if object.nil?
|
117
102
|
field_str = field.to_s
|
@@ -126,14 +111,21 @@ module Dryml
|
|
126
111
|
end
|
127
112
|
end
|
128
113
|
|
114
|
+
def get_field(object, field)
|
115
|
+
return nil if object.nil?
|
116
|
+
field_str = field.to_s
|
117
|
+
case
|
118
|
+
when object.respond_to?(field_str)
|
119
|
+
object.send(field_str)
|
120
|
+
when field_str =~ /^\d+$/
|
121
|
+
object[field.to_i]
|
122
|
+
else
|
123
|
+
object[field]
|
124
|
+
end
|
125
|
+
end
|
129
126
|
|
130
127
|
def get_field_path(object, path)
|
131
|
-
path =
|
132
|
-
path.split('.')
|
133
|
-
else
|
134
|
-
Array(path)
|
135
|
-
end
|
136
|
-
|
128
|
+
path = path.is_a?(String) ? path.split('.') : Array(path)
|
137
129
|
parent = nil
|
138
130
|
path.each do |field|
|
139
131
|
return nil if object.nil?
|
@@ -143,18 +135,12 @@ module Dryml
|
|
143
135
|
[parent, path.last, object]
|
144
136
|
end
|
145
137
|
|
146
|
-
|
147
|
-
|
148
138
|
def unreserve(word)
|
149
139
|
word = word.to_s
|
150
|
-
if RESERVED_WORDS.include?(word)
|
151
|
-
|
152
|
-
else
|
153
|
-
word
|
154
|
-
end
|
140
|
+
word += '_' if RESERVED_WORDS.include?(word)
|
141
|
+
word
|
155
142
|
end
|
156
143
|
|
157
|
-
|
158
144
|
def static_tags
|
159
145
|
@static_tags ||= begin
|
160
146
|
path = if Object.const_defined?(:Rails) && FileTest.exists?("#{Rails.root}/config/dryml_static_tags.txt")
|
@@ -228,20 +214,6 @@ private
|
|
228
214
|
{ :src => src } if Object.const_defined?(:Rails) && File.exists?("#{Rails.root}/app/views/#{src}.dryml")
|
229
215
|
end
|
230
216
|
|
231
|
-
def prepare_view!(view)
|
232
|
-
# Not sure why this isn't done for me...
|
233
|
-
# There's probably a button to press round here somewhere
|
234
|
-
for var in %w(@flash @cookies @action_name @_session @_request @request_origin
|
235
|
-
@request @ignore_missing_templates @_headers @variables_added
|
236
|
-
@_flash @response @template_class
|
237
|
-
@_cookies @before_filter_chain_aborted @url
|
238
|
-
@_response @template_root @headers @_params @params @session)
|
239
|
-
unless @view.instance_variables.include?(var)
|
240
|
-
view.instance_variable_set(var, view.controller.instance_variable_get(var))
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
217
|
# create and compile a renderer class (AKA Dryml::Template::Environment)
|
246
218
|
#
|
247
219
|
# template_src:: the DRYML source
|
@@ -261,7 +233,6 @@ private
|
|
261
233
|
renderer_class
|
262
234
|
end
|
263
235
|
|
264
|
-
|
265
236
|
def compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs=[])
|
266
237
|
template = Dryml::Template.new(template_src, renderer_class, template_path)
|
267
238
|
DEFAULT_IMPORTS.each {|m| template.import_module(m)}
|
@@ -272,7 +243,6 @@ private
|
|
272
243
|
template.compile(all_local_names, [CORE_TAGLIB]+taglibs)
|
273
244
|
end
|
274
245
|
|
275
|
-
|
276
246
|
end
|
277
247
|
|
278
248
|
require 'dryml/railtie' if Object.const_defined?(:Rails)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dryml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -1637175966
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.3.0.
|
10
|
+
- pre15
|
11
|
+
version: 1.3.0.pre15
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Tom Locke
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-11-03 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -43,13 +43,13 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
hash: -
|
46
|
+
hash: -1637175966
|
47
47
|
segments:
|
48
48
|
- 1
|
49
49
|
- 3
|
50
50
|
- 0
|
51
|
-
-
|
52
|
-
version: 1.3.0.
|
51
|
+
- pre15
|
52
|
+
version: 1.3.0.pre15
|
53
53
|
type: :runtime
|
54
54
|
version_requirements: *id002
|
55
55
|
- !ruby/object:Gem::Dependency
|