rails-lineman 0.0.3 → 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: f5f398811b6de1d755c12fdafa6d7a5df86da3a7
4
- data.tar.gz: 6bf56a4a977f8eb8b98abdbb8b3c1141f8d67f26
3
+ metadata.gz: 3e51d44ae72c3978d9f1b45af7a4be41546f0225
4
+ data.tar.gz: 976b6968970fa1559e77e59885e2276bd6f09ea4
5
5
  SHA512:
6
- metadata.gz: 41ccbd2499bbe3b752ff5b0e9834b658b7e2153c8c013c75ac3430a96c1f611b73985ebcfe5b3e3abb633898db9b1ab825bdad157e3a349651404700ed1e6b16
7
- data.tar.gz: 57e4dcd0be904bec205f9ca2dffa40ba132a0481a9c58102f227aecc15c277b67d417661b1c1aff7e5218e27ffd1f1377356c4d805285ed12d7cce72aab5df28
6
+ metadata.gz: 019e1789c5c48353b8bed1248a2f267638c200069e31c49aeb4d566f0eaf46aeab872655661200a53b7f77003abaa38e5dcde188c775c7282a66cd6cb461555a
7
+ data.tar.gz: 14669cc62d098d55dc16c0a57cee8cfcc9e2cd0897a76889d46cddcf9eef77910100c5c1a718ac4e680a22453aae9e1d65dfcb32e7544ab4ff8bd4c7c42053d0
data/README.md CHANGED
@@ -7,6 +7,8 @@ Wraps the `assets:precompile` rake task by building a specified lineman project.
7
7
 
8
8
  All you need to set is a config property `Rails.application.config.rails_lineman.lineman_project_location` or environment variable $LINEMAN_PROJECT_LOCATION.
9
9
 
10
+ You may specify exactly what dist directories you want included through `Rails.application.config.rails_lineman.lineman_assets` or environment variable $LINEMAN_ASSETS. Javascript and CSS are preprocessed, while any other folders- for example, img, are simply included in assets untouched. Multiple folders are expressed as an array of Strings or Symbols.
11
+
10
12
  From your templates you'll be able to require lineman-built JS & CSS like so:
11
13
 
