front_end_tasks 0.2.0 → 0.3.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: 6bad1318a3369819d8d18c5bfdd2c168f69f52f8
4
- data.tar.gz: bfb46e0de47371ca9666afbb40bcd7932902d14d
3
+ metadata.gz: 94d3d5d02a661a985ad05031f76398c546a5a69f
4
+ data.tar.gz: 0a1ed23f81f1fa0ea2ed8fc504164c05eb8d53ce
5
5
  SHA512:
6
- metadata.gz: d52c00a167cc3dd1093723c989c42eee1c0c659af2ee8f4465f83849a0d9d260f7afbf25c482a2415fdfc00f916feaedabd5d519710876ffbdcf72a8403ca548
7
- data.tar.gz: 3585b64745c33ff5cddaa32080a1d8adfeac70f579db9d3e0acc7299ce020ebed23aec98ec90c7b1946067f3e3e01e011f6b7a6fde72f555b45867f106452c13
6
+ metadata.gz: 73b819576fc8e3ecdc3a9b140bbe93f3fe154e3097da63765c5091d3946d44072a9e8531f4a282af79d25b59fa94d6ee4ac61601fe04b0fd11126a48b477e954
7
+ data.tar.gz: c2c2b2d288e57e9516fda1779540529dfa36df7b46200fd128ef1343a3a8cb478fe740de9f7ec6fa619599ce29dcbd8fc4cc6b84df319d35db0d2f3231b59adf
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Command line tool for client side web application development. Great for develoeprs who prefer to write plain html, css, and javascript that works without any special pre-processing. This tool helps optimize, lint, and test that code.
4
4
 
5
- # Installation
5
+ ## Installation
6
6
 
7
7
  ```bash
8
8
  $ gem install front_end_tasks
@@ -10,11 +10,11 @@ $ gem install front_end_tasks
10
10
 
11
11
  The `fe` command will be available after installing Front End Tasks.
12
12
 
13
- # Usage
13
+ ## Usage
14
14
 
15
15
  Front End Tasks can be used from the command line or scripted with Ruby.
16
16
 
17
- ## build
17
+ ### build
18
18
 
19
19
  Compiles the given html file by combining and minifying javascript and stylesheet tags according to speical html comments (see HTML Comments section).
20
20
 
@@ -23,10 +23,10 @@ $ fe build path/to/public_dir path/to/public_dir/index.html
23
23
  ```
24
24
 
25
25
  ```ruby
26
- FrontEndTasks.build('path/to/public_dir', './build', 'path/to/public_dir/index.html')
26
+ FrontEndTasks.build('path/to/public_dir', './build', ['path/to/public_dir/index.html'])
27
27
  ```
28
28
 
29
- ## server
29
+ ### server
30
30
 
31
31
  Run a development server on localhost.
32
32
 
@@ -38,7 +38,7 @@ $ fe server --public_dir app/
38
38
  FrontEndTasks.server(:public_dir => './app')
39
39
  ```
40
40
 
41
- ## lint
41
+ ### lint
42
42
 
43
43
  Run the given files through JSLint.
44
44
 
@@ -50,7 +50,7 @@ $ fe lint app/js/file_to_lint.js app/js/another_file.js
50
50
  FrontEndTasks.lint('./app/js/file_to_lint.js', './app/js/another_file.js')
51
51
  ```
52
52
 
53
- ## spec
53
+ ### spec
54
54
 
55
55
  Run Jasmine specs
56
56
 
@@ -65,7 +65,7 @@ FrontEndTasks.spec({
65
65
  })
66
66
  ```
67
67
 
68
- ## gzip
68
+ ### gzip
69
69
 
70
70
  Create a compressed .gz version of the given files
71
71
 
@@ -77,7 +77,7 @@ $ fe gzip app/js/app.js app/js/home.js
77
77
  FrontEndTasks.gzip('app/js/app.js', 'app/js/home.js')
78
78
  ```
79
79
 
80
- ## list_scripts
80
+ ### list_scripts
81
81
 
82
82
  List the javascript files that are included in the html (script tags) or js (importScripts) file
83
83
 
@@ -89,9 +89,9 @@ $ fe list_scripts ./app/index.html
89
89
  FrontEndTasks.list_scripts('./app/index.html')
