amrita2 1.9.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +112 -0
- data/init.rb +6 -0
- data/lib/amrita2/gettext.rb +116 -0
- data/lib/amrita2/macro.rb +153 -0
- data/lib/amrita2/rails_bridge.rb +172 -26
- data/lib/amrita2/template.rb +2634 -234
- data/lib/amrita2/testsupport.rb +171 -0
- data/lib/amrita2/version.rb +3 -3
- data/lib/amrita2.rb +1 -0
- data/sample/depot/app/controllers/admin_controller.rb +59 -0
- data/sample/depot/app/controllers/application.rb +20 -0
- data/sample/depot/app/controllers/info_controller.rb +19 -0
- data/sample/depot/app/controllers/login_controller.rb +85 -0
- data/sample/depot/app/controllers/store_controller.rb +68 -0
- data/sample/depot/app/helpers/admin_helper.rb +7 -0
- data/sample/depot/app/helpers/application_helper.rb +10 -0
- data/sample/depot/app/helpers/ar_form.rb +169 -0
- data/sample/depot/app/helpers/form_tag.rb +24 -0
- data/sample/depot/app/helpers/info_helper.rb +7 -0
- data/sample/depot/app/helpers/standard_form.rb +73 -0
- data/sample/depot/app/helpers/store_helper.rb +14 -0
- data/sample/depot/app/models/cart.rb +36 -0
- data/sample/depot/app/models/cart_item.rb +26 -0
- data/sample/depot/app/models/line_item.rb +34 -0
- data/sample/depot/app/models/order.rb +57 -0
- data/sample/depot/app/models/product.rb +41 -0
- data/sample/depot/app/models/user.rb +83 -0
- data/sample/depot/config/boot.rb +49 -0
- data/sample/depot/config/environment.rb +83 -0
- data/sample/depot/config/environments/development.rb +24 -0
- data/sample/depot/config/environments/production.rb +24 -0
- data/sample/depot/config/environments/test.rb +24 -0
- data/sample/depot/config/routes.rb +10 -0
- data/sample/depot/db/migrate/001_create_products.rb +18 -0
- data/sample/depot/db/migrate/002_add_price.rb +14 -0
- data/sample/depot/db/migrate/003_add_test_data.rb +68 -0
- data/sample/depot/db/migrate/004_add_sessions.rb +20 -0
- data/sample/depot/db/migrate/005_create_orders.rb +21 -0
- data/sample/depot/db/migrate/006_create_line_items.rb +27 -0
- data/sample/depot/db/migrate/007_create_users.rb +18 -0
- data/sample/depot/db/schema.rb +45 -0
- data/sample/depot/public/dispatch.rb +15 -0
- data/sample/depot/test/functional/admin_controller_test.rb +54 -0
- data/sample/depot/test/functional/info_controller_test.rb +23 -0
- data/sample/depot/test/functional/login_controller_test.rb +74 -0
- data/sample/depot/test/functional/store_controller_test.rb +57 -0
- data/sample/depot/test/integration/dsl_user_stories_test.rb +126 -0
- data/sample/depot/test/integration/user_stories_test.rb +70 -0
- data/sample/depot/test/performance/order_speed_test.rb +58 -0
- data/sample/depot/test/test_helper.rb +16 -0
- data/sample/depot/test/unit/cart_test.rb +39 -0
- data/sample/depot/test/unit/cart_test1.rb +31 -0
- data/sample/depot/test/unit/line_item_test.rb +15 -0
- data/sample/depot/test/unit/order_test.rb +15 -0
- data/sample/depot/test/unit/product_test.rb +98 -0
- data/sample/depot/vendor/plugins/amrita2/init.rb +6 -0
- data/sample/hello/hello.rb +22 -0
- data/sample/login_engine/app/controllers/application.rb +16 -0
- data/sample/login_engine/app/controllers/user_controller.rb +265 -0
- data/sample/login_engine/app/helpers/application_helper.rb +3 -0
- data/sample/login_engine/app/helpers/form_tag.rb +16 -0
- data/sample/login_engine/app/helpers/two_columns.rb +24 -0
- data/sample/login_engine/app/helpers/two_columns_form.rb +47 -0
- data/sample/login_engine/app/helpers/user_helper.rb +88 -0
- data/sample/login_engine/app/models/user.rb +7 -0
- data/sample/login_engine/app/models/user_notify.rb +75 -0
- data/sample/login_engine/config/boot.rb +45 -0
- data/sample/login_engine/config/environment.rb +140 -0
- data/sample/login_engine/config/environments/development.rb +21 -0
- data/sample/login_engine/config/environments/production.rb +18 -0
- data/sample/login_engine/config/environments/test.rb +19 -0
- data/sample/login_engine/config/routes.rb +23 -0
- data/sample/login_engine/db/migrate/001_create_users.rb +25 -0
- data/sample/login_engine/db/schema.rb +25 -0
- data/sample/login_engine/lib/config.rb +113 -0
- data/sample/login_engine/lib/hpricot_test_extension.rb +80 -0
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +113 -0
- data/sample/login_engine/lib/login_engine/authenticated_user.rb +155 -0
- data/sample/login_engine/lib/login_engine.rb +62 -0
- data/sample/login_engine/public/dispatch.rb +10 -0
- data/sample/login_engine/test/functional/amrita2_test.rb +267 -0
- data/sample/login_engine/test/functional/user_controller_test.rb +544 -0
- data/sample/login_engine/test/mocks/mail.rb +14 -0
- data/sample/login_engine/test/mocks/time.rb +19 -0
- data/sample/login_engine/test/test_helper.rb +31 -0
- data/sample/login_engine/test/unit/user_test.rb +116 -0
- data/sample/login_engine/vendor/plugins/amrita2/init.rb +6 -0
- data/specs/attribute.rb +201 -0
- data/specs/datatypes.rb +231 -0
- data/specs/dictionary.rb +68 -0
- data/specs/erb_cdata.rb +187 -0
- data/specs/filters.rb +513 -0
- data/specs/gettext/erb_gettext.rb +42 -0
- data/specs/gettext/gettext_util.rb +65 -0
- data/specs/gettext/static_text.rb +103 -0
- data/specs/impl/code_generator.rb +87 -0
- data/specs/impl/dynamic_element.rb +92 -0
- data/specs/impl/hash_delegator.rb +57 -0
- data/specs/impl/parse_opt.rb +34 -0
- data/specs/impl/preprocess.rb +823 -0
- data/specs/impl/testsupport.rb +89 -0
- data/specs/inlineruby.rb +429 -0
- data/specs/intro.rb +654 -0
- data/specs/loop.rb +203 -0
- data/specs/macro.rb +532 -0
- data/specs/sample.rb +34 -0
- data/specs/sanitize.rb +110 -0
- data/specs/template.rb +189 -0
- data/specs/trace.rb +97 -0
- metadata +138 -19
- data/lib/amrita2/core.rb +0 -1897
- data/lib/amrita2/rd.rb +0 -314
data/README
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
= Amrita2 - a xml/xhtml template library for Ruby
|
2
|
+
|
3
|
+
== Summary
|
4
|
+
|
5
|
+
Amrita2 is a a xml/xhtml template library for Ruby.
|
6
|
+
It makes html documents from a template and a model data.
|
7
|
+
|
8
|
+
=== Key feature
|
9
|
+
|
10
|
+
specify "XML template" do
|
11
|
+
t = Amrita2::Template.new <<-END
|
12
|
+
<html>
|
13
|
+
<head>
|
14
|
+
<title am:src="page_title" />
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<h1 am:src="header_title" />
|
18
|
+
<p class="text" am:src="text">
|
19
|
+
<span am:src="template" /> is a html template library for <span am:src="lang" />
|
20
|
+
</p>
|
21
|
+
</body>
|
22
|
+
</html>
|
23
|
+
END
|
24
|
+
|
25
|
+
data = {
|
26
|
+
:page_title=>'Amrita2',
|
27
|
+
:header_title=>'Hello, Amrita2',
|
28
|
+
:text=>{
|
29
|
+
:template => 'Amrita2',
|
30
|
+
:lang => 'Ruby'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
expected = <<-END
|
34
|
+
<html>
|
35
|
+
<head>
|
36
|
+
<title>Amrita2</title>
|
37
|
+
</head>
|
38
|
+
<body>
|
39
|
+
<h1>Hello, Amrita2</h1>
|
40
|
+
<p class="text">Amrita2 is a html template library for Ruby</p>
|
41
|
+
</body>
|
42
|
+
</html>
|
43
|
+
END
|
44
|
+
#
|
45
|
+
t.render_with(data).should_be_samexml_as(expected)
|
46
|
+
|
47
|
+
t2 = Amrita2::Template.new <<-END
|
48
|
+
<<html<
|
49
|
+
<<head<
|
50
|
+
<<title:page_title>>
|
51
|
+
<<body<
|
52
|
+
<<h1:header_title>>
|
53
|
+
<<p class="text":text<
|
54
|
+
<<:template>> is a html template library for <<:lang>>
|
55
|
+
END
|
56
|
+
#
|
57
|
+
t2.render_with(data).should_be_samexml_as(expected)
|
58
|
+
end
|
59
|
+
|
60
|
+
* The template for amrita2 is a pure html/xhtml document without no
|
61
|
+
special tag like <?...?> or <% .. %>
|
62
|
+
|
63
|
+
* The template can be written by designers using almost any xhtml/xml
|
64
|
+
Editor.
|
65
|
+
|
66
|
+
* Need no change on Ruby code to change the view of _dynamic_ part
|
67
|
+
(not only static part) of the template
|
68
|
+
|
69
|
+
* The model data may be standard Ruby data, Hash, Array, String... or
|
70
|
+
an instance of a classes you made.
|
71
|
+
|
72
|
+
* The output is controlled by _data_ not by logic. So It's easy to
|
73
|
+
write, test, debug code. (Good for eXtreamPrograming)
|
74
|
+
|
75
|
+
Amrita2 mixes a template and model data up to a html document naturally
|
76
|
+
matching the +id+ attribute of XML element to model data.
|
77
|
+
|
78
|
+
=== Current version and roadmap
|
79
|
+
|
80
|
+
Current version is 2.0.0 .
|
81
|
+
|
82
|
+
=== Setup
|
83
|
+
|
84
|
+
# gem install amrita2
|
85
|
+
|
86
|
+
== document
|
87
|
+
|
88
|
+
Start spec/intro.rb or Amrita2 Wiki (http://retro.brain-tokyo.net/projects/amrita2/wiki/Amrita2)
|
89
|
+
|
90
|
+
== support/developement
|
91
|
+
|
92
|
+
* http://retro.brain-tokyo.net/projects/amrita2/blog
|
93
|
+
|
94
|
+
== Download
|
95
|
+
|
96
|
+
* http://rubyforge.org/projects/amrita2
|
97
|
+
|
98
|
+
== License
|
99
|
+
|
100
|
+
Amrita2 is Copyright (c) 2008 Taku Nakajima
|
101
|
+
<tnakajima@brain-tokyo.jp>. It is free software, and may be
|
102
|
+
redistributed under the terms specified in the README file of the Ruby
|
103
|
+
distribution.
|
104
|
+
|
105
|
+
Sample source code under sample/depot is Amrita2 version of
|
106
|
+
Depot Application of "Agile Web Development with Rails".
|
107
|
+
|
108
|
+
http://www.pragprog.com/titles/rails2/source_code
|
109
|
+
|
110
|
+
Sample source code under sample/login_engine is Amrita2 version of LoginEngine.
|
111
|
+
|
112
|
+
http://rails-engines.org/news/2007/01/23/farewell-login_engine-/
|
data/init.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'amrita2/template'
|
2
|
+
require 'gettext/rgettext'
|
3
|
+
|
4
|
+
module Amrita2
|
5
|
+
module Core
|
6
|
+
class CompoundElement # :nodoc: all
|
7
|
+
def get_erb_source
|
8
|
+
@children.collect do |c|
|
9
|
+
c.get_erb_source
|
10
|
+
end.join("\n")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ErbNode # :nodoc: all
|
15
|
+
def get_erb_source
|
16
|
+
return @node.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class DynamicElement # :nodoc: all
|
21
|
+
def get_erb_source
|
22
|
+
@children.collect do |c|
|
23
|
+
c.get_erb_source
|
24
|
+
end.join("\n")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class RootElement < DynamicElement # :nodoc: all
|
30
|
+
attr_accessor :text_domain
|
31
|
+
compile_old = self.instance_method(:compile)
|
32
|
+
|
33
|
+
define_method(:compile) do |cg|
|
34
|
+
cg.code("bindtextdomain(#{@text_domain.inspect})")
|
35
|
+
compile_old.bind(self).call(cg)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class Template
|
41
|
+
attr_accessor :text_domain
|
42
|
+
def compile_for_gettext
|
43
|
+
setup
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_erb_source_for_gettext
|
47
|
+
setup
|
48
|
+
@root.get_erb_source
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module GetTextBridge # :nodoc: all
|
54
|
+
class TextNodeForGetText < Core::StaticNode
|
55
|
+
def dynamic?
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def render_me(cg)
|
60
|
+
#text = @node.to_s.strip
|
61
|
+
|
62
|
+
# to keep
|
63
|
+
text = ""
|
64
|
+
@node.output(text, :preserve=>true)
|
65
|
+
text.strip!
|
66
|
+
cg.put_string_expression("_(#{text.inspect}) % $_") if text != ""
|
67
|
+
end
|
68
|
+
def get_erb_source
|
69
|
+
return ""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module Filters
|
75
|
+
class GetTextFilter < Filters::Base
|
76
|
+
def parse_node(de, node)
|
77
|
+
case node
|
78
|
+
when Hpricot::CData
|
79
|
+
super
|
80
|
+
when Hpricot::Text
|
81
|
+
Amrita2::GetTextBridge::TextNodeForGetText.new(de, node)
|
82
|
+
else
|
83
|
+
super
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
module GetTextParser # :nodoc: all
|
90
|
+
include Amrita2
|
91
|
+
include Amrita2::GetTextBridge
|
92
|
+
|
93
|
+
module_function
|
94
|
+
def target?(file)
|
95
|
+
File.extname(file) == '.a2html'
|
96
|
+
end
|
97
|
+
|
98
|
+
def parse(file, ary)
|
99
|
+
t = Template.new(File::open(file).read) do |e, src, filters|
|
100
|
+
filters << Filters::GetTextFilter.new
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
src = t.compile_for_gettext
|
105
|
+
RubyParser.parse_lines(file, [src], ary)
|
106
|
+
src = t.get_erb_source_for_gettext
|
107
|
+
erb = ERB.new(src).src.split(/$/)
|
108
|
+
RubyParser.parse_lines(file, erb, ary)
|
109
|
+
ary.collect do |msgid, fnameandline|
|
110
|
+
[msgid, fnameandline.gsub(/\d+$/, "-")]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
GetText::RGetText.add_parser(Amrita2::GetTextParser)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'amrita2/template'
|
2
|
+
|
3
|
+
module Amrita2
|
4
|
+
|
5
|
+
class Core::Template
|
6
|
+
def add_macro(m)
|
7
|
+
@macros ||= []
|
8
|
+
@macros << m
|
9
|
+
end
|
10
|
+
alias use_macro add_macro
|
11
|
+
|
12
|
+
compile_old = instance_method(:compile)
|
13
|
+
|
14
|
+
define_method(:compile) do |*args|
|
15
|
+
macros = @macros
|
16
|
+
if macros and macros.size > 0
|
17
|
+
filter_setup do |e, name ,filters|
|
18
|
+
filters << MacroFilter.new(*macros)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
compile_old.bind(self).call(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Macro # :nodoc: all
|
26
|
+
class Base
|
27
|
+
def initialize
|
28
|
+
@mt = Template.new(get_macro_template, :amrita_prefix=>"macro:", :inline_ruby=>true)
|
29
|
+
@option = {}
|
30
|
+
@option = self.class.const_get(:Option) if self.class.const_defined?(:Option)
|
31
|
+
raise "Macro Option is not defined propery in #{self.class} #{@option.inspect}" unless @option.kind_of?(Hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_macro_template
|
35
|
+
self.class.const_get(:TemplateText)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_element_name
|
39
|
+
#self.class.const_get(:ElementName)
|
40
|
+
@option[:tag] || underscore(self.class.name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def process(de, element)
|
44
|
+
preprocess_element(@mt, element)
|
45
|
+
end
|
46
|
+
|
47
|
+
def match_element(element)
|
48
|
+
element.name == get_element_name.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def macro_data(element)
|
52
|
+
element.as_amrita_dictionary(@option)
|
53
|
+
end
|
54
|
+
|
55
|
+
def preprocess_element(mt, element)
|
56
|
+
if @option[:trace]
|
57
|
+
mt.set_trace(@option[:trace])
|
58
|
+
@option[:trace] << (macro_data(element)).inspect
|
59
|
+
end
|
60
|
+
mt.amrita_prefix = "macro:"
|
61
|
+
mt.render_with(macro_data(element))
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
# from activesupport
|
66
|
+
def underscore(camel_cased_word)
|
67
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
68
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
69
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
70
|
+
tr("-", "_").
|
71
|
+
downcase
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module Filters
|
77
|
+
class MacroFilter < Base
|
78
|
+
include Amrita2
|
79
|
+
include Util
|
80
|
+
include OptionSupport
|
81
|
+
attr_reader :macros
|
82
|
+
|
83
|
+
def initialize(*macros)
|
84
|
+
@macros = macros.collect do |m|
|
85
|
+
case m
|
86
|
+
when Class
|
87
|
+
m.new
|
88
|
+
else
|
89
|
+
m
|
90
|
+
end
|
91
|
+
end
|
92
|
+
@element_names = {}
|
93
|
+
@macros.each do |m|
|
94
|
+
@element_names[m.get_element_name.to_s] = true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def check_element(element)
|
99
|
+
return true if @element_names[element.name]
|
100
|
+
element.each_child do |c|
|
101
|
+
next unless c.kind_of?(Hpricot::Elem)
|
102
|
+
return true if @element_names[c.name] or check_element(c)
|
103
|
+
end
|
104
|
+
false
|
105
|
+
end
|
106
|
+
|
107
|
+
def filter_element(de, element)
|
108
|
+
return element unless check_element(element)
|
109
|
+
|
110
|
+
@macros.each do |m|
|
111
|
+
if m.match_element(element)
|
112
|
+
ret = m.process(de, element)
|
113
|
+
ret = Core::PreProcessor.new.process(ret.dup)
|
114
|
+
ret.gsub!('<%%', '<%')
|
115
|
+
ret.gsub!('%%>', '%>')
|
116
|
+
root = Hpricot.make("<_ />").first
|
117
|
+
Hpricot.make(ret, :xml=>true).each do |e|
|
118
|
+
root.insert_after(e, nil)
|
119
|
+
end
|
120
|
+
element = replace_target_src(root)
|
121
|
+
else
|
122
|
+
element.each_child do |c|
|
123
|
+
next unless c.kind_of?(Hpricot::Elem)
|
124
|
+
cc = filter_element(de, c)
|
125
|
+
element.replace_child(c, cc) if c != cc
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
element
|
130
|
+
end
|
131
|
+
|
132
|
+
def replace_target_src(e)
|
133
|
+
%w(src filter v skipif for).each do |k|
|
134
|
+
e.set_attribute("am:#{k}", e.attributes["target_#{k}"]) if e.attributes["target_#{k}"]
|
135
|
+
e.delete_attribute("target_#{k}")
|
136
|
+
end
|
137
|
+
e.each_child do |c|
|
138
|
+
next unless c.kind_of?(Hpricot::Elem)
|
139
|
+
replace_target_src(c)
|
140
|
+
end
|
141
|
+
e
|
142
|
+
end
|
143
|
+
|
144
|
+
def element_render_code(de, cg, element, &block)
|
145
|
+
if (element.name == 'macroroot')
|
146
|
+
yield
|
147
|
+
else
|
148
|
+
super
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/lib/amrita2/rails_bridge.rb
CHANGED
@@ -1,40 +1,186 @@
|
|
1
1
|
require 'amrita2/template'
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module ActionView # :nodoc: all
|
6
|
+
class Base #:nodoc:
|
7
|
+
include Amrita2::Runtime
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ActiveRecord # :nodoc: all
|
12
|
+
class Base
|
13
|
+
include Amrita2::DictionaryData
|
14
|
+
end
|
15
|
+
|
16
|
+
class ConnectionAdapters::Column
|
17
|
+
include Amrita2::DictionaryData
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ActionController # :nodoc: all
|
22
|
+
class Pagination::Paginator
|
23
|
+
include Amrita2::DictionaryData
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
module Amrita2View # :nodoc: all
|
4
29
|
class Base
|
30
|
+
include Amrita2
|
31
|
+
include Amrita2::Filters
|
32
|
+
include Amrita2::Runtime
|
33
|
+
include Amrita2::Util
|
34
|
+
|
35
|
+
CompileTimeBinding = binding
|
5
36
|
@@compiled_amrita2_templates = {}
|
6
37
|
|
38
|
+
@@text_domain = nil
|
39
|
+
cattr_accessor :text_domain
|
40
|
+
|
7
41
|
def initialize( action_view )
|
8
42
|
@action_view = action_view
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def render(template, local_assigns={})
|
46
|
+
Thread::current[:amrita_rails_view] = @action_view
|
47
|
+
if template.kind_of?(String)
|
48
|
+
render_amrita(template, local_assigns)
|
49
|
+
else
|
50
|
+
@action_view.render(template, local_assigns)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def setup_template(template)
|
55
|
+
setup_template_default(template)
|
56
|
+
end
|
24
57
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
58
|
+
def setup_template_default(template)
|
59
|
+
if Amrita2::const_defined?(:GetTextBridge)
|
60
|
+
t = Amrita2::Template.new(template) do |e, src, filters|
|
61
|
+
filters << Amrita2::Filters::GetTextFilter.new
|
62
|
+
end
|
63
|
+
t.text_domain = text_domain
|
64
|
+
bindtextdomain(t.text_domain)
|
65
|
+
#t.set_trace(STDOUT)
|
66
|
+
t.compiletime_binding = CompileTimeBinding
|
67
|
+
t
|
29
68
|
else
|
30
|
-
|
31
|
-
|
69
|
+
t = Amrita2::Template.new(template)
|
70
|
+
t.compiletime_binding = CompileTimeBinding
|
71
|
+
t
|
72
|
+
end
|
73
|
+
end
|
32
74
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
75
|
+
def render_amrita(template, local_assigns)
|
76
|
+
@@compiled_amrita2_templates[template] ||= setup_template(template)
|
77
|
+
tmpl = @@compiled_amrita2_templates[template]
|
78
|
+
b = setup_binding_of_view(local_assigns)
|
79
|
+
tmpl.render_with(b)
|
80
|
+
end
|
81
|
+
|
82
|
+
def setup_binding_of_view(local_assigns)
|
83
|
+
@action_view.instance_eval do
|
84
|
+
evaluate_assigns
|
85
|
+
b = binding
|
86
|
+
local_assigns.each do |k, v|
|
87
|
+
amrita_set_context_value(v)
|
88
|
+
eval "#{k}=amrita_get_context_value",b
|
89
|
+
end
|
90
|
+
b
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
module Helper
|
95
|
+
include ActionView::Helpers::UrlHelper
|
96
|
+
|
97
|
+
def view
|
98
|
+
@view ||= Thread::current[:amrita_rails_view]
|
99
|
+
end
|
100
|
+
|
101
|
+
def eval_in_view(&block)
|
102
|
+
view.instance_eval &block
|
103
|
+
end
|
104
|
+
|
105
|
+
def eval_in_view_without_escape(&block)
|
106
|
+
Amrita2::SanitizedString[eval_in_view(&block)]
|
37
107
|
end
|
38
108
|
end
|
39
109
|
end
|
40
110
|
|
111
|
+
=begin
|
112
|
+
|
113
|
+
class WithObject < Amrita2::Macro::Base
|
114
|
+
TemplateText = <<-'END'
|
115
|
+
<<%<
|
116
|
+
<% Thread::current[:amrita2_form_object] = $_[:name] || $_[:object] %>
|
117
|
+
<<_ :| Attr[:target_src=>:object]<
|
118
|
+
<<:contents>>
|
119
|
+
END
|
120
|
+
|
121
|
+
Option = {
|
122
|
+
:tag => "a:with_object",
|
123
|
+
:use_contents => :contents,
|
124
|
+
}
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
class Input < Amrita2::Macro::Base
|
129
|
+
TemplateText = <<-'END'
|
130
|
+
<<%<
|
131
|
+
<%
|
132
|
+
object = $_.delete(:object) || Thread::current[:amrita2_form_object]
|
133
|
+
input_id = $_.delete(:id)
|
134
|
+
other = $_.collect do |k, v|
|
135
|
+
"#{k}='#{v}'"
|
136
|
+
end
|
137
|
+
%>
|
138
|
+
<input id="<%= object %>_<%= input_id %>" name="<%= object %>[<%= input_id%>]" <%= other %> target_filter="Attr[:value=><%= input_id.intern.inspect %>]"/>
|
139
|
+
END
|
140
|
+
|
141
|
+
Option = {
|
142
|
+
:tag => "a:input"
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
class TextField < Amrita2::Macro::Base
|
147
|
+
TemplateText = <<-'END'
|
148
|
+
<<%<
|
149
|
+
<%
|
150
|
+
object = $_.delete(:object) || Thread::current[:amrita2_form_object]
|
151
|
+
input_id = $_.delete(:id)
|
152
|
+
$_[:size] ||= 30
|
153
|
+
other = $_.collect do |k, v|
|
154
|
+
"#{k}='#{v}'"
|
155
|
+
end
|
156
|
+
%>
|
157
|
+
<input type="text" id="<%= object %>_<%= input_id %>" name="<%= object %>[<%= input_id%>]" <%= other %> target_filter="Attr[:value=><%= input_id.intern.inspect %>]"/>
|
158
|
+
END
|
159
|
+
|
160
|
+
Option = {
|
161
|
+
:tag => "a:text_field",
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
class TextArea < Amrita2::Macro::Base
|
166
|
+
TemplateText = <<-'END'
|
167
|
+
<<%<
|
168
|
+
<%
|
169
|
+
object = $_.delete(:object) || Thread::current[:amrita2_form_object]
|
170
|
+
input_id = $_.delete(:id)
|
171
|
+
$_[:cols] ||= 40
|
172
|
+
$_[:rows] ||= 20
|
173
|
+
other = $_.collect do |k, v|
|
174
|
+
"#{k}='#{v}'"
|
175
|
+
end
|
176
|
+
%>
|
177
|
+
<textarea id="<%= object %>_<%= input_id %>" name="<%= object %>[<%= input_id%>]" <%= other %> target_filter="Attr[:body=><%= input_id.intern.inspect %>]"/>
|
178
|
+
END
|
179
|
+
|
180
|
+
Option = {
|
181
|
+
:tag => "a:textarea",
|
182
|
+
}
|
183
|
+
end
|
184
|
+
=end
|
185
|
+
|
186
|
+
|