Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor to use the new Packr header API.

  • Loading branch information...
commit dd3b812820e123542ad1b72e40c7ce0e2b5770f3 1 parent ffd13df
@jcoglan authored
View
14 lib/jake.rb
@@ -1,8 +1,6 @@
require 'erb'
require 'fileutils'
-require 'observer'
require 'yaml'
-require 'rubygems'
require 'packr'
require 'eventful'
@@ -18,6 +16,13 @@ module Jake
HELPER_FILE = 'Jakefile'
EXTENSION = '.js'
+ dir = File.expand_path('../jake', __FILE__)
+ autoload :Build, dir + '/build'
+ autoload :Buildable, dir + '/buildable'
+ autoload :Bundle, dir + '/bundle'
+ autoload :Helper, dir + '/helper'
+ autoload :Package, dir + '/package'
+
# Runs a build in the given directory. The directory must contain a jake.yml
# file, and may contain a Jakefile. See README for example YAML configurations.
def self.build!(path, options = {})
@@ -59,11 +64,6 @@ def self.symbolize_hash(hash, deep = true)
def self.erb(template)
defined?(Erubis) ? Erubis::Eruby.new(template) : ERB.new(template)
end
-
-end
-
-%w(helper build buildable package bundle).each do |file|
- require File.dirname(__FILE__) + '/jake/' + file
end
# Adds a helper method that can be called from ERB.
View
7 lib/jake/buildable.rb
@@ -57,7 +57,10 @@ def header
content = @config[:header] ?
Jake.read(Jake.path( directory, @config[:header])) :
(parent ? parent.header : @build.header)
- Jake.erb(content).result(@build.helper.scope).strip
+
+ header = Jake.erb(content).result(@build.helper.scope).strip
+ return nil if header == ''
+ header << "\n"
end
# Returns the PackR settings to use for this package during the given build.
@@ -85,7 +88,7 @@ def write!
@build.helper.build = name.to_s
FileUtils.mkdir_p(File.dirname(path))
- File.open(path, 'wb') { |f| f.write( (header + "\n\n" + code(name)).strip ) }
+ File.open(path, 'wb') { |f| f.write(code(name).strip) }
@build.fire(:file_created, self, name, path)
View
14 lib/jake/bundle.rb
@@ -17,9 +17,17 @@ def source
# Returns the result of building the source template and minifying
# the output using the given named set of PackR settings.
- def code(name)
- joiner = (packer_settings(name) == false) ? "\n\n\n" : "\n"
- @code[name] ||= @config[:files].map { |pkg| @build.package(pkg).code(name) }.join(joiner)
+ def code(build_name)
+ return @code[build_name] if @code[build_name]
+
+ joiner = (packer_settings(build_name) == false) ? "\n\n" : ""
+
+ code = @config[:files].map { |pkg| @build.package(pkg).code(build_name, false) }.join(joiner)
+ if head = header
+ code = head + code
+ end
+
+ @code[build_name] = code
end
end
View
27 lib/jake/package.rb
@@ -20,11 +20,28 @@ def source
# Returns the result of building the source template and minifying
# the output using the given named set of PackR settings.
- def code(name)
- return @code[name] if @code[name]
- settings = packer_settings(name)
- output = Jake.erb(source).result(@build.helper.scope)
- @code[name] = settings ? Packr.pack(output, settings) : output
+ def code(build_name, with_header = true)
+ if cached = @code[build_name]
+ return with_header ? cached[:with_header] : cached[:code]
+ end
+
+ code = Jake.erb(source).result(@build.helper.scope)
+ head = header
+
+ if packer = packer_settings(build_name)
+ packer = packer.merge(:header => head)
+ code = Packr.pack(code, packer)
+ else
+ code = head + "\n" + code if head
+ end
+
+ @code[name] = {
+ :with_header => code,
+ :code => head && code[head.size..-1]
+ }
+ with_header ?
+ @code[name][:with_header] :
+ @code[name][:code]
end
end
View
9 test/jake.yml
@@ -1,16 +1,21 @@
---
source_directory: src
build_directory: output
+
builds:
min:
shrink_vars: true
private: true
+ source_map: src
src:
packer: false
suffix: false
+
header: head
+
packages:
basic: basic
+
ext:
extends: basic
packer:
@@ -22,8 +27,10 @@ packages:
- Basic
requires:
- Foo
+
sub/dir/foo:
- foo/foo
+
sub/path/bar:
directory: foo
header: ../head2
@@ -31,8 +38,8 @@ packages:
shrink_vars: false
files:
- bar
+
bundles:
combo/box:
- sub/dir/foo
- ext
-
View
2  test/test_jake.rb
@@ -17,8 +17,10 @@ def setup
def test_build
Jake.clear_hooks!
Jake.build!(DIR)
+
expected = File.join(DIR, 'expected')
actual = File.join(DIR, 'output')
+
Find.find(expected) do |path|
next unless File.file?(path)
actual_path = actual + path.gsub(expected, '')
2  vendor/packr
@@ -1 +1 @@
-Subproject commit 14c39049356d36bd311414b0dd8314ef6ef619a9
+Subproject commit 6004c3838120edf310aaac89909e2ab1c995a593
Please sign in to comment.
Something went wrong with that request. Please try again.