jake 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,8 @@
1
1
  module Jake
2
- # A +Buildable+ represents a group of files that may be merged to form a single
3
- # build file. There are two subtypes of +Buildable+; a +Package+ takes several
4
- # source files and produces a build file, and a +Bundle+ takes several +Package+
5
- # build files to produce another build file. This class should be considered
6
- # abstract as some of its methods must be filled in by subtypes.
7
2
  class Buildable
8
3
 
9
4
  attr_reader :name
10
5
 
11
- # Create a new +Buildable+ using a +Build+ container, a name and a configuration
12
- # hash, typically a subsection of jake.yml.
13
6
  def initialize(build, name, config)
14
7
  @build, @name = build, name
15
8
  @config = case config
@@ -20,21 +13,17 @@ module Jake
20
13
  @code = {}
21
14
  end
22
15
 
23
- # Returns the parent +Buildable+ set using the +extends+ option, or +nil+ if
24
- # there is no parent.
25
16
  def parent
26
17
  return nil unless @config[:extends]
27
18
  @parent ||= @build.package(@config[:extends])
28
19
  end
29
20
 
30
- # Returns the source directory for this package.
31
21
  def directory
32
22
  dir = @config[:directory]
33
23
  return parent.directory if parent && !dir
34
24
  Jake.path(@build.source_directory, @config[:directory])
35
25
  end
36
26
 
37
- # Returns the path to the output file from this package for the given build name.
38
27
  def build_path(build_name)
39
28
  suffix = @build.use_suffix?(build_name) ? "-#{ build_name }" : ""
40
29
  @build.layout == 'together' ?
@@ -42,42 +31,38 @@ module Jake
42
31
  Jake.path(@build.build_directory, build_name, "#{ @name }.js")
43
32
  end
44
33
 
45
- # Returns +true+ if the build file for the given build name is out of date and
46
- # should be regenerated.
47
34
  def build_needed?(name)
48
35
  return true if @build.forced?
49
36
  path = build_path(name)
50
37
  return true unless File.file?(path)
51
38
  build_time = File.mtime(path)
52
- files.any? { |path| File.mtime(path) > build_time }
39
+
40
+ input_files = files + @build.config_files
41
+ input_files.any? { |path| File.mtime(path) > build_time }
53
42
  end
54
43
 
55
- # Returns the header string being used for this package.
56
44
  def header
57
45
  content = @config[:header] ?
58
46
  Jake.read(Jake.path( directory, @config[:header])) :
59
47
  (parent ? parent.header : @build.header)
60
- Jake.erb(content).result(@build.helper.scope).strip
48
+
49
+ header = Jake.erb(content).result(@build.helper.scope)
50
+ return nil if header == ''
51
+ header
61
52
  end
62
53
 
63
- # Returns the PackR settings to use for this package during the given build.
64
54
  def packer_settings(build_name)
65
55
  global = @build.packer_settings(build_name)
66
56
  local = @config[:packer]
67
57
  return parent.packer_settings(build_name) if parent && !local
68
- return false if global == false or local == false
58
+ return {:minify => false} if global == false or local == false
69
59
  {}.merge(global || {}).merge(local || {})
70
60
  end
71
61
 
72
- # Returns a hash containing any metadata attached to the package in the config.
73
62
  def meta
74
63
  @config[:meta] || {}
75
64
  end
76
65
 
77
- # Generates all the build files for this package by looping over all the
78
- # required builds and compressing the source code using each set of minification
79
- # options. Files are only generated if they are out of date or the build has
80
- # been forced.
81
66
  def write!
82
67
  @build.each do |name, settings|
83
68
  path = build_path(name)
@@ -85,7 +70,15 @@ module Jake
85
70
 
86
71
  @build.helper.build = name.to_s
87
72
  FileUtils.mkdir_p(File.dirname(path))
88
- File.open(path, 'wb') { |f| f.write( (header + "\n\n" + code(name)).strip ) }
73
+
74
+ output_code = code(name)
75
+ source_map = output_code.source_map if output_code.respond_to?(:source_map)
76
+
77
+ File.open(path, 'w') { |f| f.write(output_code) }
78
+
79
+ if source_map and source_map.enabled?
80
+ File.open(source_map.filename, 'w') { |f| f.write(source_map.to_s) }
81
+ end
89
82
 
90
83
  @build.fire(:file_created, self, name, path)
91
84
 
@@ -1,25 +1,27 @@
1
1
  module Jake
2
2
  class Bundle < Buildable
