Class: Nitro::Element
- Inherits:
-
Object
- Object
- Nitro::Element
- Includes:
- ElementMixin
- Defined in:
- lib/nitro/element.rb,
lib/nitro/element/javascript.rb
Overview
A programmatically generated element.
Usage
in the code
class Page < Nitro::Element
def render
%{
<div id="@id">#{content}</div>
}
end
end
in your template
<Page>hello</Page>
> <div id=“page”>hello</div>
the id is automatically fille with the class name using class.method_name eg. MyModule::MyPage => my_module__my_page
you can override the id to use the element multiple times on the page
Sub Elements
Elements can be imbricated. To render the the child element in the parent’s template, use #:element_id
Design
An underscore is used for the standard attibutes to avoid name clashes. – TODO:
-
separate ‘view’ template files.
++
Defined Under Namespace
Classes: Javascript
Instance Attribute Summary
Attributes included from ElementMixin
#_children, #_parent, #_text, #_view, #id
Class Method Summary collapse
-
.compile_template_elements ⇒ Object
Compile the element templates into element classes.
Methods included from ElementMixin
#add_child, #close, #content, #initialize, #open, #render, #render_children
Class Method Details
.compile_template_elements ⇒ Object
Compile the element templates into element classes. Typically called at startup.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/nitro/element.rb', line 193 def compile_template_elements if File.exist? Element.template_root Dir.recurse(Element.template_root) do |filename| if filename =~ /\.#{Glue::Template.extension}$/ name = File.basename(filename).split('.').first.camelize Nitro::Element.module_eval %{ class #{name} < Nitro::Element def render <<-END_OF_TEMPLATE #{File.read(filename)} END_OF_TEMPLATE end end } end end end end |