bunch 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/bunch.rb +30 -11
- data/lib/bunch/caching.rb +42 -0
- data/lib/bunch/cli.rb +6 -6
- data/lib/bunch/coffee_node.rb +4 -2
- data/lib/bunch/directory_node.rb +3 -3
- data/lib/bunch/file_node.rb +1 -1
- data/lib/bunch/rack.rb +6 -16
- data/lib/bunch/sass_node.rb +4 -2
- data/lib/bunch/version.rb +1 -1
- metadata +7 -6
data/lib/bunch.rb
CHANGED
@@ -12,30 +12,49 @@ rescue LoadError
|
|
12
12
|
end
|
13
13
|
|
14
14
|
require 'bunch/version'
|
15
|
+
require 'bunch/rack'
|
16
|
+
require 'bunch/caching'
|
15
17
|
require 'bunch/directory_node'
|
16
18
|
require 'bunch/file_node'
|
17
19
|
require 'bunch/coffee_node'
|
18
20
|
require 'bunch/sass_node'
|
19
|
-
require 'bunch/rack'
|
20
21
|
|
21
22
|
module Bunch
|
22
23
|
end
|
23
24
|
|
24
25
|
class << Bunch
|
25
|
-
def
|
26
|
+
def content_for(path)
|
27
|
+
tree_for(normalized_path(path)).content
|
28
|
+
end
|
29
|
+
|
30
|
+
def tree_for(path)
|
26
31
|
case
|
27
|
-
when
|
28
|
-
|
29
|
-
when
|
30
|
-
Bunch::
|
31
|
-
when
|
32
|
-
Bunch::
|
33
|
-
when fn =~ /\.s(a|c)ss$/
|
34
|
-
Bunch::SassNode.new(fn)
|
32
|
+
when File.directory?(path)
|
33
|
+
Bunch::DirectoryNode.new(path)
|
34
|
+
when path =~ /\.coffee$/
|
35
|
+
Bunch::CoffeeNode.new(path)
|
36
|
+
when path =~ /\.s(a|c)ss$/
|
37
|
+
Bunch::SassNode.new(path)
|
35
38
|
else
|
36
|
-
Bunch::FileNode.new(
|
39
|
+
Bunch::FileNode.new(path)
|
37
40
|
end
|
38
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def normalized_path(path)
|
45
|
+
case
|
46
|
+
when File.exist?(path)
|
47
|
+
path
|
48
|
+
when File.exist?(chopped_path = path.sub(%r(\.[^.]*$), ''))
|
49
|
+
chopped_path
|
50
|
+
when File.basename(path).start_with?('all.') && File.exist?(dir_path = File.dirname(path))
|
51
|
+
dir_path
|
52
|
+
when (path_w_different_extension = Dir["#{chopped_path}.*"].first)
|
53
|
+
path_w_different_extension
|
54
|
+
else
|
55
|
+
raise Errno::ENOENT, path.to_s
|
56
|
+
end
|
57
|
+
end
|
39
58
|
end
|
40
59
|
|
41
60
|
#class Module
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Bunch
|
2
|
+
module Caching
|
3
|
+
class << self
|
4
|
+
def initialize_cache
|
5
|
+
@cache = Hash.new { |h, k| h[k] = {} }
|
6
|
+
end
|
7
|
+
|
8
|
+
def stored?(fn)
|
9
|
+
@cache.keys.include?(fn)
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(fn)
|
13
|
+
@cache[fn][:content]
|
14
|
+
end
|
15
|
+
|
16
|
+
def mtime(fn)
|
17
|
+
@cache[fn][:mtime]
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(fn, mtime, content)
|
21
|
+
@cache[fn] = {:mtime => mtime, :content => content}
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(fn, &blk)
|
25
|
+
current_mtime = File.mtime(fn)
|
26
|
+
|
27
|
+
if stored?(fn) && mtime(fn) == current_mtime
|
28
|
+
read(fn)
|
29
|
+
else
|
30
|
+
content = blk.call
|
31
|
+
write(fn, current_mtime, content)
|
32
|
+
content
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
initialize_cache
|
37
|
+
|
38
|
+
def fetch(filename, &blk)
|
39
|
+
Bunch::Caching.fetch(filename, &blk)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/bunch/cli.rb
CHANGED
@@ -25,7 +25,7 @@ module Bunch
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def generate_files
|
28
|
-
tree = Bunch
|
28
|
+
tree = Bunch.tree_for(@input.to_s)
|
29
29
|
|
30
30
|
if @output
|
31
31
|
FileUtils.mkdir_p(@output.to_s)
|
@@ -33,22 +33,22 @@ module Bunch
|
|
33
33
|
|
34
34
|
if @opts[:all]
|
35
35
|
if @output
|
36
|
-
write("all.#{tree.target_extension}", tree.
|
36
|
+
write("all.#{tree.target_extension}", tree.content)
|
37
37
|
else
|
38
|
-
puts tree.
|
38
|
+
puts tree.content
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
if @opts[:individual]
|
43
43
|
tree.children.each do |child|
|
44
|
-
write("#{child.name}.#{child.target_extension}", child.
|
44
|
+
write("#{child.name}.#{child.target_extension}", child.content)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
50
|
-
def write(fn,
|
51
|
-
File.open(@output.join(fn), 'w') { |f| f.write(
|
50
|
+
def write(fn, content)
|
51
|
+
File.open(@output.join(fn), 'w') { |f| f.write(content) }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/bunch/coffee_node.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Bunch
|
2
2
|
class CoffeeNode
|
3
|
+
include Caching
|
4
|
+
|
3
5
|
def initialize(fn)
|
4
6
|
unless defined?(@@coffee_required)
|
5
7
|
require 'coffee-script'
|
@@ -10,8 +12,8 @@ module Bunch
|
|
10
12
|
raise "'gem install coffee-script' to compile .coffee files."
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
@
|
15
|
+
def content
|
16
|
+
@content ||= fetch(@filename) { CoffeeScript.compile(File.read(@filename), :bare => false) }
|
15
17
|
end
|
16
18
|
|
17
19
|
def name
|
data/lib/bunch/directory_node.rb
CHANGED
@@ -12,7 +12,7 @@ module Bunch
|
|
12
12
|
|
13
13
|
def children
|
14
14
|
@children ||= begin
|
15
|
-
children = filenames.map &Bunch.method(:
|
15
|
+
children = filenames.map &Bunch.method(:tree_for)
|
16
16
|
ordering_file = @root.join('_.yml')
|
17
17
|
|
18
18
|
if File.exist?(ordering_file)
|
@@ -36,8 +36,8 @@ module Bunch
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
@
|
39
|
+
def content
|
40
|
+
@content ||= children.map(&:content).join
|
41
41
|
end
|
42
42
|
|
43
43
|
def name
|
data/lib/bunch/file_node.rb
CHANGED
data/lib/bunch/rack.rb
CHANGED
@@ -15,7 +15,7 @@ module Bunch
|
|
15
15
|
path = @root.join(env['PATH_INFO'].sub(/^\//, '')).to_s
|
16
16
|
type = MIME::Types.type_for(path).first || 'text/plain'
|
17
17
|
|
18
|
-
[200, headers(type), [
|
18
|
+
[200, headers(type), [content_for(path)]]
|
19
19
|
rescue => e
|
20
20
|
[500, headers('text/plain'), [error_log(e)]]
|
21
21
|
end
|
@@ -25,23 +25,13 @@ module Bunch
|
|
25
25
|
@headers.merge('Content-Type' => mime_type.to_s)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
contents(path)
|
32
|
-
when File.exist?(chopped_path = path.sub(%r(\.[^.]*$), ''))
|
33
|
-
contents(chopped_path)
|
34
|
-
when File.basename(path).start_with?('all.')
|
35
|
-
contents(File.dirname(path))
|
36
|
-
when (path_w_different_extension = Dir["#{chopped_path}.*"].first)
|
37
|
-
contents(path_w_different_extension)
|
38
|
-
else
|
39
|
-
raise Errno::ENOENT, path.to_s
|
40
|
-
end
|
28
|
+
private
|
29
|
+
def content_for(path)
|
30
|
+
Bunch.content_for(path)
|
41
31
|
end
|
42
32
|
|
43
|
-
def
|
44
|
-
|
33
|
+
def headers(mime_type)
|
34
|
+
@headers.merge('Content-Type' => mime_type.to_s)
|
45
35
|
end
|
46
36
|
|
47
37
|
def error_log(e)
|
data/lib/bunch/sass_node.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Bunch
|
2
2
|
class SassNode
|
3
|
+
include Caching
|
4
|
+
|
3
5
|
def initialize(fn)
|
4
6
|
unless defined?(@@sass_required)
|
5
7
|
require 'sass'
|
@@ -10,8 +12,8 @@ module Bunch
|
|
10
12
|
raise "'gem install sass' to compile .sass and .scss files."
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
@
|
15
|
+
def content
|
16
|
+
@content ||= fetch(@filename) { Sass::Engine.for_file(@filename, {}).render }
|
15
17
|
end
|
16
18
|
|
17
19
|
def name
|
data/lib/bunch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
16
|
-
requirement: &
|
16
|
+
requirement: &70263668761740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70263668761740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: slop
|
27
|
-
requirement: &
|
27
|
+
requirement: &70263668761320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70263668761320
|
36
36
|
description: Directory-structure-based asset bundling.
|
37
37
|
email:
|
38
38
|
- rfitz@academia.edu
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- example/js/test4/test4b.coffee
|
66
66
|
- example/js/test4/test4c.coffee
|
67
67
|
- lib/bunch.rb
|
68
|
+
- lib/bunch/caching.rb
|
68
69
|
- lib/bunch/cli.rb
|
69
70
|
- lib/bunch/coffee_node.rb
|
70
71
|
- lib/bunch/directory_node.rb
|