9
9
require 'pp'
10
10
11
11
module UI
12
- module Builder
13
-
12
+ module Template
14
13
# This module allows to build user interfaces
15
14
# using slim templates (http://www.slim-lang.org)
16
15
#
@@ -160,7 +159,7 @@ def parse_attributes attrs
160
159
161
160
def on_slim_tag ( name , attrs , body )
162
161
attrs_str = parse_attributes attrs
163
- if LEAF_ELEMENTS . include? ( name . to_sym )
162
+ if Builder :: LEAF_ELEMENTS . include? ( name . to_sym )
164
163
attrs_str . prepend ", " unless attrs_str . empty?
165
164
body = compile ( body )
166
165
if body . empty?
@@ -171,7 +170,7 @@ def on_slim_tag(name, attrs, body)
171
170
body ,
172
171
[ :dynamic , attrs_str + "\n " ]
173
172
]
174
- elsif ( CONTAINER_ELEMENTS +TOPLEVEL_ELEMENTS ) . include? ( name . to_sym )
173
+ elsif ( Builder :: CONTAINER_ELEMENTS +Builder :: TOPLEVEL_ELEMENTS ) . include? ( name . to_sym )
175
174
attrs_str = "(" +attrs_str +")" unless attrs_str . empty?
176
175
177
176
[ :multi ,
@@ -200,18 +199,25 @@ class Engine < Temple::Engine
200
199
end
201
200
202
201
end
203
- end
204
- end
205
202
206
- module UI
203
+ # Builds a widget/dialog using a slim template
204
+ # mandatory part of options is either :file or :text key that
205
+ # specify template
206
+ #
207
+ # {include:file:examples/slim_template.rb}
208
+ def render ( options = { } )
209
+ raise "specify template to render by file: or text: key" if !options [ :file ] && !options [ :text ]
210
+ io = options . delete ( :text ) || File . read ( options . delete ( :file ) )
211
+
212
+ options [ :context ] ||= self
213
+
214
+ code = UI ::Template ::Slim ::Engine . new ( options ) . call ( io )
215
+ File . write ( "/tmp/ui.log" , code )
216
+ puts options . inspect
217
+ options [ :context ] . extend UI ::Builder
218
+ options [ :context ] . instance_eval code
219
+ end
207
220
208
- # Builds a widget/dialog using a slim template
209
- #
210
- # {include:file:examples/slim_template.rb}
211
- def self . slim ( io , context , options = { } )
212
- code = UI ::Builder ::Slim ::Engine . new ( options ) . call ( io )
213
- File . write ( "/tmp/ui.log" , code )
214
- context . extend UI ::Builder
215
- context . instance_eval code
216
221
end
217
222
end
223
+
0 commit comments