12
14
  ``` erb
@@ -2,17 +2,62 @@ require 'pathname'
2
2
  require 'fileutils'
3
3
 
4
4
  module RailsLineman
5
+
6
+ class Asset
7
+ def initialize(config, descriptor)
8
+ @descriptor = descriptor.strip
9
+ @source = File.join(config.lineman_project_location, "dist", descriptor, ".")
10
+ @destination = destination
11
+ end
12
+
13
+ def destination
14
+ if is_precompilable?
15
+ Rails.root.join(File.join("tmp", "rails_lineman", "lineman"))
16
+ else
17
+ Rails.root.join(File.join("public", "assets", @descriptor))
18
+ end
19
+ end
20
+
21
+ def ensure_directories
22
+ [@source, @destination].each do |path|
23
+ FileUtils.mkdir_p(path)
24
+ end
25
+ end
26
+
27
+ def copy
28
+ FileUtils.cp_r(@source, @destination)
29
+ end
30
+
31
+ def add_if_precompilable
32
+ if(is_precompilable?)
33
+ Rails.application.config.assets.precompile +=
34
+ Dir.glob("#{@destination}/**/*.#{@descriptor}")
35
+ end
36
+ end
37
+
38
+ def is_precompilable?
39
+ ["js", "css"].member? @descriptor
40
+ end
41
+
42
+ def delete
43
+ FileUtils.rm_rf(@destination)
44
+ end
45
+ end
46
+
5
47
  class LinemanDoer
6
48
  def initialize(config)
49
+ gather_assets(config)
7
50
  @lineman_project_location = config.lineman_project_location
8
- @javascripts_source = File.join(@lineman_project_location, "dist", "js", ".")
9
- @javascripts_destination = Rails.root.join(config.javascripts_destination)
10
- @stylesheets_source = File.join(@lineman_project_location, "dist", "css", ".")
11
- @stylesheets_destination = Rails.root.join(config.stylesheets_destination)
12
51
  @tmp_dir = Rails.root.join(config.tmp_dir)
13
52
  @remove_lineman_assets_after_asset_pipeline_precompilation = config.remove_lineman_assets_after_asset_pipeline_precompilation
14
53
  end
15
54
 
55
+ def gather_assets(config)
56
+ @assets = config.lineman_assets.collect do |d|
57
+ Asset.new(config, d.to_s)
58
+ end
59
+ end
60
+
16
61
  def build
17
62
  absolutify_lineman_path
18
63
  chdir @lineman_project_location do
@@ -22,16 +67,13 @@ module RailsLineman
22
67
  delete_node_js_from_heroku
23
68
  end
24
69
  ensure_directories_exist
25
- copy_javascripts
26
- add_javascripts_to_precompile_list
27
- copy_stylesheets
28
- add_stylesheets_to_precompile_list
70
+ copy
71
+ add_to_precompile_list
29
72
  end
30
73
 
31
74
  def destroy
32
75
  return unless @remove_lineman_assets_after_asset_pipeline_precompilation
33
- delete_javascripts
34
- delete_stylesheets
76
+ delete
35
77
  delete_tmp_dir
36
78
  end
37
79
 
@@ -112,33 +154,19 @@ module RailsLineman
112
154
  end
113
155
 
114
156
  def ensure_directories_exist
115
- ([@javascripts_source, @javascripts_destination, @stylesheets_source, @stylesheets_destination]).each do |path|
116
- FileUtils.mkdir_p(path)
117
- end
118
- end
119
-
120
- def copy_javascripts
121
- FileUtils.cp_r(@javascripts_source, @javascripts_destination)
122
- end
123
-
124
- def add_javascripts_to_precompile_list
125
- Rails.application.config.assets.precompile += Dir.glob("#{@javascripts_destination}/**/*.js")
126
- end
127
-
128
- def copy_stylesheets
129
- FileUtils.cp_r(@stylesheets_source, @stylesheets_destination)
157
+ @assets.map(&:ensure_directories)
130
158
  end
131
159
 
132
- def add_stylesheets_to_precompile_list
133
- Rails.application.config.assets.precompile += Dir.glob("#{@stylesheets_destination}/**/*.css")
160
+ def copy
161
+ @assets.map(&:copy)
134
162
  end
135
163
 
136
- def delete_javascripts
137
- FileUtils.rm_rf(@javascripts_destination)
164
+ def add_to_precompile_list
165
+ @assets.map(&:add_if_precompilable)
138
166
  end
139
167
 
140
- def delete_stylesheets
141
- FileUtils.rm_rf(@stylesheets_destination)
168
+ def delete
169
+ @assets.map(&:delete)
142
170
  end
143
171
 
144
172
  def delete_tmp_dir
@@ -3,9 +3,8 @@ module RailsLineman
3
3
  config.rails_lineman = ActiveSupport::OrderedOptions.new
4
4
 
5
5
  config.rails_lineman.lineman_project_location = ENV['LINEMAN_PROJECT_LOCATION']
6
- config.rails_lineman.javascripts_destination = File.join("tmp", "rails_lineman", "lineman")
7
- config.rails_lineman.stylesheets_destination = File.join("tmp", "rails_lineman", "lineman")
8
- config.rails_lineman.remove_lineman_assets_after_asset_pipeline_precompilation = true
6
+ config.rails_lineman.lineman_assets = ENV['LINEMAN_ASSETS'] || [:js, :css]
7
+ config.rails_lineman.remove_lineman_assets_after_asset_pipeline_precompilation = false
9
8
 
10
9
  config.rails_lineman.tmp_dir = File.join("tmp", "rails_lineman")
11
10
  config.rails_lineman.asset_paths = [ config.rails_lineman.tmp_dir ]
@@ -1,3 +1,3 @@
1
1
  module RailsLineman
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-lineman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-23 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake