guard-mirror 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'sprockets'
4
+ require 'coffee_script'
5
+ require 'jade'
6
+ require "#{File.dirname __FILE__}/../jade/html_compiler.rb"
7
+ require "#{File.dirname __FILE__}/../jade/html_template.rb"
8
+ require 'stylus'
9
+ require 'closure-compiler'
10
+ require 'yui/compressor'
11
+
12
+ module ::Guard
13
+ class Mirror < Guard
14
+
15
+ def initialize watchers = [], options = {}
16
+ super
17
+
18
+ @options = {
19
+ compress: false
20
+ }.merge options
21
+
22
+ @env = ::Sprockets::Environment.new
23
+ @env.register_mime_type 'text/html', '.html'
24
+ @env.register_engine '.jade', ::Jade::HtmlTemplate
25
+ @env.register_engine '.jadet', ::Jade::Template
26
+ @env.register_engine '.styl', ::Tilt::StylusTemplate
27
+
28
+ @options[:paths].each { |path| @env.append_path path }
29
+
30
+ if @options[:compress]
31
+ @env.js_compressor = ::Closure::Compiler.new
32
+ @env.css_compressor = ::YUI::CssCompressor.new
33
+ end
34
+
35
+ end
36
+
37
+ def start
38
+ UI.info "A mirror has started."
39
+ run_all
40
+ end
41
+
42
+ def run_all
43
+ UI.info "Mirroring all files..."
44
+ run_on_changes(
45
+ @options[:target] ?
46
+ [@options[:target]] :
47
+ Dir[File.join @env.paths.first, '**{,/*/**}.*'].map do |path|
48
+ path[@env.paths.first.length + 1 .. -1]
49
+ end
50
+ )
51
+ end
52
+
53
+ def run_on_changes paths
54
+ (@options[:target] ? [@options[:target]] : paths).each do |src|
55
+ dest = src_to_dest src
56
+ dirname = File.dirname dest
57
+ UI.info "Mirroring #{src} -> #{dest}"
58
+ FileUtils.mkdir_p dirname unless File.directory? dirname
59
+ File.open(dest, 'w') do |f|
60
+ f.write(
61
+ begin
62
+ @env[src]
63
+ rescue ExecJS::ProgramError => e
64
+ e
65
+ rescue ExecJS::RuntimeError => e
66
+ e
67
+ end)
68
+ end
69
+ end
70
+ UI.info 'Done.'
71
+ end
72
+
73
+ private
74
+
75
+ def src_to_dest path
76
+ path = path
77
+ .sub(/\.coffee|\.jst\.jadet/, '.js')
78
+ .sub(/\.styl/, '.css')
79
+ .sub /\.jade/, '.html'
80
+ File.expand_path "#{@options[:dest]}/#{path}"
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,11 @@
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
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-mirror
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Casey Foster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sprockets
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: coffee-script
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jade
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: stylus
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: closure-compiler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: yui-compressor
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: json
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: ! " A CoffeeScript, Stylus, and Jade (HTML and JST) Guard that mirrors\n
143
+ \ yoursource files (.coffee/.styl/.jade/.jst.jadet) in another location\n (public/www/etc...).\n"
144
+ email: nick@quaran.to
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - lib/guard/mirror.rb
150
+ - lib/jade/html_compiler.rb
151
+ - lib/jade/html_template.rb
152
+ homepage: https://github.com/caseywebdev/guard-mirror
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: 1.9.3
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Mirror .coffee, .styl, and .jade as .js, .css, and .html
176
+ test_files: []