bunch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.name = "bunch"
7
7
  s.version = Bunch::VERSION
8
8
  s.authors = ["Ryan Fitzgerald"]
9
- s.email = ["rwfitzge@gmail.com"]
10
- s.homepage = "http://rynftz.gr"
11
- s.summary = %q{Simple, directory-structure-based asset bundling.}
12
- s.description = %q{Simple, directory-structure-based asset bundling.}
9
+ s.email = ["rfitz@academia.edu"]
10
+ s.homepage = ""
11
+ s.summary = %q{Directory-structure-based asset bundling.}
12
+ s.description = %q{Directory-structure-based asset bundling.}
13
13
 
14
14
  s.rubyforge_project = "bunch"
15
15
 
@@ -4,9 +4,23 @@ module Bunch
4
4
  @input = Pathname.new(input)
5
5
  @output = output ? Pathname.new(output) : nil
6
6
  @opts = opts
7
+
8
+ if @opts[:server]
9
+ run_server
10
+ else
11
+ generate_files
12
+ end
7
13
  end
8
14
 
9
- def process!
15
+ def run_server
16
+ require 'rack'
17
+ ::Rack::Handler::WEBrick.run(Bunch::Rack.new(@input), :Port => 3001)
18
+ rescue LoadError
19
+ $stderr.puts "ERROR: 'gem install rack' to run Bunch in server mode."
20
+ exit 1
21
+ end
22
+
23
+ def generate_files
10
24
  tree = Bunch::Tree(@input.to_s)
11
25
 
12
26
  if @output
@@ -15,7 +29,7 @@ module Bunch
15
29
 
16
30
  if @opts[:all]
17
31
  if @output
18
- write(@output.join("all.#{tree.target_extension}"), tree.contents)
32
+ write("all.#{tree.target_extension}", tree.contents)
19
33
  else
20
34
  puts tree.contents
21
35
  end
@@ -23,14 +37,14 @@ module Bunch
23
37
 
24
38
  if @opts[:individual]
25
39
  tree.children.each do |child|
26
- write(@output.join("#{child.name}.#{child.target_extension}"), child.contents)
40
+ write("#{child.name}.#{child.target_extension}", child.contents)
27
41
  end
28
42
  end
29
43
  end
30
44
 
31
45
  private
32
46
  def write(fn, contents)
33
- File.open(fn, 'w') { |f| f.write(contents) }
47
+ File.open(@output.join(fn), 'w') { |f| f.write(contents) }
34
48
  end
35
49
  end
36
50
 
@@ -39,37 +53,36 @@ module Bunch
39
53
  opts = Slop.parse! do
40
54
  banner 'Usage: bunch [options] INPUT_PATH [OUTPUT_PATH]'
41
55
 
56
+ on :s, :server, 'Instead of creating files, use WEBrick to serve files from INPUT_PATH'
42
57
  on :i, :individual, 'Create one output file for each file or directory in the input path (default)', :default => true
43
58
  on :a, :all, 'Create an all.[extension] file combining all inputs'
44
59
  on :h, :help, 'Show this message' do
45
- display_help = true
60
+ puts self
61
+ exit
46
62
  end
47
63
  end
48
64
 
49
65
  if ARGV.count < 1
50
- $stderr.puts "ERROR: Must give an input path."
51
66
  display_help = true
67
+ raise "Must give an input path."
52
68
  end
53
69
 
54
- if ARGV.count < 2 && opts[:individual]
55
- $stderr.puts "ERROR: Must give an output path unless --no-individual is provided."
70
+ if ARGV.count < 2 && opts[:individual] && !opts[:server]
56
71
  display_help = true
57
- end
58
-
59
- if display_help
60
- $stderr.puts "\n#{opts}"
61
- exit
72
+ raise "Must give an output path unless --no-individual or --server is provided."
62
73
  end
63
74
 
64
75
  input = ARGV.shift
65
76
  output = ARGV.shift
66
77
 
