Class: Cup::Builder
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #build(*params) ⇒ Object
- #build!(*params) ⇒ Object
- #concatenate(*params) ⇒ Object
- #concatenate!(options = {}) ⇒ Object
-
#initialize(directory) ⇒ Builder
constructor
A new instance of Builder.
- #minify(*params) ⇒ Object
- #minify!(options = {}) ⇒ Object
Constructor Details
#initialize(directory) ⇒ Builder
Returns a new instance of Builder.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cup/builder.rb', line 10 def initialize directory @directory = directory @build_directory = @directory.path + 'build' if File.exists? @build_directory if File.file? @build_directory raise "Cannot build, build directory is a file" end else Dir.mkdir @build_directory end end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
8 9 10 |
# File 'lib/cup/builder.rb', line 8 def directory @directory end |
Instance Method Details
#build(*params) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cup/builder.rb', line 24 def build *params cupfile.before_build.call concatenated = concatenate *params minified = minify *params cupfile.after_build.call { :concatenated => concatenated, :minified => minified } end |
#build!(*params) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cup/builder.rb', line 39 def build! *params cupfile.before_build.call concatenated = concatenate! *params minified = minify! *params cupfile.after_build.call { :concatenated => concatenated, :minified => minified } end |
#concatenate(*params) ⇒ Object
50 51 52 53 54 |
# File 'lib/cup/builder.rb', line 50 def concatenate *params {:status => :ok, :output => (concatenate! *params)} rescue Exception => e {:status => :failed, :exception => e} end |
#concatenate!(options = {}) ⇒ Object
62 63 64 65 66 |
# File 'lib/cup/builder.rb', line 62 def concatenate!( = {}) process(, :concatenated) do |input_file| File.read(input_file) end end |
#minify(*params) ⇒ Object
56 57 58 59 60 |
# File 'lib/cup/builder.rb', line 56 def minify *params {:status => :ok, :output => (minify! *params)} rescue Exception => e {:status => :failed, :exception => e} end |
#minify!(options = {}) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/cup/builder.rb', line 68 def minify!( = {}) process(, :minified) do |input_file| result = `uglifyjs "#{input_file}"` fail "FAILED: uglifyjs '#{input_file}'" unless $?.exitstatus == 0 result end end |