guard-mirror 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ guard-mirror
2
+ ============
3
+
4
+ A CoffeeScript, Stylus, and Jade (HTML and JST) Guard that mirrors your source
5
+ files (.coffee/.styl/.jade/.jst.jadet) in another location (public/www/etc...).
6
+ guard-mirror also can compress the files on the fly for use in production with
7
+ a simple `compress: true` option. Google Closure Compiler is used for JS and
8
+ YUI Compressor for CSS. Jade -> HTML files are automatically shrinkwrapped.
9
+ Sprockets is used for file requiring and concatination so all of the same
10
+ Sprockets syntax can be used.
11
+
12
+ I created this to help with PhoneGap/Cordova development and it's working out really nice!
13
+
14
+ Installation
15
+ ------------
16
+
17
+ In your `Gemfile`...
18
+
19
+ ```ruby
20
+ source :rubygems
21
+
22
+ gem 'guard-mirror'
23
+ # Optionally a notifier like Growl. Syntax/parse errors will be displayed in
24
+ # notifications which becomes very handy!
25
+ # Use the `notify: false` option to turn this off
26
+ # gem 'growl'
27
+ ```
28
+
29
+ If you want to use nib, you'll have to have the module installed. I recommend adding a `package.json` file to your root directory with something like...
30
+
31
+ ```json
32
+ {
33
+ "name": "app-name",
34
+ "version": "0.0.1",
35
+ "author": "Your Name <you@example.com>",
36
+ "dependencies": [
37
+ "coffee-script",
38
+ "stylus",
39
+ "nib",
40
+ "jade"
41
+ ]
42
+ }
43
+ ```
44
+
45
+ And then running...
46
+
47
+ ```bash
48
+ cd to/your/root
49
+ npm install
50
+ ```
51
+
52
+ Configuration
53
+ -------------
54
+
55
+ In your `Guardfile`...
56
+
57
+ ```ruby
58
+ guard :mirror,
59
+ paths: ['src/js/templates', 'src/js'],
60
+ # If a target is specified, only this file will be compiled when any
61
+ # watched file changes.
62
+ target: 'app.coffee',
63
+ dest: 'www',
64
+ compress: true do
65
+ watch %r{^src/js/(.+\..+)}
66
+ end
67
+
68
+ guard :mirror,
69
+ paths: ['src/css'],
70
+ target: 'app.styl',
71
+ dest: 'www',
72
+ # nib is supported with this flag
73
+ nib: true,
74
+ compress: true do
75
+ watch %r{^src/css/(.+\..+)}
76
+ end
77
+
78
+ guard :mirror,
79
+ paths: ['src/html'],
80
+ dest: 'www' do
81
+ watch(%r{^src/html/(.+\..+)}) { |m| m[1] }
82
+ end
83
+ ```
84
+
85
+ Running It
86
+ ----------
87
+
88
+ ```bash
89
+ bundle update
90
+ bundle --binstubs
91
+ bin/guard
92
+ ```
93
+
94
+ Profit!
@@ -0,0 +1,7 @@
1
+ module ::Jade
2
+ class HtmlCompiler < Compiler
3
+ def compile(template)
4
+ context.eval("jade.compile(#{template.to_json}, #{@options.to_json})()")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module ::Jade
2
+ class Template
3
+
4
+ private
5
+
6
+ def compile_function
7
+ if file.end_with? '.html.jade'
8
+ Template.default_mime_type = 'text/html'
9
+ compiler = HtmlCompiler
10
+ else
11
+ Template.default_mime_type = 'application/javascript'
12
+ compiler = Compiler
13
+ end
14
+
15
+ compiler.new(client: false, filename: file).compile data
16
+ end
17
+ end
18
+ end
data/lib/guard/mirror.rb CHANGED
@@ -3,8 +3,8 @@ require 'guard/guard'
3
3
  require 'sprockets'
4
4
  require 'coffee_script'
5
5
  require 'jade'