90
90
  ```
91
91
 
92
- # HTML Comments
92
+ ## HTML Comments
93
93
 
94
- ## build:script
94
+ ### build:script
95
95
 
96
96
  Combine and minify scripts. Takes an argument that specifies the resulting file. See the following example
97
97
 
@@ -110,7 +110,7 @@ The above combine and minify app.js and home.js together into scripts.min.js
110
110
 
111
111
  Note: Only script tags that reference local urls are allowed between build:script and /build html comments.
112
112
 
113
- ## build:style
113
+ ### build:style
114
114
 
115
115
  Similar to build:script, but for stylesheets
116
116
 
@@ -129,11 +129,11 @@ 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
- # External References
132
+ ## External References
133
133
 
134
134
  The build command will find any references to other files in the project and include them in the resulting build.
135
135
 
136
- ## Stylesheets
136
+ ### Stylesheets
137
137
 
138
138
  CSS Files may reference fonts, images, etc... by using `url(...)`.
139
139
 
@@ -157,7 +157,7 @@ The above font file will be moved into the same directory as the combined styles
157
157
 
158
158
  Note: Since all the files references from stylesheets are placed in the same directory, the filenames must be unique.
159
159
 
160
- ## Javascripts
160
+ ### Javascripts
161
161
 
162
162
  Javascript files may have references to worker scripts. For example:
163
163
 
@@ -173,7 +173,7 @@ importScripts('/js/workers/worker_helper.js')
173
173
 
174
174
  The above is replaced with the contents of the given file, then the whole worker script is minified.
175
175
 
176
- # MIT License
176
+ ## MIT License
177
177
 
178
178
  Copyright (c) 2014 Mike Enriquez (http://enriquez.me)
179
179
 
@@ -9,9 +9,9 @@ require 'front_end_tasks/documents'
9
9
 
10
10
  module FrontEndTasks
11
11
 
12
- def self.build(public_dir, build_dir, *files)
12
+ def self.build(public_dir, build_dir, files, opts = {})
13
13
  optimizer = Optimizer.new(public_dir, files)
14
- optimizer.build_to(build_dir)
14
+ optimizer.build_to(build_dir, opts)
15
15
  end
16
16
 
17
17
  def self.gzip(*files)
@@ -6,9 +6,10 @@ module FrontEndTasks
6
6
  class CLI < Thor
7
7
 
8
8
  desc "build", "Builds the given files according to special build comments"
9
+ method_option :js_concat_only, :type => :boolean
9
10
  method_option :result, :default => File.expand_path('./build')
10
11
  def build(public_dir, *files)
11
- FrontEndTasks.build(public_dir, options[:result], *files)
12
+ FrontEndTasks.build(public_dir, options[:result], files, options)
12
13
  end
13
14
 
14
15
  desc "gzip", "Creates a compressed .gz version of the given file"
@@ -5,4 +5,21 @@ require 'front_end_tasks/documents/js_document'
5
5
  require 'front_end_tasks/documents/html_document'
6
6
 
7
7
  module FrontEndTasks::Documents
8
+
9
+ def self.create(public_dir, file)
10
+ extension = File.extname(file).downcase
11
+ contents = File.read(file)
12
+
13
+ case extension
14
+ when '.html'
15
+ HtmlDocument.new(public_dir, contents)
16
+ when '.js'
17
+ JsDocument.new(public_dir, contents)
18
+ when '.css'
19
+ CssDocument.new(public_dir, contents)
20
+ else
21
+ AssetDocument.new(public_dir, contents)
22
+ end
23
+ end
24
+
8
25
  end
@@ -4,7 +4,7 @@ module FrontEndTasks
4
4
  module Documents
5
5
  class AssetDocument < BaseDocument
6
6
 
7
- def compile
7
+ def compile(opts = {})
8
8
  {
9
9
  @compiled_path => @content
10
10
  }
@@ -9,7 +9,7 @@ module FrontEndTasks
9
9
  @content = content
10
10
  end
11
11
 
12
- def compile
12
+ def compile(opts = {})
13
13
  raise NotImplementedError.new('Must override "compile" in subclass')
14
14
  end
15
15
 
@@ -6,7 +6,7 @@ module FrontEndTasks
6
6
  module Documents
7
7
  class CssDocument < BaseDocument
8
8
 
9
- def compile
9
+ def compile(opts = {})
10
10
  compressor = YUI::CssCompressor.new
11
11
  compiled_content = compressor.compress(@content)
12
12
 
@@ -12,7 +12,7 @@ module FrontEndTasks
12
12
  @doc = Nokogiri::HTML(content)
13
13
  end
14
14
 
15
- def compile
15
+ def compile(opts = {})
16
16
  path_content_pairs = {}
17
17
 
18
18
  script_groups.each do |group|
@@ -20,7 +20,7 @@ module FrontEndTasks
20
20
  combined_file_path = group[:combined_file_path]
21
21
  js_document = JsDocument.new(@public_root, combined_content)
22
22
  js_document.compiled_path = combined_file_path
23
- new_files = js_document.compile
23
+ new_files = js_document.compile(opts)
24
24
 
25
25
  script_node = Nokogiri::XML::Node.new("script", @doc)
26
26
  script_node[:src] = combined_file_path
@@ -5,7 +5,7 @@ module FrontEndTasks
5
5
  module Documents
6
6
  class JsDocument < BaseDocument
7
7
 
8
- def compile
8
+ def compile(opts = {})
9
9
  path_content_pairs = {}
10
10
 
11
11
  workers = find_worker_references(@public_root, @content)
@@ -16,10 +16,16 @@ module FrontEndTasks
16
16
 
17
17
  @content = replace_worker_import_scripts(@public_root, @content)
18
18
 
19
- compiled_content = Uglifier.compile(@content)
20
- path_content_pairs.merge!({
21
- @compiled_path => compiled_content
22
- })
19
+ if opts[:js_concat_only]
20
+ path_content_pairs.merge!({
21
+ @compiled_path => @content
22
+ })
23
+ else
24
+ compiled_content = Uglifier.compile(@content)
25
+ path_content_pairs.merge!({
26
+ @compiled_path => compiled_content
27
+ })
28
+ end
23
29
 
24
30
  path_content_pairs
25
31
  end
@@ -10,13 +10,11 @@ module FrontEndTasks
10
10
  @files = files.map { |f| File.expand_path(f) }
11
11
  end
12
12
 
13
- def build_to(result_dir)
13
+ def build_to(result_dir, opts = {})
14
14
  @files.each do |file|
15
- html_filename = File.basename(file)
16
- html_doc = Documents::HtmlDocument.new(@public_dir, File.read(file))
17
- html_doc.compiled_path = html_filename
18
-
19
- files = html_doc.compile
15
+ doc = Documents.create(@public_dir, file)
16
+ doc.compiled_path = File.basename(file)
17
+ files = doc.compile(opts)
20
18
 
21
19
  files.each_pair do |file, contents|
22
20
  save_file(File.join(result_dir, file), contents)
@@ -1,3 +1,3 @@
1
1
  module FrontEndTasks
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: front_end_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Enriquez