module Deklarativna
Module
Deklarativna
is a module thought for creating embedded HTML/XML templates fully written in ruby
It can provide its functionallity to any of your ruby existing code just by adding ‘include Deklarativna` inside your classes or modules
Public Class Methods
included(base)
click to toggle source
Private Method
It metaprograms most of the module’s methods
# File lib/deklarativna.rb, line 13 def self.included(base) nesting_renderables = ["html", "head", "body", "header", "footer", "p", "div", "span", "table", "tr", "td", "ul", "ol", "li", "center", "dd", "dl", "dt", "i", "b", "em", "strong", "title", "label", "pre", "script", "style", "a", "form", "textarea", "select", "option", "article", "section", "code", "abbr", "acronym", "address", "bdo", "address", "big", "tt", "small", "blockquote", "button", "caption", "dfn", "cite", "code", "samp", "kbd", "var", "colgroup", "del", "ins", "dir", "fieldset", "legend", "frameset", "iframe", "noframes", "noscript", "object", "optgroup", "q","sub", "sup", "thead", "tfoot", "tbody"] (1..6).each { |e| nesting_renderables.push "h#{e}" } nesting_renderables.each do |tag_name| send :define_method, tag_name do |*args, &block| attributes = args[0] if !args.nil? nesting_renderable_string tag_name, block, attributes end end single_tag_renderables = ["meta", "br", "hr", "link", "input", "img", "base", "col", "frame", "param"] single_tag_renderables.each do |tag_name| send :define_method, tag_name do |*args| attributes = args[0] if !args.nil? single_tag_renderable_string tag_name, attributes end end form_input_renderables = ["text", "password", "checkbox", "radio", "submit"] form_input_renderables.each do |type| send :define_method, type do |*args| attributes = args[0] if !args.nil? attributes ||= {} attributes["type"] = type input attributes end end end
Public Instance Methods
comment(&comment_block)
click to toggle source
Public Method
Helper for adding your comments to the template
# File lib/deklarativna.rb, line 81 def comment &comment_block comment_renderable_string comment_block end
comment_renderable_string(comment_block)
click to toggle source
Private Method
Factory Method for creating comment renderables
# File lib/deklarativna_core.rb, line 94 def comment_renderable_string comment_block renderable_string CommentRenderable, comment_block end
css(attributes={})
click to toggle source
Public Method
Helper for adding your css to the template
# File lib/deklarativna.rb, line 74 def css attributes={}, &style_text_block attributes["type"] = "text/css" style attributes, &style_text_block end
javascript(attributes={})
click to toggle source
Public Method
Helper for adding your javascript to the template
# File lib/deklarativna.rb, line 67 def javascript attributes={}, &script_text_block attributes["type"] = "text/javascript" script attributes, &script_text_block end
nesting_renderable_string(tag_name, block, attributes={})
click to toggle source
Private Method
Factory Method for creating nesting renderables
# File lib/deklarativna_core.rb, line 88 def nesting_renderable_string tag_name, block, attributes={} renderable_string NestingRenderable, block, attributes, tag_name end
renderable_string(renderable_class, block, attributes={})
click to toggle source
Private Method
This is a helper for factory methods
# File lib/deklarativna_core.rb, line 70 def renderable_string renderable_class, block, attributes={}, tag_name="" (renderable_class.new { |instance| instance.tag_name = tag_name instance.attributes = attributes if instance.respond_to? :content instance.content = block end }).to_s end
single_tag_renderable_string(tag_name, attributes={})
click to toggle source
Private Method
Factory Method for creating single tag renderables
# File lib/deklarativna_core.rb, line 82 def single_tag_renderable_string tag_name, attributes={} renderable_string SingleTagRenderable, nil, attributes, tag_name end
xml_double_tag(tag_name, attributes={})
click to toggle source
Public Method
Helper for adding XML tags with the format ‘<tagname></tagname>’
# File lib/deklarativna.rb, line 93 def xml_double_tag tag_name, attributes={}, &html_block nesting_renderable_string tag_name.downcase, html_block, attributes end
xml_single_tag(tag_name, attributes={})
click to toggle source
Public Method
Helper for adding XML tags with the format ‘<tagname />’
# File lib/deklarativna.rb, line 87 def xml_single_tag tag_name, attributes={} single_tag_renderable_string tag_name.downcase, attributes end