6
- require "#{File.dirname __FILE__}/../jade/html_compiler.rb"
7
- require "#{File.dirname __FILE__}/../jade/html_template.rb"
6
+ require_relative 'mirror/jade/html_compiler'
7
+ require_relative 'mirror/jade/template'
8
8
  require 'stylus'
9
9
  require 'closure-compiler'
10
10
  require 'yui/compressor'
@@ -16,15 +16,25 @@ module ::Guard
16
16
  super
17
17
 
18
18
  @options = {
19
- compress: false
19
+ notify: true
20
20
  }.merge options
21
21
 
22
22
  @env = ::Sprockets::Environment.new
23
+
24
+ # CoffeeScript is baked into sprockets so we can skip that, but register
25
+ # these other guys.
23
26
  @env.register_mime_type 'text/html', '.html'
24
- @env.register_engine '.jade', ::Jade::HtmlTemplate
25
- @env.register_engine '.jadet', ::Jade::Template
27
+
28
+ # The problem (awesomeness) with Jade is that it can export HTML or an
29
+ # anonymous function for use as a JST. Use `.html.jade` for HTML and
30
+ # `.jst.jade` for a jade template.
31
+ @env.register_engine '.jade', ::Jade::Template
32
+
26
33
  @env.register_engine '.styl', ::Tilt::StylusTemplate
27
34
 
35
+ # Turn on nib on demand
36
+ Stylus.use :nib if @options[:nib]
37
+
28
38
  @options[:paths].each { |path| @env.append_path path }
29
39
 
30
40
  if @options[:compress]
@@ -57,20 +67,24 @@ module ::Guard
57
67
  (@options[:target] ? [@options[:target]] : paths).each do |path|
58
68
  dest = src_to_dest path
59
69
  dirname = File.dirname dest
60
- UI.info "Mirroring #{path}..."
70
+ UI.info "IN -> #{path}..."
61
71
  FileUtils.mkdir_p dirname unless File.directory? dirname
62
72
  File.open(dest, 'w') do |f|
63
73
  f.write(
64
74
  begin
65
75
  @env[path]
66
76
  rescue => e
67
- Notifier.notify e.message, title: 'guard-mirror', image: :failed
77
+ if @options[:nofify]
78
+ Notifier.notify e.message,
79
+ title: 'guard-mirror',
80
+ image: :failed
81
+ end
68
82
  UI.error e.message
69
83
  e.message
70
84
  end
71
85
  )
72
86
  end
73
- UI.info "Saved to #{dest}."
87
+ UI.info "OUT -> #{dest}"
74
88
  end
75
89
  end
76
90
 
@@ -78,9 +92,9 @@ module ::Guard
78
92
 
79
93
  def src_to_dest path
80
94
  path = path
81
- .sub(/\.coffee|\.jst\.jadet/, '.js')
95
+ .sub(/\.coffee|\.jst\.jade/, '.js')
82
96
  .sub(/\.styl/, '.css')
83
- .sub /\.jade/, '.html'
97
+ .sub /\.html\.jade/, '.html'
84
98
  File.expand_path "#{@options[:dest]}/#{path}"
85
99
  end
86
100
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-mirror
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -146,9 +146,10 @@ executables: []
146
146
  extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
+ - README.md
150
+ - lib/guard/mirror/jade/html_compiler.rb
151
+ - lib/guard/mirror/jade/template.rb
149
152
  - lib/guard/mirror.rb
150
- - lib/jade/html_compiler.rb
151
- - lib/jade/html_template.rb
152
153
  homepage: https://github.com/caseywebdev/guard-mirror
153
154
  licenses: []
154
155
  post_install_message:
@@ -1,8 +0,0 @@
1
- module ::Jade
2
- class HtmlCompiler < Compiler
3
- def compile(template)
4
- template = template.read if template.respond_to?(:read)
5
- template = context.eval("jade.compile(#{template.to_json}, #{@options.to_json})()")
6
- end
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- module ::Jade
2
- class HtmlTemplate < Template
3
- self.default_mime_type = 'text/html'
4
-
5
- private
6
-
7
- def compile_function
8
- Jade::HtmlCompiler.new(client: false, filename: file).compile data
9
- end
10
- end
11
- end