dryml 1.3.0.pre12 → 1.3.0.pre13
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.
- data/Rakefile +6 -11
- data/VERSION +1 -1
- data/lib/dryml/railtie/page_tag_resolver.rb +8 -4
- data/lib/dryml/railtie.rb +7 -0
- data/lib/dryml/template.rb +1 -1
- data/lib/dryml/template_environment.rb +3 -4
- data/lib/dryml.rb +217 -218
- data/test/dryml.rdoctest +1 -1
- metadata +7 -8
- data/lib/dryml/railtie/page_tag_handler.rb +0 -13
data/Rakefile
CHANGED
@@ -2,22 +2,17 @@ require 'rake'
|
|
2
2
|
require 'rake/rdoctask'
|
3
3
|
require 'rake/testtask'
|
4
4
|
|
5
|
-
$:.unshift File.expand_path('../lib', __FILE__)
|
6
|
-
$:.unshift File.expand_path('../../hobo_support/lib', __FILE__)
|
7
|
-
require 'dryml' # to get VERSION
|
8
|
-
|
9
5
|
RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
|
10
6
|
RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} -S rubydoctest"
|
11
7
|
|
12
|
-
desc "Default Task"
|
13
|
-
task :default => [ :test ]
|
14
|
-
|
15
8
|
# --- Testing --- #
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
namespace "test" do
|
11
|
+
desc "Run the doctests"
|
12
|
+
task :doctest do |t|
|
13
|
+
files=Dir['test/**/*.rdoctest'].map {|f| File.expand_path(f)}.join(' ')
|
14
|
+
exit(1) if !system("#{RUBYDOCTEST} #{files}")
|
15
|
+
end
|
21
16
|
end
|
22
17
|
|
23
18
|
# --- RDOC --- #
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.0.
|
1
|
+
1.3.0.pre13
|
@@ -9,11 +9,15 @@ module Dryml
|
|
9
9
|
|
10
10
|
def find_templates(name, prefix, partial, details)
|
11
11
|
tag_name = @controller.dryml_fallback_tag || name.dasherize + '-page'
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
method_name = tag_name.to_s.gsub('-', '_')
|
13
|
+
if Dryml.empty_page_renderer(@controller.view_context).respond_to?(method_name)
|
14
|
+
[ActionView::Template.new('', Dryml.page_tag_identifier(@controller.controller_path, tag_name),
|
15
|
+
Dryml::Railtie::TemplateHandler, details)]
|
16
|
+
else
|
17
|
+
[]
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
|
-
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
data/lib/dryml/railtie.rb
CHANGED
@@ -15,5 +15,12 @@ module Dryml
|
|
15
15
|
ActionView::Template.register_template_handler("dryml", Dryml::Railtie::TemplateHandler)
|
16
16
|
end
|
17
17
|
|
18
|
+
initializer 'dryml' do |app|
|
19
|
+
app.config.to_prepare do
|
20
|
+
Dryml.clear_cache
|
21
|
+
Dryml::Taglib.clear_cache
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
18
25
|
end
|
19
26
|
end
|
data/lib/dryml/template.rb
CHANGED
@@ -51,7 +51,7 @@ module Dryml
|
|
51
51
|
def compile(local_names=[], auto_taglibs=[])
|
52
52
|
now = Time.now
|
53
53
|
|
54
|
-
unless @template_path.
|
54
|
+
unless @template_path.blank?
|
55
55
|
p = Pathname.new template_path
|
56
56
|
p = Pathname.new(Rails.root) + p unless p.absolute? || !Object.const_defined?(:Rails)
|
57
57
|
mtime = p.mtime rescue Time.now
|
@@ -26,10 +26,9 @@ module Dryml
|
|
26
26
|
include ActionView::Helpers
|
27
27
|
include Helper ## FIXME remove
|
28
28
|
|
29
|
-
def initialize(
|
30
|
-
unless
|
29
|
+
def initialize(view=nil)
|
30
|
+
unless view.nil?
|
31
31
|
@view = view
|
32
|
-
@_view_name = view_name
|
33
32
|
@_erb_binding = binding
|
34
33
|
@_part_contexts = {}
|
35
34
|
@_scoped_variables = ScopedVariables.new
|
@@ -49,7 +48,7 @@ module Dryml
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
for attr in [:erb_binding, :part_contexts,
|
51
|
+
for attr in [:erb_binding, :part_contexts,
|
53
52
|
:this, :this_parent, :this_field, :this_key,
|
54
53
|
:form_this, :form_field_path, :form_field_names]
|
55
54
|
class_eval "def #{attr}; @_#{attr}; end"
|
data/lib/dryml.rb
CHANGED
@@ -15,265 +15,264 @@ ActiveSupport::Dependencies.autoload_paths |= [ File.dirname(__FILE__)]
|
|
15
15
|
# The Don't Repeat Yourself Markup Language
|
16
16
|
module Dryml
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
18
|
+
VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
|
19
|
+
@@root = Pathname.new File.expand_path(File.dirname(__FILE__) + "/..")
|
20
|
+
def self.root; @@root; end
|
21
|
+
|
22
|
+
class DrymlSyntaxError < RuntimeError; end
|
23
|
+
|
24
|
+
class DrymlException < Exception
|
25
|
+
def initialize(message, path=nil, line_num=nil)
|
26
|
+
if path && line_num
|
27
|
+
super(message + " -- at #{path}:#{line_num}")
|
28
|
+
else
|
29
|
+
super(message)
|
31
30
|
end
|
32
31
|
end
|
32
|
+
end
|
33
33
|
|
34
|
-
|
34
|
+
TagDef = Struct.new "TagDef", :name, :attrs, :proc
|
35
35
|
|
36
|
-
|
36
|
+
RESERVED_WORDS = %w{if for while do class else elsif unless case when module in}
|
37
37
|
|
38
|
-
|
38
|
+
ID_SEPARATOR = '; dryml-tag: '
|
39
|
+
APPLICATION_TAGLIB = { :src => "taglibs/application" }
|
40
|
+
CORE_TAGLIB = { :src => "core", :plugin => "dryml" }
|
39
41
|
|
40
|
-
|
41
|
-
CORE_TAGLIB = { :src => "core", :plugin => "dryml" }
|
42
|
+
DEFAULT_IMPORTS = defined?(ApplicationHelper) ? [ApplicationHelper] : []
|
42
43
|
|
43
|
-
|
44
|
+
@cache = {}
|
44
45
|
|
45
|
-
|
46
|
-
@tag_page_renderer_classes = {}
|
46
|
+
extend self
|
47
47
|
|
48
|
-
|
48
|
+
attr_accessor :last_if
|
49
49
|
|
50
|
-
attr_accessor :last_if
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
Dir.
|
55
|
-
|
56
|
-
taglibs.each do |f|
|
57
|
-
Dryml::Taglib.get(:template_dir => File.dirname(f), :src => File.basename(f).remove(".dryml"))
|
58
|
-
end
|
51
|
+
def precompile_taglibs
|
52
|
+
Dir.chdir(Rails.root) do
|
53
|
+
Dir["app/views/taglibs/**/*.dryml"].each do |f|
|
54
|
+
Taglib.get(:template_dir => File.dirname(f), :src => File.basename(f).remove(".dryml"))
|
59
55
|
end
|
60
56
|
end
|
57
|
+
end
|
61
58
|
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
60
|
+
def clear_cache
|
61
|
+
@cache = {}
|
62
|
+
end
|
67
63
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
def render_tag(view, tag, options={})
|
65
|
+
renderer = empty_page_renderer(view)
|
66
|
+
renderer.render_tag(tag, options)
|
67
|
+
end
|
72
68
|
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
def empty_page_renderer(view)
|
71
|
+
page_renderer(view, page_tag_identifier(view.controller.controller_path))
|
72
|
+
end
|
73
|
+
|
74
|
+
def page_tag_identifier(controller_path, tag_name='')
|
75
|
+
"controller: #{controller_path}#{ID_SEPARATOR}#{tag_name}"
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
def call_render(view, local_assigns, identifier)
|
79
|
+
renderer = page_renderer(view, identifier, local_assigns.keys)
|
80
|
+
this = view.controller.send(:dryml_context) || local_assigns[:this]
|
81
|
+
view.instance_variable_set("@this", this)
|
82
|
+
if identifier =~ /#{ID_SEPARATOR}/
|
83
|
+
tag_name = identifier.split(ID_SEPARATOR).last
|
84
|
+
renderer.render_tag(tag_name, {:with => this} )
|
85
|
+
else
|
84
86
|
renderer.render_page(this, local_assigns).strip
|
85
87
|
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def page_renderer(view, identifier, local_names=[], controller_path=nil)
|
92
|
+
controller_path ||= view.controller.controller_path
|
93
|
+
# prepare_view!(view)
|
94
|
+
if identifier =~ /#{ID_SEPARATOR}/
|
95
|
+
identifier = identifier.split(ID_SEPARATOR).first
|
96
|
+
@cache[identifier] ||= make_renderer_class("", "", local_names, taglibs_for(controller_path))
|
97
|
+
@cache[identifier].new(view)
|
98
|
+
else
|
99
|
+
mtime = File.mtime(identifier)
|
100
|
+
renderer_class = @cache[identifier]
|
101
|
+
# do we need to recompile?
|
102
|
+
if (!renderer_class || # nothing cached?
|
103
|
+
(local_names - renderer_class.compiled_local_names).any? || # any new local names?
|
104
|
+
renderer_class.load_time < mtime) # cache out of date?
|
105
|
+
renderer_class = make_renderer_class(File.read(identifier), identifier,
|
106
|
+
local_names, taglibs_for(controller_path))
|
107
|
+
renderer_class.load_time = mtime
|
108
|
+
@cache[identifier] = renderer_class
|
109
|
+
end
|
110
|
+
renderer_class.new(view)
|
111
|
+
end
|
112
|
+
end
|
86
113
|
|
87
114
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
opt[:controller],
|
97
|
-
false,
|
98
|
-
view.lookup_context.instance_variable_get('@details')).identifier
|
99
|
-
end
|
100
|
-
if page_path.ends_with?(EMPTY_PAGE) || identifier.starts_with?('dryml-page-tag:')
|
101
|
-
controller_class = view.controller.class
|
102
|
-
@tag_page_renderer_classes[controller_class.name] ||=
|
103
|
-
make_renderer_class("", page_path, local_names, DEFAULT_IMPORTS, included_taglibs)
|
104
|
-
@tag_page_renderer_classes[controller_class.name].new(page_path, view)
|
115
|
+
def get_field(object, field)
|
116
|
+
return nil if object.nil?
|
117
|
+
field_str = field.to_s
|
118
|
+
begin
|
119
|
+
return object.send(field_str)
|
120
|
+
rescue NoMethodError => ex
|
121
|
+
if field_str =~ /^\d+$/
|
122
|
+
return object[field.to_i]
|
105
123
|
else
|
106
|
-
|
107
|
-
renderer_class = @renderer_classes[page_path]
|
108
|
-
|
109
|
-
# do we need to recompile?
|
110
|
-
if (!renderer_class || # nothing cached?
|
111
|
-
(local_names - renderer_class.compiled_local_names).any? || # any new local names?
|
112
|
-
renderer_class.load_time < mtime) # cache out of date?
|
113
|
-
renderer_class = make_renderer_class(File.read(identifier), identifier, local_names,
|
114
|
-
DEFAULT_IMPORTS, included_taglibs)
|
115
|
-
renderer_class.load_time = mtime
|
116
|
-
@renderer_classes[page_path] = renderer_class
|
117
|
-
end
|
118
|
-
renderer_class.new(page_path, view)
|
124
|
+
return object[field]
|
119
125
|
end
|
120
126
|
end
|
121
|
-
|
122
|
-
def controller_taglibs(controller_class)
|
123
|
-
controller_class.try.included_taglibs || []
|
124
|
-
end
|
127
|
+
end
|
125
128
|
|
126
129
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
def application_taglibs
|
135
|
-
Dir.chdir(Rails.root) do
|
136
|
-
Dir["app/views/taglibs/application/**/*.dryml"].map{|f| File.basename f, '.dryml'}.map do |n|
|
137
|
-
{ :src => "taglibs/application/#{n}" }
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
130
|
+
def get_field_path(object, path)
|
131
|
+
path = if path.is_a? String
|
132
|
+
path.split('.')
|
133
|
+
else
|
134
|
+
Array(path)
|
135
|
+
end
|
141
136
|
|
142
|
-
|
137
|
+
parent = nil
|
138
|
+
path.each do |field|
|
143
139
|
return nil if object.nil?
|
144
|
-
|
145
|
-
|
146
|
-
return object.send(field_str)
|
147
|
-
rescue NoMethodError => ex
|
148
|
-
if field_str =~ /^\d+$/
|
149
|
-
return object[field.to_i]
|
150
|
-
else
|
151
|
-
return object[field]
|
152
|
-
end
|
153
|
-
end
|
140
|
+
parent = object
|
141
|
+
object = get_field(parent, field)
|
154
142
|
end
|
143
|
+
[parent, path.last, object]
|
144
|
+
end
|
155
145
|
|
156
146
|
|
157
|
-
def get_field_path(object, path)
|
158
|
-
path = if path.is_a? String
|
159
|
-
path.split('.')
|
160
|
-
else
|
161
|
-
Array(path)
|
162
|
-
end
|
163
147
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
[parent, path.last, object]
|
148
|
+
def unreserve(word)
|
149
|
+
word = word.to_s
|
150
|
+
if RESERVED_WORDS.include?(word)
|
151
|
+
word + "_"
|
152
|
+
else
|
153
|
+
word
|
171
154
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def static_tags
|
159
|
+
@static_tags ||= begin
|
160
|
+
path = if Object.const_defined?(:Rails) && FileTest.exists?("#{Rails.root}/config/dryml_static_tags.txt")
|
161
|
+
"#{Rails.root}/config/dryml_static_tags.txt"
|
162
|
+
else
|
163
|
+
File.join(File.dirname(__FILE__), "dryml/static_tags")
|
164
|
+
end
|
165
|
+
File.readlines(path).*.chop
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
attr_writer :static_tags
|
170
|
+
|
171
|
+
# FIXME: This helper seems to be useless, since it does need Rails,
|
172
|
+
# and with Rails it is useless since Dryml does not need Hobo
|
173
|
+
#
|
174
|
+
# Helper function for use outside Hobo/Rails
|
175
|
+
#
|
176
|
+
# Pass the template context in locals[:this]
|
177
|
+
#
|
178
|
+
# This function caches. If the mtime of template_path is older
|
179
|
+
# than the last compilation time, the cached version will be
|
180
|
+
# used. If no template_path is given, template_src is used as the
|
181
|
+
# key to the cache.
|
182
|
+
#
|
183
|
+
# If a local variable is not present when the template is
|
184
|
+
# compiled, it will be ignored when the template is used. In
|
185
|
+
# other words, the variable values may change, but the names may
|
186
|
+
# not.
|
187
|
+
#
|
188
|
+
# included_taglibs is only used during template compilation.
|
189
|
+
#
|
190
|
+
# @param [String] template_src the DRYML source
|
191
|
+
# @param [Hash] locals local variables.
|
192
|
+
# @param [String, nil] template_path the filename of the source.
|
193
|
+
# @param [Array] included_taglibs A list of Taglibs to include. { :src =>
|
194
|
+
# "core", :plugin => "dryml" } is automatically
|
195
|
+
# added to this list.
|
196
|
+
# @param [ActionView::Base] view an ActionView instance
|
197
|
+
def render(template_src, locals={}, template_path=nil, included_taglibs=[], view=nil)
|
198
|
+
template_path ||= template_src
|
199
|
+
view ||= ActionView::Base.new(ActionController::Base.view_paths, {})
|
200
|
+
this = locals.delete(:this) || nil
|
201
|
+
|
202
|
+
renderer_class = Dryml::Template.build_cache[template_path]._?.environment ||
|
203
|
+
make_renderer_class(template_src, template_path, locals.keys)
|
204
|
+
renderer_class.new(view).render_page(this, locals)
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
|
209
|
+
def taglibs_for(controller_path)
|
210
|
+
([APPLICATION_TAGLIB] +
|
211
|
+
application_taglibs() +
|
212
|
+
[subsite_taglib(controller_path)] +
|
213
|
+
(controller_path.camelize+"Controller").constantize.try.included_taglibs||[]).compact
|
214
|
+
end
|
215
|
+
|
216
|
+
def application_taglibs
|
217
|
+
Dir.chdir(Rails.root) do
|
218
|
+
Dir["app/views/taglibs/application/**/*.dryml"].map{|f| File.basename f, '.dryml'}.map do |n|
|
219
|
+
{ :src => "taglibs/application/#{n}" }
|
185
220
|
end
|
186
221
|
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
#
|
198
|
-
#
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
def compile_renderer_class(renderer_class, template_src, template_path, locals, imports, included_taglibs=[])
|
209
|
-
template = Dryml::Template.new(template_src, renderer_class, template_path)
|
210
|
-
imports.each {|m| template.import_module(m)}
|
211
|
-
|
212
|
-
taglibs = [CORE_TAGLIB] + included_taglibs
|
213
|
-
|
214
|
-
# the sum of all the names we've seen so far - eventually we'll be ready for all of 'em
|
215
|
-
all_local_names = renderer_class.compiled_local_names | locals
|
216
|
-
|
217
|
-
template.compile(all_local_names, taglibs)
|
218
|
-
end
|
219
|
-
|
220
|
-
|
221
|
-
def unreserve(word)
|
222
|
-
word = word.to_s
|
223
|
-
if RESERVED_WORDS.include?(word)
|
224
|
-
word + "_"
|
225
|
-
else
|
226
|
-
word
|
222
|
+
end
|
223
|
+
|
224
|
+
def subsite_taglib(controller_path)
|
225
|
+
parts = controller_path.split("/")
|
226
|
+
subsite = parts.length >= 2 ? parts[0..-2].join('_') : "front"
|
227
|
+
src = "taglibs/#{subsite}_site"
|
228
|
+
{ :src => src } if Object.const_defined?(:Rails) && File.exists?("#{Rails.root}/app/views/#{src}.dryml")
|
229
|
+
end
|
230
|
+
|
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))
|
227
241
|
end
|
228
242
|
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# create and compile a renderer class (AKA Dryml::Template::Environment)
|
246
|
+
#
|
247
|
+
# template_src:: the DRYML source
|
248
|
+
# template_path:: the filename of the source. This is used for
|
249
|
+
# caching
|
250
|
+
# locals:: local variables.
|
251
|
+
# imports:: A list of helper modules to import. For example, Hobo
|
252
|
+
# uses [Hobo::Helper, Hobo::Helper::Translations,
|
253
|
+
# ApplicationHelper]
|
254
|
+
# included_taglibs:: A list of Taglibs to include. { :src =>
|
255
|
+
# "core", :plugin => "dryml" } is automatically
|
256
|
+
# added to this list.
|
257
|
+
#
|
258
|
+
def make_renderer_class(template_src, template_path, locals=[], taglibs=[])
|
259
|
+
renderer_class = Class.new(TemplateEnvironment)
|
260
|
+
compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs)
|
261
|
+
renderer_class
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
def compile_renderer_class(renderer_class, template_src, template_path, locals, taglibs=[])
|
266
|
+
template = Dryml::Template.new(template_src, renderer_class, template_path)
|
267
|
+
DEFAULT_IMPORTS.each {|m| template.import_module(m)}
|
268
|
+
|
269
|
+
# the sum of all the names we've seen so far - eventually we'll be ready for all of 'em
|
270
|
+
all_local_names = renderer_class.compiled_local_names | locals
|
271
|
+
|
272
|
+
template.compile(all_local_names, [CORE_TAGLIB]+taglibs)
|
273
|
+
end
|
229
274
|
|
230
275
|
|
231
|
-
def static_tags
|
232
|
-
@static_tags ||= begin
|
233
|
-
path = if Object.const_defined?(:Rails) && FileTest.exists?("#{Rails.root}/config/dryml_static_tags.txt")
|
234
|
-
"#{Rails.root}/config/dryml_static_tags.txt"
|
235
|
-
else
|
236
|
-
File.join(File.dirname(__FILE__), "dryml/static_tags")
|
237
|
-
end
|
238
|
-
File.readlines(path).*.chop
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
attr_writer :static_tags
|
243
|
-
|
244
|
-
# Helper function for use outside Hobo/Rails
|
245
|
-
#
|
246
|
-
# Pass the template context in locals[:this]
|
247
|
-
#
|
248
|
-
# This function caches. If the mtime of template_path is older
|
249
|
-
# than the last compilation time, the cached version will be
|
250
|
-
# used. If no template_path is given, template_src is used as the
|
251
|
-
# key to the cache.
|
252
|
-
#
|
253
|
-
# If a local variable is not present when the template is
|
254
|
-
# compiled, it will be ignored when the template is used. In
|
255
|
-
# other words, the variable values may change, but the names may
|
256
|
-
# not.
|
257
|
-
#
|
258
|
-
# included_taglibs is only used during template compilation.
|
259
|
-
#
|
260
|
-
# @param [String] template_src the DRYML source
|
261
|
-
# @param [Hash] locals local variables.
|
262
|
-
# @param [String, nil] template_path the filename of the source.
|
263
|
-
# @param [Array] included_taglibs A list of Taglibs to include. { :src =>
|
264
|
-
# "core", :plugin => "dryml" } is automatically
|
265
|
-
# added to this list.
|
266
|
-
# @param [ActionView::Base] view an ActionView instance
|
267
|
-
def render(template_src, locals={}, template_path=nil, included_taglibs=[], view=nil)
|
268
|
-
template_path ||= template_src
|
269
|
-
view ||= ActionView::Base.new(ActionController::Base.view_paths, {})
|
270
|
-
this = locals.delete(:this) || nil
|
271
|
-
|
272
|
-
renderer_class = Dryml::Template.build_cache[template_path]._?.environment ||
|
273
|
-
Dryml.make_renderer_class(template_src, template_path, locals.keys)
|
274
|
-
renderer_class.new(template_path, view).render_page(this, locals)
|
275
|
-
end
|
276
|
-
|
277
276
|
end
|
278
277
|
|
279
278
|
require 'dryml/railtie' if Object.const_defined?(:Rails)
|
data/test/dryml.rdoctest
CHANGED
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: -1637175964
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.3.0.
|
10
|
+
- pre13
|
11
|
+
version: 1.3.0.pre13
|
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-10-
|
19
|
+
date: 2010-10-20 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: -1637175964
|
47
47
|
segments:
|
48
48
|
- 1
|
49
49
|
- 3
|
50
50
|
- 0
|
51
|
-
-
|
52
|
-
version: 1.3.0.
|
51
|
+
- pre13
|
52
|
+
version: 1.3.0.pre13
|
53
53
|
type: :runtime
|
54
54
|
version_requirements: *id002
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- lib/dryml/parser/tree_parser.rb
|
100
100
|
- lib/dryml/part_context.rb
|
101
101
|
- lib/dryml/railtie.rb
|
102
|
-
- lib/dryml/railtie/page_tag_handler.rb
|
103
102
|
- lib/dryml/railtie/page_tag_resolver.rb
|
104
103
|
- lib/dryml/railtie/template_handler.rb
|
105
104
|
- lib/dryml/scoped_variables.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Dryml
|
2
|
-
class Railtie
|
3
|
-
class PageTagHandler < ActionView::Template::Handler
|
4
|
-
|
5
|
-
self.default_format = Mime::HTML
|
6
|
-
|
7
|
-
def self.call(template)
|
8
|
-
"ActionView::Template::Text.new(%q(#{template.source}), Mime::HTML).render"
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|