bower-rails 0.2.1 → 0.3.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cb67f76bfaa66d517071c94179c6939875b5444
4
+ data.tar.gz: 58a066463fb3fb28ae7f4ca70fca264bb7a981f3
5
+ SHA512:
6
+ metadata.gz: c598443d14f97c2f306f0be54d4c813d3f15d70b38045c5a10800dec0dcbb177e8768866eef2e525d2670c6d39d868edd7d9c9db9cbaef440d8b71093af99b53
7
+ data.tar.gz: cc57c5802e7fc964f5c589442f76e8f65aa285683b297ca321f32b5a1c69726069be07bd9d86ba625c29e777a0e7ee56d671917f7a3413f3dd93daceee9b1fad
data/README.md CHANGED
@@ -3,17 +3,28 @@ bower-rails
3
3
 
4
4
  rake tasks for bower on rails. Dependency file is bower.json in Rails root dir.
5
5
 
6
+ **Asset Pipeline**
7
+
8
+ As of version 0.3.0 bower-rails installs components in the asset directory, rather than assets/javascripts. This is because some of these packages also include stylesheets, or images. As such you may have to add components to your asset pipeline.
9
+
10
+ ``` Ruby
11
+ # config/application.rb
12
+
13
+ config.assets.paths << Rails.root.join("lib", "assets", "components")
14
+ config.assets.paths << Rails.root.join("vendor", "assets", "components")
15
+ ```
16
+
6
17
  **Requirements**
7
18
 
