rab 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70ec01c9cac79e43818cf4f443250646e68191ea
4
- data.tar.gz: 91b1ccdbd5ce70063b92bd0bfc76a9e2504f762f
3
+ metadata.gz: 475c9e38ba1ea4ee44bf74c88e7e56ec975535cd
4
+ data.tar.gz: bf04191cf1e257484c0ef942075122c23baaff9c
5
5
  SHA512:
6
- metadata.gz: 1b48382802e3cc59742e8f27fe6d1d60feb281d289e47da0d75735a44e86679844a51ba934c2cbbce15d477f7525f876d33c724bc5254d04c08b33f2436d1244
7
- data.tar.gz: d2039afe8edd8dd07d3d33a20e6afba6d3b418b005bec480ecb100e53d579807e64c20e5cf5f7977f38df637d99707063d46f0efb8ce8f1837f3b50931ee9c0b
6
+ metadata.gz: af164bf2639ae1c6bf3a745903a90bb4cf3ebb89d678c29bc514e011f60038551be65e4e5cd341e75c6e7a57c8a9f43802bd9c6f5f3af359e953a441263f35b3
7
+ data.tar.gz: 6eeeb6453bbbd558338f34e2a671ff2166252bdc619efbfc759c18abca6d25acc86c02d41a14c443acf87f824bab74a3669be5940e11dc6bfa9d74cbb09fe5ed
data/README.md CHANGED
@@ -1,28 +1,23 @@
1
- # Rab
1
+ # Rails Asset Builder (RAB)
2
2
 