3
3
 
4
- # Returns a list of paths to all the files used to build this package.
5
4
  def files
6
5
  base = parent ? parent.files : []
7
6
  base + @config[:files].map { |pkg| @build.package(pkg).files }.flatten
8
7
  end
9
8
 
10
- # Returns the full uncompressed source code of this package, before
11
- # ERB processing. ERB output will be build-dependent; this method
12
- # simply builds the raw template for further processing by other
13
- # methods.
14
9
  def source
15
- @source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n\n\n")
10
+ @source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n")
16
11
  end
17
12
 
18
- # Returns the result of building the source template and minifying
19
- # the output using the given named set of PackR settings.
20
- def code(name)
21
- joiner = (packer_settings(name) == false) ? "\n\n\n" : "\n"
22
- @code[name] ||= @config[:files].map { |pkg| @build.package(pkg).code(name) }.join(joiner)
13
+ def code(build_name)
14
+ return @code[build_name] if @code[build_name]
15
+
16
+ packer = packer_settings(build_name)
17
+ joiner = (packer[:minify] == false) ? "\n" : ""
18
+
19
+ code = @config[:files].map { |pkg| @build.package(pkg).code(build_name, false) }.join(joiner)
20
+ if head = header
21
+ code = head + code
22
+ end
23
+
24
+ @code[build_name] = code
23
25
  end
24
26
 
25
27
  end
@@ -1,6 +1,4 @@
1
1
  module Jake
2
- # The +Helper+ class stores helper methods that can be called from ERB
3
- # when generating source code. Use +jake_helper+ to define new helpers.
4
2
  class Helper
5
3
  attr_accessor :build
6
4
  attr_reader :options
@@ -1,7 +1,6 @@
1
1
  module Jake
2
2
  class Package < Buildable
3
3
 
4
- # Returns a list of paths to all the files used to build this package.
5
4
  def files
6
5
  base = parent ? parent.files : []
7
6
  base + @config[:files].map do |path|
@@ -10,21 +9,60 @@ module Jake
10
9
  end
11
10
  end
12
11
 
13
- # Returns the full uncompressed source code of this package, before
14
- # ERB processing. ERB output will be build-dependent; this method
15
- # simply builds the raw template for further processing by other
16
- # methods.
17
12
  def source
18
- @source ||= files.map { |path| Jake.read(path) }.join("\n\n\n")
13
+ @source ||= files.map { |path| Jake.read(path) }.join("\n")
19
14
  end
20
15
 
21
- # Returns the result of building the source template and minifying
22
- # the output using the given named set of PackR settings.
23
- def code(name)
24
- return @code[name] if @code[name]
25
- settings = packer_settings(name)
26
- output = Jake.erb(source).result(@build.helper.scope)
27
- @code[name] = settings ? Packr.pack(output, settings) : output
16
+ def code(build_name, with_header = true)
17
+ if cached = @code[build_name]
18
+ return with_header ? cached : cached.code
19
+ end
20
+
21
+ packer = packer_settings(build_name)
22
+
23
+ head = header
24
+ head = head.strip unless packer[:minify] == false
25
+
26
+ packer = packer.merge(:header => head)
27
+ code = code_for_packer(packer, build_name)
28
+
29
+ cached = @code[build_name] = code
30
+ with_header ? code : code.code
31
+ end
32
+
33
+ private
34
+
35
+ def code_for_packer(packer, build_name)
36
+ if source_map = packer.delete(:source_map)
37
+ code = code_for_source_map(packer, build_path(build_name), source_map)
38
+ else
39
+ code = compile_erb(source)
40
+ end
41
+ Packr.pack(code, packer)
42
+ end
43
+
44
+ def code_for_source_map(packer, output_path, source_map)
45
+ packer.update(:output_file => output_path)
46
+
47
+ if source_map == :source
48
+ code_for_original_map(packer)
49
+ else
50
+ source_path = Packr::FileSystem.relative_path(build_path(source_map), output_path)
51
+ [{:code => code(source_map), :source => source_path}]
52
+ end
53
+ end
54
+
55
+ def code_for_original_map(packer)
56
+ files.map do |file|
57
+ {
58
+ :code => compile_erb(Jake.read(file)),
59
+ :source => Packr::FileSystem.relative_path(file, packer[:output_file])
60
+ }
61
+ end
62
+ end
63
+
64
+ def compile_erb(template)
65
+ Jake.erb(template).result(@build.helper.scope)
28
66
  end
29
67
 
30
68
  end