67
- CLI.new(input, output, opts).process!
68
- rescue Exception => e
78
+ CLI.new(input, output, opts)
79
+ rescue => e
69
80
  if ENV['BUNCH_DEBUG']
70
81
  raise
71
82
  else
72
83
  $stderr.puts "ERROR: #{e.message}"
84
+ $stderr.puts "\n#{opts}" if display_help
85
+ exit 1
73
86
  end
74
87
  end
75
88
  end
@@ -4,7 +4,7 @@ module Bunch
4
4
  require 'coffee-script'
5
5
  @filename = fn
6
6
  rescue LoadError
7
- $stderr.puts "ERROR: 'gem install coffee-script' to compile .coffee files."
7
+ raise "'gem install coffee-script' to compile .coffee files."
8
8
  end
9
9
 
10
10
  def contents
@@ -45,7 +45,7 @@ module Bunch
45
45
  end
46
46
 
47
47
  def inspect
48
- "#<Node @root=#{@root.inspect} @children=#{children.inspect}>"
48
+ "#<DirectoryNode @root=#{@root.inspect} @children=#{children.inspect}>"
49
49
  end
50
50
  end
51
51
  end
@@ -5,7 +5,7 @@ module Bunch
5
5
  def initialize(fn)
6
6
  @filename = fn
7
7
 
8
- if fn =~ %r(\.([^/]*?)$)
8
+ if fn =~ %r(\.([^.]*)$)
9
9
  @name = File.basename($`)
10
10
  @target_extension = $1
11
11
  else
@@ -17,7 +17,7 @@ module Bunch
17
17
  def generate(path)
18
18
  if File.exist?(path)
19
19
  Bunch::Tree(path).contents
20
- elsif File.exist?(chopped_path = path.sub(%r(\.[^/]*?$), ''))
20
+ elsif File.exist?(chopped_path = path.sub(%r(\.[^.]*$), ''))
21
21
  Bunch::Tree(chopped_path).contents
22
22
  elsif File.basename(path).start_with?('all.')
23
23
  Bunch::Tree(File.dirname(path)).contents
@@ -4,7 +4,7 @@ module Bunch
4
4
  require 'sass'
5
5
  @filename = fn
6
6
  rescue LoadError
7
- $stderr.puts "ERROR: 'gem install sass' to compile .coffee files."
7
+ raise "'gem install sass' to compile .sass and .scss files."
8
8
  end
9
9
 
10
10
  def contents
@@ -1,3 +1,3 @@
1
1
  module Bunch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
4
+ version: 0.0.2
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: 2011-12-28 00:00:00.000000000 Z
12
+ date: 2011-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
16
- requirement: &70324537243860 !ruby/object:Gem::Requirement
16
+ requirement: &70119922351140 !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: *70324537243860
24
+ version_requirements: *70119922351140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: slop
27
- requirement: &70324537243440 !ruby/object:Gem::Requirement
27
+ requirement: &70119922350720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70324537243440
36
- description: Simple, directory-structure-based asset bundling.
35
+ version_requirements: *70119922350720
36
+ description: Directory-structure-based asset bundling.
37
37
  email:
38
- - rwfitzge@gmail.com
38
+ - rfitz@academia.edu
39
39
  executables:
40
40
  - bunch
41
41
  extensions: []
@@ -72,7 +72,7 @@ files:
72
72
  - lib/bunch/rack.rb
73
73
  - lib/bunch/sass_node.rb
74
74
  - lib/bunch/version.rb
75
- homepage: http://rynftz.gr
75
+ homepage: ''
76
76
  licenses: []
77
77
  post_install_message:
78
78
  rdoc_options: []
@@ -95,6 +95,6 @@ rubyforge_project: bunch
95
95
  rubygems_version: 1.8.10
96
96
  signing_key:
97
97
  specification_version: 3
98
- summary: Simple, directory-structure-based asset bundling.
98
+ summary: Directory-structure-based asset bundling.
99
99
  test_files: []
100
100
  has_rdoc: