Class: Pupu::DSL
- Inherits:
-
Object
- Object
- Pupu::DSL
- Defined in:
- lib/pupu/dsl.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #dependencies(*pupus) ⇒ Object
- #dependency(pupu, params = Hash.new) ⇒ Object
- #evaluate ⇒ Object
- #files ⇒ Object
- #get_dependencies ⇒ Object
-
#initialize(pupu, page = Page.new) ⇒ DSL
constructor
A new instance of DSL.
- #javascript(basename, params = Hash.new) ⇒ Object
- #javascripts(*names) ⇒ Object
-
#parameter(name, params = Hash.new, &block) ⇒ Object
parameter :more do |boolean| javascript “mootools-1.2-more” if boolean end.
- #stylesheet(basename, params = Hash.new) ⇒ Object
- #stylesheets(*names) ⇒ Object
Constructor Details
#initialize(pupu, page = Page.new) ⇒ DSL
Returns a new instance of DSL.
21 22 23 24 25 26 27 28 29 |
# File 'lib/pupu/dsl.rb', line 21 def initialize(pupu, page = Page.new) @pupu = pupu @page = page @output = Array.new @files = files @dependencies = Array.new # puts "DSL: #{page.inspect}" @path = pupu.file("config.rb") end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
15 16 17 |
# File 'lib/pupu/dsl.rb', line 15 def output @output end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/pupu/dsl.rb', line 15 def path @path end |
Instance Method Details
#dependencies(*pupus) ⇒ Object
49 50 51 52 53 |
# File 'lib/pupu/dsl.rb', line 49 def dependencies(*pupus) pupus.each do |pupu| self.dependency(pupu) end end |
#dependency(pupu, params = Hash.new) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/pupu/dsl.rb', line 42 def dependency(pupu, params = Hash.new) struct = OpenStruct.new struct.name = pupu struct.params = params @dependencies.push(struct) end |
#evaluate ⇒ Object
31 32 33 34 35 36 |
# File 'lib/pupu/dsl.rb', line 31 def evaluate content = File.read(self.path.to_s) self.instance_eval(content) rescue Exception => exception abort "Exception during parsing #{self.path} in #{pupu.inspect}:\n#{exception.inspect}\n#{exception.backtrace.join("\n")}" end |
#files ⇒ Object
17 18 19 |
# File 'lib/pupu/dsl.rb', line 17 def files @page.files end |
#get_dependencies ⇒ Object
55 56 57 |
# File 'lib/pupu/dsl.rb', line 55 def get_dependencies @dependencies end |
#javascript(basename, params = Hash.new) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pupu/dsl.rb', line 59 def javascript(basename, params = Hash.new) path = @pupu.javascript(basename).url tag = "<script src='#{path}' type='text/javascript'></script>" if params[:if] tag = "<!--[if #{params[:if]}]>" + tag + "<![endif]-->" end unless files.include?(path) files.push(path) @output.push(tag) end end |
#javascripts(*names) ⇒ Object
86 87 88 89 90 |
# File 'lib/pupu/dsl.rb', line 86 def javascripts(*names) names.each do |name| self.javascript(name) end end |
#parameter(name, params = Hash.new, &block) ⇒ Object
parameter :more do |boolean|
javascript "mootools-1.2-more" if boolean
end
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pupu/dsl.rb', line 105 def parameter(name, params = Hash.new, &block) # pupu :autocompleter, type: "request" # @pupu.params: { type: "request" } # pupu :mootools, more: true # @pupu.params: { more: true } if @pupu.params.key?(name) block.call(@pupu.params[name]) end end |
#stylesheet(basename, params = Hash.new) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pupu/dsl.rb', line 71 def stylesheet(basename, params = Hash.new) path = @pupu.stylesheet(basename).url condition = params.delete(:if) default = {media: 'screen', rel: 'stylesheet', type: 'text/css'} params = default.merge(params) tag = "<link href='#{path}' #{params.to_html_attrs} />" if condition tag = "<!--[if #{condition}]>" + tag + "<![endif]-->" end unless files.include?(path) files.push(path) @output.push(tag) end end |
#stylesheets(*names) ⇒ Object
92 93 94 95 96 |
# File 'lib/pupu/dsl.rb', line 92 def stylesheets(*names) names.each do |name| self.stylesheet(name) end end |