metadata CHANGED
@@ -1,130 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jake
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - James Coglan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-09-21 00:00:00 +01:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: eventful
16
+ requirement: &10784480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
17
22
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: *10784480
25
+ - !ruby/object:Gem::Dependency
26
26
  name: packr
27
+ requirement: &10783700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.2.0
27
33
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
34
+ prerelease: false
35
+ version_requirements: *10783700
36
+ - !ruby/object:Gem::Dependency
36
37
  name: oyster
38
+ requirement: &10869700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.5
37
44
  type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: hoe
45
+ prerelease: false
46
+ version_requirements: *10869700
47
+ - !ruby/object:Gem::Dependency
48
+ name: test-unit
49
+ requirement: &10868800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 2.3.3
54
- version:
55
- description: ""
56
- email:
57
- - jcoglan@googlemail.com
58
- executables:
56
+ prerelease: false
57
+ version_requirements: *10868800
58
+ description:
59
+ email: jcoglan@gmail.com
60
+ executables:
59
61
  - jake
60
62
  extensions: []
61
-
62
- extra_rdoc_files:
63
+ extra_rdoc_files:
64
+ - README.rdoc
65
+ files:
63
66
  - History.txt
64
- - Manifest.txt
65
- - README.txt
66
- files:
67
- - History.txt
68
- - Manifest.txt
69
- - README.txt
70
- - Rakefile
67
+ - README.rdoc
71
68
  - bin/jake
72
69
  - lib/jake.rb
70
+ - lib/jake/bundle.rb
73
71
  - lib/jake/helper.rb
74
72
  - lib/jake/build.rb
75
- - lib/jake/buildable.rb
76
73
  - lib/jake/package.rb
77
- - lib/jake/bundle.rb
78
- - test/test_jake.rb
79
- - test/jake.yml
80
- - test/Jakefile
81
- - test/packages.erb
82
- - test/expected/combo/box.js
83
- - test/expected/combo/box-min.js
84
- - test/expected/sub/dir/foo.js
85
- - test/expected/sub/dir/foo-min.js
86
- - test/expected/sub/path/bar.js
87
- - test/expected/sub/path/bar-min.js
88
- - test/expected/basic.js
89
- - test/expected/basic-min.js
90
- - test/expected/ext.js
91
- - test/expected/ext-min.js
92
- - test/expected/LISTING
93
- - test/expected/README
94
- - test/src/foo/bar.js
95
- - test/src/foo/foo.js
96
- - test/src/basic.js
97
- - test/src/basic-ext.js
98
- - test/src/head.js
99
- - test/src/head2.js
100
- has_rdoc: true
74
+ - lib/jake/buildable.rb
101
75
  homepage: http://github.com/jcoglan/jake
102
76
  licenses: []
103
-
104
77
  post_install_message:
105
- rdoc_options:
78
+ rdoc_options:
106
79
  - --main
107
- - README.txt
108
- require_paths:
80
+ - README.rdoc
81
+ require_paths:
109
82
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: "0"
115
- version:
116
- required_rubygems_version: !ruby/object:Gem::Requirement
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: "0"
121
- version:
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
122
95
  requirements: []
123
-
124
- rubyforge_project: jake
125
- rubygems_version: 1.3.3
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.17
126
98
  signing_key:
127
99
  specification_version: 3
128
- summary: ""
129
- test_files:
130
- - test/test_jake.rb
100
+ summary: Build tools for JavaScript projects
101
+ test_files: []
@@ -1,33 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- bin/jake
6
- lib/jake.rb
7
- lib/jake/helper.rb
8
- lib/jake/build.rb
9
- lib/jake/buildable.rb
10
- lib/jake/package.rb
11
- lib/jake/bundle.rb
12
- test/test_jake.rb
13
- test/jake.yml
14
- test/Jakefile
15
- test/packages.erb
16
- test/expected/combo/box.js
17
- test/expected/combo/box-min.js
18
- test/expected/sub/dir/foo.js
19
- test/expected/sub/dir/foo-min.js
20
- test/expected/sub/path/bar.js
21
- test/expected/sub/path/bar-min.js
22
- test/expected/basic.js
23
- test/expected/basic-min.js
24
- test/expected/ext.js
25
- test/expected/ext-min.js
26
- test/expected/LISTING
27
- test/expected/README
28
- test/src/foo/bar.js
29
- test/src/foo/foo.js
30
- test/src/basic.js
31
- test/src/basic-ext.js
32
- test/src/head.js
33
- test/src/head2.js