3
- TODO: Write a gem description
3
+ Rails Asset Builder (RAB) builds Rails asset as a gem from a [bower](http://bower.io/) project.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'rab'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install rab
7
+ ```
8
+ gem install rab
9
+ ```
18
10
 
19
11
  ## Usage
20
12
 
21
- TODO: Write usage instructions here
13
+ ```
14
+ rab build BOWER_PROJECT GEM_FOLDER
15
+ ```
16
+
22
17
 
23
18
  ## Contributing
24
19
 
25
- 1. Fork it ( https://github.com/[my-github-username]/rab/fork )
20
+ 1. Fork it (https://github.com/jingweno/rab/fork)
26
21
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
22
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
23
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/rab.rb CHANGED
@@ -4,6 +4,20 @@ end
4
4
  require "rab/bower/command_error"
5
5
  require "rab/bower/command"
6
6
  require "rab/bower/project"
7
+
8
+ require "rab/gem/writer/template"
9
+ require "rab/gem/writer/asset"
10
+ require "rab/gem/writer/readme"
11
+ require "rab/gem/writer/gemspec"
12
+ require "rab/gem/writer/gemfile"
13
+ require "rab/gem/writer/rakefile"
14
+ require "rab/gem/writer/engine"
15
+ require "rab/gem/writer/version"
16
+ require "rab/gem/writer/js"
17
+ require "rab/gem/writer/css"
18
+ require "rab/gem/writer/font"
19
+ require "rab/gem/writer/image"
7
20
  require "rab/gem/packer"
21
+
8
22
  require "rab/builder"
9
23
  require "rab/version"
@@ -34,8 +34,13 @@ module Bower
34
34
 
35
35
  def build_assets(cwd, paths)
36
36
  Array(paths).map do |p|
37
- full_path(cwd, p)
38
- end
37
+ pp = full_path(cwd, p)
38
+ if File.directory?(pp)
39
+ pp = Dir["#{pp}/**/*"].select { |f| !File.directory? f }
40
+ end
41
+
42
+ pp
43
+ end.flatten
39
44
  end
40
45
 
41
46
  def build_dep_assets(cwd, dep_paths)
@@ -59,11 +64,11 @@ module Bower
59
64
  end
60
65
 
61
66
  def rails_assets_dir_name
62
- @dir_name ||= "rails-assets-#{dir_name}"
67
+ @dir_name ||= "rab-#{dir_name}"
63
68
  end
64
69
 
65
70
  def rails_assets_namespace
66
- @namespace ||= "RailsAssets#{classify(underscore(name))}"
71
+ @namespace ||= "Rab#{classify(underscore(name))}"
67
72
  end
68
73
 
69
74
  def js_assets
@@ -78,6 +83,10 @@ module Bower
78
83
  @font_assets ||= assets.select { |a| [ ".eot", ".svg", ".ttf", ".woff" ].include?(File.extname(a)) }
79
84
  end
80
85
 
86
+ def image_assets
87
+ @image_assets ||= assets.select { |a| [ ".png", ".ico", ".jpg", ".jpeg", ".gif" ].include?(File.extname(a)) }
88
+ end
89
+
81
90
  def self.create!(src)
82
91
  Creator.new(src).create!
83
92
  end
@@ -9,84 +9,61 @@ module Gem
9
9
  end
10
10
 
11
11
  def pack!(dst)
12
+ dst = File.join(dst, @project.rails_assets_dir_name)
13
+ FileUtils.mkdir_p(dst)
14
+
12
15
  write_readme(dst)
13
16
  write_gemspec(dst)
14
17
  write_gemfile(dst)
15
18
  write_rakefile(dst)
16
- write_lib_file(dst)
19
+ write_engine_file(dst)
17
20
  write_version_file(dst)
18
21
  write_js_assets(dst)
19
22
  write_css_assets(dst)
20
23
  write_font_assets(dst)
24
+ write_image_assets(dst)
21
25
  end
22
26
 
23
27
  private
24
28
 
25
29
  def write_readme(dst)
26
- readme = File.join(dst, "README.md")
27
- write_template("README.md.erb", readme)
30
+ Gem::Writter::Readme.new(@project).write(dst)
28
31
  end
29
32
 
30
33
  def write_gemspec(dst)
31
- gemspec = File.join(dst, "#{@project.rails_assets_dir_name}.gemspec")
32
- write_template("gemspec.gemspec.erb", gemspec)
34
+ Gem::Writter::Gemspec.new(@project).write(dst)
33
35
  end
34
36
 
35
37
  def write_gemfile(dst)
36
- gemfile = File.join(dst, "Gemfile")
37
- write_template("Gemfile.erb", gemfile)
38
+ Gem::Writter::Gemfile.new(@project).write(dst)
38
39
  end
39
40
 
40
41
  def write_rakefile(dst)
41
- rakefile = File.join(dst, "Rakefile")
42
- write_template("Rakefile.erb", rakefile)
42
+ Gem::Writter::Rakefile.new(@project).write(dst)
43
43
  end
44
44
 
45
- def write_lib_file(dst)
46
- lib_file = File.join(dst, "lib", "#{@project.rails_assets_dir_name}.rb")
47
- write_template("lib.rb.erb", lib_file)
45
+ def write_engine_file(dst)
46
+ Gem::Writter::Engine.new(@project).write(dst)
48
47
  end
49
48
 
50
49
  def write_version_file(dst)
51
- version_file = File.join(dst, "lib", @project.rails_assets_dir_name, "version.rb")
52
- write_template("version.rb.erb", version_file)
53
- end
54
-
55
- def write_template(name, to_file)
56
- FileUtils.mkdir_p File.dirname(to_file)
57
- template = ERB.new File.read(template(name)), nil, "-"
58
- File.open(to_file, "w") { |f| f.write template.result(binding) }
50
+ Gem::Writter::Version.new(@project).write(dst)
59
51
  end
60
52
 
61
53
  def write_js_assets(dst)
62
- js_dir = File.join(dst, "vendor", "assets", "javascripts")
63
- write_assets(js_dir, @project.js_assets)
64
-
65
- manifest_file = File.join(js_dir, "#{@project.dir_name}.js")
66
- write_template("js.js.erb", manifest_file)
54
+ Gem::Writter::JS.new(@project).write(dst)
67
55
  end
68
56
 
69
57
  def write_css_assets(dst)
70
- css_dir = File.join(dst, "vendor", "assets", "stylesheets")
71
- write_assets(css_dir, @project.css_assets)
72
-
73
- manifest_file = File.join(css_dir, "#{@project.dir_name}.css")
74
- write_template("css.css.erb", manifest_file)
58
+ Gem::Writter::CSS.new(@project).write(dst)
75
59
  end
76
60
 
77
61
  def write_font_assets(dst)
78
- font_dir = File.join(dst, "vendor", "assets", "fonts")
79
- write_assets(font_dir, @project.font_assets)
80
- end
81
-
82
- def write_assets(dir, assets)
83
- asset_dir = File.join(dir, @project.dir_name)
84
- FileUtils.mkdir_p(asset_dir)
85
- assets.each { |a| FileUtils.cp a, File.join(asset_dir, File.basename(a)) }
62
+ Gem::Writter::Font.new(@project).write(dst)
86
63
  end
87
64
 
88
- def template(name)
89
- File.expand_path File.join(File.dirname(__FILE__), "templates", name)
65
+ def write_image_assets(dst)
66
+ Gem::Writter::Image.new(@project).write(dst)
90
67
  end
91
68
  end
92
69
  end
@@ -6,7 +6,7 @@ require '<%= @project.rails_assets_dir_name %>/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "<%= @project.rails_assets_dir_name %>"
8
8
  spec.version = <%= @project.rails_assets_namespace %>::VERSION
9
- spec.authors = ["rails-assets.org"]
9
+ spec.authors = ["rab"]
10
10
  spec.description = ""
11
11
  spec.summary = ""
12
12
  spec.homepage = "https://github.com/angular/bower-angular"
@@ -0,0 +1,13 @@
1
+ module Gem
2
+ module Writter
3
+ class Asset < Template
4
+ protected
5
+
6
+ def write_assets(dir, assets)
7
+ asset_dir = File.join(dir, @project.dir_name)
8
+ FileUtils.mkdir_p(asset_dir)
9
+ assets.each { |a| FileUtils.cp a, File.join(asset_dir, File.basename(a)) }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Gem
2
+ module Writter
3
+ class CSS < Asset
4
+ def write(dst)
5
+ return if @project.css_assets.empty?
6
+
7
+ css_dir = File.join(dst, "vendor", "assets", "stylesheets")
8
+ write_assets(css_dir, @project.css_assets)
9
+
10
+ manifest_file = File.join(css_dir, "#{@project.dir_name}.css")
11
+ write_template("css_manifest.css.erb", manifest_file)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Engine < Template
4
+ def write(dst)
5
+ engine_file = File.join(dst, "lib", "#{@project.rails_assets_dir_name}.rb")
6
+ write_template("engine.rb.erb", engine_file)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Gem
2
+ module Writter
3
+ class Font < Asset
4
+ def write(dst)
5
+ return if @project.font_assets.empty?
6
+
7
+ font_dir = File.join(dst, "vendor", "assets", "fonts")
8
+ write_assets(font_dir, @project.font_assets)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Gemfile < Template
4
+ def write(dst)
5
+ gemfile = File.join(dst, "Gemfile")
6
+ write_template("Gemfile.erb", gemfile)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Gemspec < Template
4
+ def write(dst)
5
+ gemspec = File.join(dst, "#{@project.rails_assets_dir_name}.gemspec")
6
+ write_template("gemspec.gemspec.erb", gemspec)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Gem
2
+ module Writter
3
+ class Image < Asset
4
+ def write(dst)
5
+ return if @project.image_assets.empty?
6
+
7
+ image_dir = File.join(dst, "vendor", "assets", "images")
8
+ write_assets(image_dir, @project.image_assets)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Gem
2
+ module Writter
3
+ class JS < Asset
4
+ def write(dst)
5
+ return if @project.js_assets.empty?
6
+
7
+ js_dir = File.join(dst, "vendor", "assets", "javascripts")
8
+ write_assets(js_dir, @project.js_assets)
9
+
10
+ manifest_file = File.join(js_dir, "#{@project.dir_name}.js")
11
+ write_template("js_manifest.js.erb", manifest_file)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Rakefile < Template
4
+ def write(dst)
5
+ rakefile = File.join(dst, "Rakefile")
6
+ write_template("Rakefile.erb", rakefile)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Readme < Template
4
+ def write(dst)
5
+ readme = File.join(dst, "README.md")
6
+ write_template("README.md.erb", readme)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ module Gem
2
+ module Writter
3
+ class Template
4
+ def initialize(project)
5
+ @project = project
6
+ end
7
+
8
+ protected
9
+
10
+ def write_template(template_name, to_file)
11
+ FileUtils.mkdir_p File.dirname(to_file)
12
+ template = ERB.new File.read(template(template_name)), nil, "-"
13
+ File.open(to_file, "w") { |f| f.write template.result(binding) }
14
+ end
15
+
16
+ def template(name)
17
+ File.expand_path File.join(File.dirname(__FILE__), "..", "templates", name)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Gem
2
+ module Writter
3
+ class Version < Template
4
+ def write(dst)
5
+ version_file = File.join(dst, "lib", @project.rails_assets_dir_name, "version.rb")
6
+ write_template("version.rb.erb", version_file)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Rab
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Rab::VERSION
9
9
  spec.authors = ["Jingwen Owen Ou"]
10
10
  spec.email = ["jingweno@gmail.com"]
11
- spec.summary = %q{Rails Assets Buidler (RAB) builds Rails asset from a bower project.}
11
+ spec.summary = %q{Rails Assets Buidler (RAB) builds Rails asset as a gem from a bower project.}
12
12
  spec.homepage = "https://github.com/jingweno/rab"
13
13
  spec.license = "MIT"
14
14
 
@@ -6,6 +6,6 @@ describe Bower do
6
6
  prj = Bower::Project.create!("test/fixtures/bower_project")
7
7
  prj.name.must_equal "test-project"
8
8
  prj.version.must_equal "0.0.0"
9
- prj.assets.size.must_equal 9
9
+ prj.assets.size.must_equal 12
10
10
  end
11
11
  end
File without changes
@@ -4,7 +4,7 @@
4
4
  },
5
5
  "name": "test-project",
6
6
  "version": "0.0.0",
7
- "main": ["./foo.js", "./foo.css"],
7
+ "main": ["./foo.js", "./foo.css", "./foo.png", "./bar"],
8
8
  "dependencies": {
9
9
  "bootstrap": ">=1"
10
10
  }
File without changes
@@ -8,14 +8,16 @@ describe Rab::Builder do
8
8
  rab = Rab::Builder.new("test/fixtures/bower_project", dir)
9
9
  rab.build!
10
10
 
11
+ dir = File.join(dir, "rab-test-project")
12
+
11
13
  readme = File.read File.join(dir, "README.md")
12
- readme.must_include "# rails-assets-test-project"
13
- readme.must_include "gem \"rails-assets-test-project\""
14
+ readme.must_include "# rab-test-project"
15
+ readme.must_include "gem \"rab-test-project\""
14
16
  readme.must_include "//= require \"test-project\""
15
17
 
16
- gemspec = File.read File.join(dir, "rails-assets-test-project.gemspec")
17
- gemspec.must_include "require 'rails-assets-test-project/version'"
18
- gemspec.must_include "RailsAssetsTestProject::VERSION"
18
+ gemspec = File.read File.join(dir, "rab-test-project.gemspec")
19
+ gemspec.must_include "require 'rab-test-project/version'"
20
+ gemspec.must_include "RabTestProject::VERSION"
19
21
 
20
22
  gemfile = File.read File.join(dir, "Gemfile")
21
23
  gemfile.must_include "source 'https://rails-assets.org'"
@@ -23,18 +25,21 @@ describe Rab::Builder do
23
25
  rakefile = File.read File.join(dir, "Rakefile")
24
26
  rakefile.must_include "require \"bundler/gem_tasks\""
25
27
 
26
- lib_file = File.read File.join(dir, "lib", "rails-assets-test-project.rb")
27
- lib_file.must_include "require \"rails-assets-test-project/version\""
28
- lib_file.must_include "module RailsAssetsTestProject"
28
+ lib_file = File.read File.join(dir, "lib", "rab-test-project.rb")
29
+ lib_file.must_include "require \"rab-test-project/version\""
30
+ lib_file.must_include "module RabTestProject"
29
31
 
30
- version_file = File.read File.join(dir, "lib", "rails-assets-test-project", "version.rb")
31
- version_file.must_include "module RailsAssetsTestProject"
32
+ version_file = File.read File.join(dir, "lib", "rab-test-project", "version.rb")
33
+ version_file.must_include "module RabTestProject"
32
34
  version_file.must_include "VERSION = \"0.0.0\""
33
35
 
34
36
  js_path = File.join(dir, "vendor", "assets", "javascripts", "test-project")
35
37
  js_files = Dir.entries(js_path)
38
+ js_files.size.must_equal 7 # plus . and ..
36
39
  js_files.must_include "bootstrap.js"
37
40
  js_files.must_include "foo.js"
41
+ js_files.must_include "bar.js"
42
+ js_files.must_include "baz.js"
38
43
  js_files.must_include "jquery.js"
39
44
 
40
45
  js_manifest = File.read File.join(dir, "vendor", "assets", "javascripts", "test-project.js")
@@ -44,6 +49,7 @@ describe Rab::Builder do
44
49
 
45
50
  css_path = File.join(dir, "vendor", "assets", "stylesheets", "test-project")
46
51
  css_files = Dir.entries(css_path)
52
+ css_files.size.must_equal 4 # plus . and ..
47
53
  css_files.must_include "bootstrap.css"
48
54
  css_files.must_include "foo.css"
49
55
 
@@ -53,10 +59,16 @@ describe Rab::Builder do
53
59
 
54
60
  font_path = File.join(dir, "vendor", "assets", "fonts", "test-project")
55
61
  font_files = Dir.entries(font_path)
62
+ font_files.size.must_equal 6 # plus . and ..
56
63
  font_files.must_include "glyphicons-halflings-regular.eot"
57
64
  font_files.must_include "glyphicons-halflings-regular.svg"
58
65
  font_files.must_include "glyphicons-halflings-regular.ttf"
59
66
  font_files.must_include "glyphicons-halflings-regular.woff"
67
+
68
+ image_path = File.join(dir, "vendor", "assets", "images", "test-project")
69
+ image_files = Dir.entries(image_path)
70
+ image_files.size.must_equal 3 # plus . and ..
71
+ image_files.must_include "foo.png"
60
72
  end
61
73
  end
62
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingwen Owen Ou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -91,18 +91,33 @@ files:
91
91
  - lib/rab/gem/templates/Gemfile.erb
92
92
  - lib/rab/gem/templates/README.md.erb
93
93
  - lib/rab/gem/templates/Rakefile.erb
94
- - lib/rab/gem/templates/css.css.erb
94
+ - lib/rab/gem/templates/css_manifest.css.erb
95
+ - lib/rab/gem/templates/engine.rb.erb
95
96
  - lib/rab/gem/templates/gemspec.gemspec.erb
96
- - lib/rab/gem/templates/js.js.erb
97
- - lib/rab/gem/templates/lib.rb.erb
97
+ - lib/rab/gem/templates/js_manifest.js.erb
98
98
  - lib/rab/gem/templates/version.rb.erb
99
+ - lib/rab/gem/writer/asset.rb
100
+ - lib/rab/gem/writer/css.rb
101
+ - lib/rab/gem/writer/engine.rb
102
+ - lib/rab/gem/writer/font.rb
103
+ - lib/rab/gem/writer/gemfile.rb
104
+ - lib/rab/gem/writer/gemspec.rb
105
+ - lib/rab/gem/writer/image.rb
106
+ - lib/rab/gem/writer/js.rb
107
+ - lib/rab/gem/writer/rakefile.rb
108
+ - lib/rab/gem/writer/readme.rb
109
+ - lib/rab/gem/writer/template.rb
110
+ - lib/rab/gem/writer/version.rb
99
111
  - lib/rab/version.rb
100
112
  - rab.gemspec
101
113
  - test/bower/test_bower.rb
102
114
  - test/fixtures/bower_project/.gitignore
115
+ - test/fixtures/bower_project/bar/bar.js
116
+ - test/fixtures/bower_project/bar/baz/baz.js
103
117
  - test/fixtures/bower_project/bower.json
104
118
  - test/fixtures/bower_project/foo.css
105
119
  - test/fixtures/bower_project/foo.js
120
+ - test/fixtures/bower_project/foo.png
106
121
  - test/test_builder.rb
107
122
  homepage: https://github.com/jingweno/rab
108
123
  licenses:
@@ -127,11 +142,14 @@ rubyforge_project:
127
142
  rubygems_version: 2.2.2
128
143
  signing_key:
129
144
  specification_version: 4
130
- summary: Rails Assets Buidler (RAB) builds Rails asset from a bower project.
145
+ summary: Rails Assets Buidler (RAB) builds Rails asset as a gem from a bower project.
131
146
  test_files:
132
147
  - test/bower/test_bower.rb
133
148
  - test/fixtures/bower_project/.gitignore
149
+ - test/fixtures/bower_project/bar/bar.js
150
+ - test/fixtures/bower_project/bar/baz/baz.js
134
151
  - test/fixtures/bower_project/bower.json
135
152
  - test/fixtures/bower_project/foo.css
136
153
  - test/fixtures/bower_project/foo.js
154
+ - test/fixtures/bower_project/foo.png
137
155
  - test/test_builder.rb