front_end_tasks 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -0
- data/lib/front_end_tasks/cli.rb +1 -0
- data/lib/front_end_tasks/documents/html_document.rb +12 -3
- data/lib/front_end_tasks/server.rb +1 -0
- data/lib/front_end_tasks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06d3aff4225bea249054d163b33821180ececb3
|
4
|
+
data.tar.gz: 2dfdb555c52124b0e13241fe76fd73ad92fe9891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c78571a36ab37144b6e18656f9ff013cec6c53e6e1c890128e43ea7d02a633c44988a634d3947910fe91f4a93064688b436ad98eaaeac91ccca8cc61fcc99dd
|
7
|
+
data.tar.gz: 8f13b0ce944507e5d7aaa8f2d4add250cda42c787ca9cd041d6f59bfedd437f4bbb6315d658290848e1109b386bb6079209217745cd66eb7f68ef171114fc092
|
data/README.md
CHANGED
@@ -129,6 +129,76 @@ The above becomes
|
|
129
129
|
|
130
130
|
Note: Only link tags that reference local urls are allowed between build:style and /build html comments.
|
131
131
|
|
132
|
+
## HTML Script Target Attributes
|
133
|
+
|
134
|
+
The build command accepts a `src_targets` option. It is useful for including certain versions of a script. For example, Ember.js comes with a development version with debugging tools and a lighter weight production version. We can include Ember into our HTML like this:
|
135
|
+
|
136
|
+
```html
|
137
|
+
<script src="ember.js"
|
138
|
+
build-production-src="ember.prod.js"></script>
|
139
|
+
```
|
140
|
+
|
141
|
+
By default, we use the `ember.js` development version by specifying it with the `src` attribute. To build for production we can pass the `src_targets` option to the build command
|
142
|
+
|
143
|
+
```bash
|
144
|
+
$ fe build path/to/public_dir path/to/public_dir/index.html --src_targets=production
|
145
|
+
```
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
FrontEndTasks.build('path/to/public_dir', './build', ['path/to/public_dir/index.html'], :src_targets => ['production'])
|
149
|
+
```
|
150
|
+
|
151
|
+
It is possible to specify multiple `src_targets`.
|
152
|
+
|
153
|
+
### Target specific script
|
154
|
+
|
155
|
+
The `src` attribute may be omitted if it is only relevant for a target. This is useful for including a script for a test target only.
|
156
|
+
|
157
|
+
```html
|
158
|
+
<script build-test-src="tests/app_tests.js"></script>
|
159
|
+
```
|
160
|
+
|
161
|
+
The above script is not included in development (since the `src` is not specified), but it can be included when running the build command with `test` included in `src_targets`.
|
162
|
+
|
163
|
+
### Full example
|
164
|
+
|
165
|
+
```html
|
166
|
+
<script src="ember.js"
|
167
|
+
build-production-src="ember.prod.js"></script>
|
168
|
+
<script src="config/development.js"
|
169
|
+
build-bitcoin-mainnet-src="config/bitcoin_mainnet.js"
|
170
|
+
build-bitcoin-testnet-src="config/bitcoin_testnet.js"></script>
|
171
|
+
<script build-test-src="tests/app_tests.js"></script>
|
172
|
+
```
|
173
|
+
|
174
|
+
The following combination of `src_targets` will include the specified scripts.
|
175
|
+
|
176
|
+
#### No src_targets
|
177
|
+
|
178
|
+
* ember.js
|
179
|
+
* config/development.js
|
180
|
+
|
181
|
+
#### src_targets=production
|
182
|
+
|
183
|
+
* ember.prod.js
|
184
|
+
* config/development.js
|
185
|
+
|
186
|
+
#### src_targets=production bitcoin-mainnet
|
187
|
+
|
188
|
+
* ember.prod.js
|
189
|
+
* config/bitcoin_mainnet.js
|
190
|
+
|
191
|
+
#### src_targets=bitcoin-testnet
|
192
|
+
|
193
|
+
* ember.js
|
194
|
+
* config/bitcoin_testnet.js
|
195
|
+
|
196
|
+
#### src_targets=test
|
197
|
+
|
198
|
+
* ember.js
|
199
|
+
* config/development.js
|
200
|
+
* tests/app_tests.js
|
201
|
+
|
132
202
|
## External References
|
133
203
|
|
134
204
|
The build command will find any references to other files in the project and include them in the resulting build.
|
data/lib/front_end_tasks/cli.rb
CHANGED
@@ -8,6 +8,7 @@ module FrontEndTasks
|
|
8
8
|
desc "build", "Builds the given files according to special build comments"
|
9
9
|
method_option :js_concat_only, :type => :boolean
|
10
10
|
method_option :result, :default => File.expand_path('./build')
|
11
|
+
method_option :src_targets, :type => :array
|
11
12
|
def build(public_dir, *files)
|
12
13
|
FrontEndTasks.build(public_dir, options[:result], files, options)
|
13
14
|
end
|
@@ -14,8 +14,9 @@ module FrontEndTasks
|
|
14
14
|
|
15
15
|
def compile(opts = {})
|
16
16
|
path_content_pairs = {}
|
17
|
+
src_targets = opts[:src_targets] || []
|
17
18
|
|
18
|
-
script_groups.each do |group|
|
19
|
+
script_groups(src_targets).each do |group|
|
19
20
|
combined_content = group[:files].inject('') { |content, file| content << File.read(file) }
|
20
21
|
combined_file_path = group[:combined_file_path]
|
21
22
|
js_document = JsDocument.new(@public_root, combined_content)
|
@@ -80,10 +81,18 @@ module FrontEndTasks
|
|
80
81
|
|
81
82
|
protected
|
82
83
|
|
83
|
-
def script_groups
|
84
|
+
def script_groups(src_targets)
|
85
|
+
src_target_attributes = src_targets.map { |t| "build-#{t}-src" }
|
84
86
|
groups = groups_matching_opening_comment(/\s?build:script (\S+)\s?$/, :tag_name => 'script')
|
85
87
|
groups.each do |group|
|
86
|
-
group[:files] = group[:elements].map
|
88
|
+
group[:files] = group[:elements].map do |element|
|
89
|
+
src = src_target_attributes.detect { |attribute| element.attribute(attribute) } || 'src'
|
90
|
+
if element[src]
|
91
|
+
File.join(@public_root, element[src])
|
92
|
+
else
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
end.compact
|
87
96
|
group[:combined_file_path] = group[:args][0]
|
88
97
|
end
|
89
98
|
groups
|
@@ -5,6 +5,7 @@ module FrontEndTasks
|
|
5
5
|
include WEBrick
|
6
6
|
|
7
7
|
def self.start(opts)
|
8
|
+
HTTPUtils::DefaultMimeTypes.store('manifest', 'text/cache-manifest')
|
8
9
|
server = HTTPServer.new(:Port => opts[:port], :DocumentRoot => opts[:public_dir])
|
9
10
|
trap("INT") { server.shutdown }
|
10
11
|
server.start
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: front_end_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Enriquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|