Class: Pupu::DSL
- Inherits:
-
Object
- Object
- Pupu::DSL
- Defined in:
- lib/pupu/dsl.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#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
- #get_dependencies ⇒ Object
-
#initialize(pupu) ⇒ 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) ⇒ DSL
Returns a new instance of DSL.
15 16 17 18 19 20 21 |
# File 'lib/pupu/dsl.rb', line 15 def initialize(pupu) @pupu = pupu @output = Array.new @files = Array.new @dependencies = Array.new @path = pupu.file("config.rb") end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
14 15 16 |
# File 'lib/pupu/dsl.rb', line 14 def files @files end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/pupu/dsl.rb', line 14 def output @output end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/pupu/dsl.rb', line 14 def path @path end |
Instance Method Details
#dependencies(*pupus) ⇒ Object
41 42 43 44 45 |
# File 'lib/pupu/dsl.rb', line 41 def dependencies(*pupus) pupus.each do |pupu| self.dependency(pupu) end end |
#dependency(pupu, params = Hash.new) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/pupu/dsl.rb', line 34 def dependency(pupu, params = Hash.new) struct = OpenStruct.new struct.name = pupu struct.params = params @dependencies.push(struct) end |
#evaluate ⇒ Object
23 24 25 26 27 28 |
# File 'lib/pupu/dsl.rb', line 23 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 |
#get_dependencies ⇒ Object
47 48 49 |
# File 'lib/pupu/dsl.rb', line 47 def get_dependencies @dependencies end |
#javascript(basename, params = Hash.new) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/pupu/dsl.rb', line 51 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 @files.push(path) @output.push(tag) end |
#javascripts(*names) ⇒ Object
74 75 76 77 78 |
# File 'lib/pupu/dsl.rb', line 74 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
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pupu/dsl.rb', line 93 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
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pupu/dsl.rb', line 61 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 @files.push(path) @output.push(tag) end |
#stylesheets(*names) ⇒ Object
80 81 82 83 84 |
# File 'lib/pupu/dsl.rb', line 80 def stylesheets(*names) names.each do |name| self.stylesheet(name) end end |