Browse files

Remove comments.

  • Loading branch information...
1 parent bdb5edc commit e0e7a14d4ec3399bb1e4e8533e8bee9c9b62847b @jcoglan committed Apr 7, 2012
Showing with 2 additions and 71 deletions.
  1. +0 −10 lib/jake.rb
  2. +2 −25 lib/jake/build.rb
  3. +0 −20 lib/jake/buildable.rb
  4. +0 −7 lib/jake/bundle.rb
  5. +0 −2 lib/jake/helper.rb
  6. +0 −7 lib/jake/package.rb
View
10 lib/jake.rb
@@ -23,26 +23,20 @@ module Jake
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 = {})
build = Build.new(path, options)
build.run!
end
- # Removes all registered build event hooks.
def self.clear_hooks!
Build.delete_observers
end
- # Returns a path made by joining the given pieces and removing unnecessary
- # /. sections using expand_path.
def self.path(*parts)
parts = parts.compact.map { |p| p.to_s }
File.expand_path(File.join(*parts))
end
- # Returns the contents of the given path, which may be missing a .js extension.
def self.read(path)
path = File.expand_path(path)
[path, "#{path}#{EXTENSION}"].each do |file|
@@ -51,7 +45,6 @@ def self.read(path)
return nil
end
- # Returns a copy of the given hash with the keys cast to symbols.
def self.symbolize_hash(hash, deep = true)
hash.inject({}) do |output, (key, value)|
value = Jake.symbolize_hash(value) if deep and value.is_a?(Hash)
@@ -60,21 +53,18 @@ def self.symbolize_hash(hash, deep = true)
end
end
- # Returns either an Erubis or ERB instance, depending on what's available.
def self.erb(template)
defined?(Erubis) ? Erubis::Eruby.new(template) : ERB.new(template)
end
end
-# Adds a helper method that can be called from ERB.
def jake_helper(name, &block)
Jake::Helper.class_eval do
define_method(name, &block)
end
end
alias :jake :jake_helper
-# Registers an event listener that will fire whenever a build is run.
def jake_hook(type, &block)
Jake::Build.on(type, &block)
end
View
27 lib/jake/build.rb
@@ -1,18 +1,11 @@
module Jake
- # A +Build+ encapsulates a single instance of running <tt>Jake.build!</tt>. It
- # is responsible for running the build and provides access to any configuration
- # data used to set up the build.
class Build
include Eventful
-
- DEFAULT_LAYOUT = 'together'
-
include Enumerable
attr_reader :config_files, :helper
- # Builds are initialized using a directory in which to run the build, and an
- # options hash. Options are passed through to helper methods in the +options+
- # object.
+ DEFAULT_LAYOUT = 'together'
+
def initialize(dir, options = {})
@dir = File.expand_path(dir)
@helper = Helper.new(options)
@@ -43,35 +36,29 @@ def initialize(dir, options = {})
end
end
- # Yields to the block for each build in the group.
def each(&block)
@builds.each(&block)
end
- # Forces the build to generate new files even if target files appear up-to-date.
def force!
@forced = true
end
- # Returns +true+ iff this is a forced build.
def forced?
defined?(@forced)
end
- # Returns a list of names for all packages in the build.
def packages
list = []
@packages.each { |name, pkg| list << name }
@bundles.each { |name, pkg| list << name }
list
end
- # Returns the +Buildable+ with the given name.
def package(name)
@packages[name.to_sym] || @bundles[name.to_sym]
end
- # Runs the build, generating new files in +build_directory+.
def run!
FileUtils.cd(@dir) do
@packages.each { |name, pkg| pkg.write! }
@@ -80,44 +67,34 @@ def run!
end
end
- # Returns the path to the build directory, where generated files appear.
def build_directory
Jake.path(@dir, @config[:build_directory] || '.')
end
alias :build_dir :build_directory
- # Returns the path to the source directory, where source code is read from.
def source_directory
Jake.path(@dir, @config[:source_directory] || '.')
end
alias :source_dir :source_directory
- # Returns the header string used for the build, or an empty string if no
- # header file has been set.
def header
@config[:header] ?
Jake.read(Jake.path(source_directory, @config[:header])) :
""
end
- # Returns the minification settings for Packr for the given build name. Each
- # +Build+ object can build all its packages multiple times with different
- # minification settings in each run.
def packer_settings(build_name)
build = @builds[build_name.to_sym]
return false unless build
build[:packer].nil? ? build : build[:packer]
end
- # Returns +true+ iff filename suffixes based on build name should be added
- # to generated files for the given build name.
def use_suffix?(build_name)
build = @builds[build_name.to_sym]
return true unless build
build[:suffix] != false
end
- # Returns the name of the layout being used, either +together+ or +apart+.
def layout
@config[:layout] || DEFAULT_LAYOUT
end
View
20 lib/jake/buildable.rb
@@ -1,15 +1,8 @@
module Jake
- # A +Buildable+ represents a group of files that may be merged to form a single
- # build file. There are two subtypes of +Buildable+; a +Package+ takes several
- # source files and produces a build file, and a +Bundle+ takes several +Package+
- # build files to produce another build file. This class should be considered
- # abstract as some of its methods must be filled in by subtypes.
class Buildable
attr_reader :name
- # Create a new +Buildable+ using a +Build+ container, a name and a configuration
- # hash, typically a subsection of jake.yml.
def initialize(build, name, config)
@build, @name = build, name
@config = case config
@@ -20,30 +13,24 @@ def initialize(build, name, config)
@code = {}
end
- # Returns the parent +Buildable+ set using the +extends+ option, or +nil+ if
- # there is no parent.
def parent
return nil unless @config[:extends]
@parent ||= @build.package(@config[:extends])
end
- # Returns the source directory for this package.
def directory
dir = @config[:directory]
return parent.directory if parent && !dir
Jake.path(@build.source_directory, @config[:directory])
end
- # Returns the path to the output file from this package for the given build name.
def build_path(build_name)
suffix = @build.use_suffix?(build_name) ? "-#{ build_name }" : ""
@build.layout == 'together' ?
Jake.path(@build.build_directory, "#{ @name }#{ suffix }.js") :
Jake.path(@build.build_directory, build_name, "#{ @name }.js")
end
- # Returns +true+ if the build file for the given build name is out of date and
- # should be regenerated.
def build_needed?(name)
return true if @build.forced?
path = build_path(name)
@@ -54,7 +41,6 @@ def build_needed?(name)
input_files.any? { |path| File.mtime(path) > build_time }
end
- # Returns the header string being used for this package.
def header
content = @config[:header] ?
Jake.read(Jake.path( directory, @config[:header])) :
@@ -65,7 +51,6 @@ def header
header
end
- # Returns the Packr settings to use for this package during the given build.
def packer_settings(build_name)
global = @build.packer_settings(build_name)
local = @config[:packer]
@@ -74,15 +59,10 @@ def packer_settings(build_name)
{}.merge(global || {}).merge(local || {})
end
- # Returns a hash containing any metadata attached to the package in the config.
def meta
@config[:meta] || {}
end
- # Generates all the build files for this package by looping over all the
- # required builds and compressing the source code using each set of minification
- # options. Files are only generated if they are out of date or the build has
- # been forced.
def write!
@build.each do |name, settings|
path = build_path(name)
View
7 lib/jake/bundle.rb
@@ -1,22 +1,15 @@
module Jake
class Bundle < Buildable
- # Returns a list of paths to all the files used to build this package.
def files
base = parent ? parent.files : []
base + @config[:files].map { |pkg| @build.package(pkg).files }.flatten
end
- # Returns the full uncompressed source code of this package, before
- # ERB processing. ERB output will be build-dependent; this method
- # simply builds the raw template for further processing by other
- # methods.
def source
@source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n")
end
- # Returns the result of building the source template and minifying
- # the output using the given named set of Packr settings.
def code(build_name)
return @code[build_name] if @code[build_name]
View
2 lib/jake/helper.rb
@@ -1,6 +1,4 @@
module Jake
- # The +Helper+ class stores helper methods that can be called from ERB
- # when generating source code. Use +jake_helper+ to define new helpers.
class Helper
attr_accessor :build
attr_reader :options
View
7 lib/jake/package.rb
@@ -1,7 +1,6 @@
module Jake
class Package < Buildable
- # Returns a list of paths to all the files used to build this package.
def files
base = parent ? parent.files : []
base + @config[:files].map do |path|
@@ -10,16 +9,10 @@ def files
end
end
- # Returns the full uncompressed source code of this package, before
- # ERB processing. ERB output will be build-dependent; this method
- # simply builds the raw template for further processing by other
- # methods.
def source
@source ||= files.map { |path| Jake.read(path) }.join("\n")
end
- # Returns the result of building the source template and minifying
- # the output using the given named set of Packr settings.
def code(build_name, with_header = true)
if cached = @code[build_name]
return with_header ? cached : cached.code

0 comments on commit e0e7a14

Please sign in to comment.