8
19
  * [node](http://nodejs.org) ([on github](https://github.com/joyent/node))
9
- * [bower](https://github.com/twitter/bow) installed with npm
20
+ * [bower](https://github.com/twitter/bow) (>= 0.9) installed with npm
10
21
 
11
22
  **Install**
12
23
 
13
24
  in Gemfile
14
25
 
15
26
  ``` Ruby
16
- gem 'bower-rails'
27
+ gem "bower-rails", "~> 0.3.1"
17
28
  ```
18
29
 
19
30
  **Initialize**
@@ -24,8 +35,7 @@ To add an empty bower.json file to the project root.
24
35
  rails g bower_rails:initialize
25
36
  ```
26
37
 
27
-
28
- **Configuration**
38
+ ##JSON configuration
29
39
 
30
40
  The bower.json file is two seperate bower [component.js](https://github.com/twitter/bower#defining-a-package) files. Defining a package in lib and vendor will install those packages to the corresponding directories.
31
41
 
@@ -36,8 +46,8 @@ The bower.json file is two seperate bower [component.js](https://github.com/twit
36
46
  "lib": {
37
47
  "dependencies": {
38
48
  "threex" : "git@github.com:rharriso/threex.git",
39
- "gsvpano.js" : "https://github.com/rharriso/GSVPano.js/blob/master/src/GSVPano.js"
40
- }
49
+ "gsvpano.js" : "https://github.com/rharriso/GSVPano.js/blob/master/src/GSVPano.js"
50
+ }
41
51
  },
42
52
  "vendor": {
43
53
  "dependencies": {
@@ -48,9 +58,45 @@ The bower.json file is two seperate bower [component.js](https://github.com/twit
48
58
  ```
49
59
 
50
60
 
51
- **Available command
61
+ **Available commands**
52
62
 
53
63
  ``` bash
54
64
  rake bower:install #install js components
55
65
  rake bower:update #update js components
56
- ```
66
+ ```
67
+
68
+
69
+ ##Ruby DSL configuration
70
+
71
+ The Ruby DSL configuration is a Jsfile with DSL syntax similar to Bundler
72
+
73
+
74
+ **Example Jsfile**
75
+
76
+ ``` ruby
77
+ assets_path "assets/javascript"
78
+
79
+ # Puts files under ./vendor/assets/js
80
+ group :vendor, :assets_path => "assets/js" do
81
+ js "jquery" # Assummes it's latests
82
+ js "backbone", "1.2"
83
+ end
84
+
85
+ # Puts files under ./lib/assets/javascript
86
+ group :lib do
87
+ js "jquery"
88
+ js "backbone", "1.2"
89
+ end
90
+ ```
91
+
92
+ **Available commands with a Jsfile**
93
+
94
+ ``` bash
95
+ rake bower:dsl:install #install js components
96
+ rake bower:dsl:update #update js components
97
+ ```
98
+
99
+
100
+
101
+
102
+
@@ -1,3 +1,4 @@
1
1
  module BowerRails
2
2
  require 'bower-rails/railtie' if defined?(Rails)
3
+ require "bower-rails/dsl"
3
4
  end
@@ -0,0 +1,94 @@
1
+ require "json"
2
+ require 'fileutils'
3
+
4
+ module BowerRails
5
+ class Dsl
6
+
7
+ def self.config=(conf)
8
+ @config = conf
9
+ end
10
+
11
+ def self.config
12
+ @config
13
+ end
14
+
15
+ def self.evalute(file)
16
+ inst = new
17
+ inst.eval_file(file)
18
+ inst
19
+ end
20
+
21
+ def initialize
22
+ @dependencies = {}
23
+ @groups = []
24
+ @root_path = BowerRails::Dsl.config[:root_path] || File.expand_path("./")
25
+ @assets_path = BowerRails::Dsl.config[:assets_path] || "/assets/javascripts"
26
+ end
27
+
28
+ def eval_file(file)
29
+ contents = File.open(file,"r").read
30
+ instance_eval(contents, file.to_s, 1)
31
+ end
32
+
33
+ def directories
34
+ @dependencies.keys
35
+ end
36
+
37
+ def dependencies
38
+ @dependencies
39
+ end
40
+
41
+ def group(*args, &blk)
42
+ @groups.concat [args]
43
+ yield
44
+ ensure
45
+ args.each { @groups.pop }
46
+ end
47
+
48
+ def js(name, *args)
49
+ options = Hash === args.last ? args.pop : {}
50
+ version = args.first || "latest"
51
+
52
+ @groups = ["lib"] if @groups.empty?
53
+
54
+ @groups.each do |g|
55
+ g_options = Hash === g.last ? g.pop : {}
56
+ assets_path = g_options[:assets_path] || @assets_path
57
+
58
+ g_norm = normalize_location_path(g.first,assets_path)
59
+ @dependencies[g_norm] ||= {}
60
+ @dependencies[g_norm][name] = version
61
+ end
62
+ end
63
+
64
+ def to_json(location)
65
+ dependencies_to_json @dependencies[normalize_location_path(location)]
66
+ end
67
+
68
+ def write_bower_json
69
+ @dependencies.each do |dir,data|
70
+ FileUtils.mkdir_p dir unless File.directory? dir
71
+ File.open(File.join(dir,"bower.json"),"w") do |f|
72
+ f.write(dependencies_to_json(data))
73
+ end
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def dependencies_to_json(data)
80
+ JSON.pretty_generate({
81
+ :dependencies => data
82
+ })
83
+ end
84
+
85
+ def assets_path(assets_path)
86
+ @assets_path = assets_path
87
+ end
88
+
89
+ def normalize_location_path(loc,assets_path)
90
+ File.join(@root_path,loc.to_s,assets_path)
91
+ end
92
+
93
+ end
94
+ end
@@ -4,6 +4,12 @@ module BowerRails
4
4
  class Railtie < Rails::Railtie
5
5
  railtie_name :bower
6
6
 
7
+ config.after_initialize do |app|
8
+ ["lib", "vendor"].each do |dir|
9
+ app.config.assets.paths << Rails.root.join(dir, 'assets', 'components')
10
+ end
11
+ end
12
+
7
13
  rake_tasks do
8
14
  load "tasks/bower.rake"
9
15
  end
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
  require 'pp'
3
-
4
3
  namespace :bower do
5
4
 
6
5
  desc "install files from bower"
@@ -18,6 +17,40 @@ namespace :bower do
18
17
  sh 'bower update'
19
18
  end
20
19
  end
20
+
21
+ namespace :dsl do
22
+ desc "install files from bower"
23
+ task :install do
24
+ #install to corresponding directories
25
+ dsl_perform_command do
26
+ sh 'bower install'
27
+ end
28
+ end
29
+
30
+ desc "update bower packages"
31
+ task :update do
32
+ #install to corresponding directories
33
+ dsl_perform_command false do
34
+ sh 'bower update'
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def dsl_perform_command remove_components = true
41
+ BowerRails::Dsl.config = {:root_path => Rails.root}
42
+ dsl = BowerRails::Dsl.evalute(Rails.root.join("Jsfile"))
43
+
44
+ if remove_components
45
+ dsl.write_bower_json
46
+ puts "bower.js files generated"
47
+ end
48
+
49
+ dsl.directories.each do |dir|
50
+ Dir.chdir(dir) do
51
+ yield
52
+ end
53
+ end
21
54
  end
22
55
 
23
56
  #run the passed bower block in appropriate folders
@@ -31,7 +64,7 @@ def perform_command remove_components = true
31
64
  data = json[dir]
32
65
 
33
66
  #check folder existence and create?
34
- dir = "#{Rails.root}/#{dir}/assets/javascripts"
67
+ dir = "#{Rails.root}/#{dir}/assets"
35
68
  FileUtils.mkdir_p dir unless File.directory? dir
36
69
  #go in to dir to act
37
70
  Dir.chdir(dir) do
@@ -39,16 +72,16 @@ def perform_command remove_components = true
39
72
  #remove old components
40
73
  FileUtils.rm_rf("components") if remove_components
41
74
 
42
- #create component json
43
- File.open("component.json","w") do |f|
75
+ #create bower json
76
+ File.open("bower.json","w") do |f|
44
77
  f.write(data.to_json)
45
78
  end
46
79
 
47
80
  #run command
48
81
  yield
49
82
 
50
- #remove component file
51
- FileUtils.rm("component.json")
83
+ #remove bower file
84
+ FileUtils.rm("bower.json")
52
85
 
53
86
  end if data
54
87
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bower-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ross Harrison
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
11
+ date: 2013-05-08 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Bower for Rails
15
14
  email: rtharrison86@gmail.com
@@ -17,6 +16,7 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
19
+ - lib/bower-rails/dsl.rb
20
20
  - lib/bower-rails/railtie.rb
21
21
  - lib/bower-rails.rb
22
22
  - lib/generators/bower_rails/initialize/initialize_generator.rb
@@ -26,26 +26,25 @@ files:
26
26
  - README.md
27
27
  homepage: https://github.com/rharriso/bower-rails
28
28
  licenses: []
29
+ metadata: {}
29
30
  post_install_message:
30
31
  rdoc_options: []
31
32
  require_paths:
32
33
  - lib
33
34
  required_ruby_version: !ruby/object:Gem::Requirement
34
- none: false
35
35
  requirements:
36
- - - ! '>='
36
+ - - '>='
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  required_rubygems_version: !ruby/object:Gem::Requirement
40
- none: false
41
40
  requirements:
42
- - - ! '>='
41
+ - - '>='
43
42
  - !ruby/object:Gem::Version
44
43
  version: '0'
45
44
  requirements: []
46
45
  rubyforge_project:
47
- rubygems_version: 1.8.24
46
+ rubygems_version: 2.0.3
48
47
  signing_key:
49
- specification_version: 3
48
+ specification_version: 4
50
49
  summary: Bower for Rails
51
50
  test_files: []