guard-haml-coffee 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/lib/guard/haml-coffee.rb +45 -30
- data/lib/guard/haml-coffee/version.rb +1 -1
- data/spec/guard/haml-coffee_spec.rb +50 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d6697a599e04e7f9eead77b24bc06978cfd2da1
|
4
|
+
data.tar.gz: d1a48068586bc2d3c675ca483ac1c232367ab5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fa2b1c70ecd84c2a944bfd6df5e877a7880b688eaf7244f1bc6145f3917c3f58cc96ffc6a2f33528e0832a9de1957ec1e8e0d73abb5be4505e6c9bb6ed2ed19
|
7
|
+
data.tar.gz: 81b51bfff2e9a9978f07622146a9d3a2c51f9d29bf1cad0724d49d406b3bb151d803d23fd90c02936003549b66d7e66e332fc196361a112e1149985dc4d2703c
|
data/.travis.yml
ADDED
data/lib/guard/haml-coffee.rb
CHANGED
@@ -26,10 +26,7 @@ module Guard
|
|
26
26
|
|
27
27
|
def start
|
28
28
|
Compat::UI.info('Guard::HamlCoffee has started watching your files', {})
|
29
|
-
|
30
|
-
source += load_config('../haml-coffee/hamlcoffee.js') + ';'
|
31
|
-
source += load_config('../haml-coffee/hamlcoffee_compiler.js')
|
32
|
-
@runtime = ExecJS.compile(source)
|
29
|
+
prepare
|
33
30
|
end
|
34
31
|
|
35
32
|
# Get the file path to output the html based on the file being
|
@@ -79,40 +76,58 @@ module Guard
|
|
79
76
|
basename = File.basename(path, '.js.hamlc')
|
80
77
|
output_file = get_output(path)
|
81
78
|
FileUtils.mkdir_p File.dirname(output_file)
|
82
|
-
|
83
|
-
basename,
|
84
|
-
File.read(path),
|
85
|
-
jst = true,
|
86
|
-
namespace = nil,
|
87
|
-
format = nil,
|
88
|
-
uglify = false,
|
89
|
-
basename,
|
90
|
-
escapeHtml = nil,
|
91
|
-
escapeAttributes = nil,
|
92
|
-
cleanValue = nil,
|
93
|
-
customHtmlEscape = nil,
|
94
|
-
customCleanValue = nil,
|
95
|
-
customPreserve = nil,
|
96
|
-
customFindAndPreserve = nil,
|
97
|
-
customSurround = nil,
|
98
|
-
customSucceed = nil,
|
99
|
-
customPrecede = nil,
|
100
|
-
preserveTags = nil,
|
101
|
-
selfCloseTags = nil,
|
102
|
-
context = false,
|
103
|
-
extendScope = nil,
|
104
|
-
]
|
105
|
-
output = @runtime.call('HamlCoffeeCompiler.compile', *options)
|
79
|
+
output = compile(basename, File.read(path))
|
106
80
|
File.open(output_file, "w") { |f| f.write output }
|
107
|
-
::
|
81
|
+
Compat::UI.info "# compiled haml coffee in '#{path}' to js in '#{output_file}'"
|
108
82
|
end
|
109
83
|
rescue StandardError => error
|
110
|
-
::
|
84
|
+
Compat::UI.error "Guard Haml Coffee Error: " + error.message
|
111
85
|
throw :task_has_failed
|
112
86
|
end
|
113
87
|
|
114
88
|
def load_config(file)
|
115
89
|
File.read(File.expand_path(file, __FILE__))
|
116
90
|
end
|
91
|
+
|
92
|
+
def prepare
|
93
|
+
runtime
|
94
|
+
end
|
95
|
+
|
96
|
+
def runtime
|
97
|
+
@runtime ||=
|
98
|
+
begin
|
99
|
+
source = File.read(::CoffeeScript::Source.path) + ';'
|
100
|
+
source += load_config('../haml-coffee/hamlcoffee.js') + ';'
|
101
|
+
source += load_config('../haml-coffee/hamlcoffee_compiler.js')
|
102
|
+
ExecJS.compile(source)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def compile(basename, code)
|
107
|
+
options = [
|
108
|
+
basename,
|
109
|
+
code,
|
110
|
+
true, # jst
|
111
|
+
nil, # namespace
|
112
|
+
nil, # format
|
113
|
+
false, # uglify
|
114
|
+
basename,
|
115
|
+
nil, # escapeHtml
|
116
|
+
nil, # escapeAttributes
|
117
|
+
nil, # cleanValue
|
118
|
+
nil, # customHtmlEscape
|
119
|
+
nil, # customCleanValue
|
120
|
+
nil, # customPreserve
|
121
|
+
nil, # customFindAndPreserve
|
122
|
+
nil, # customSurround
|
123
|
+
nil, # customSucceed
|
124
|
+
nil, # customPrecede
|
125
|
+
nil, # preserveTags
|
126
|
+
nil, # selfCloseTags
|
127
|
+
false, # context
|
128
|
+
nil, # extendScope
|
129
|
+
]
|
130
|
+
runtime.call('HamlCoffeeCompiler.compile', *options)
|
131
|
+
end
|
117
132
|
end
|
118
133
|
end
|
@@ -6,6 +6,8 @@ RSpec.describe Guard::HamlCoffee do
|
|
6
6
|
|
7
7
|
let(:options) { {} }
|
8
8
|
|
9
|
+
let(:runtime) { double(:execjs_runtime) }
|
10
|
+
|
9
11
|
before do
|
10
12
|
allow(Guard::Compat::UI).to receive(:info)
|
11
13
|
allow(File).to receive(:expand_path) do |*args|
|
@@ -17,6 +19,18 @@ RSpec.describe Guard::HamlCoffee do
|
|
17
19
|
msg = 'unstubbed call to IO.read(%s)'
|
18
20
|
fail msg % args.map(&:inspect).join(',')
|
19
21
|
end
|
22
|
+
|
23
|
+
# prepare method expecations
|
24
|
+
allow(File).to receive(:expand_path).with('../coffee-script.js', anything).and_return('foo.js')
|
25
|
+
allow(IO).to receive(:read).with('foo.js').and_return('foo')
|
26
|
+
|
27
|
+
allow(File).to receive(:expand_path).with('../haml-coffee/hamlcoffee.js', anything).and_return('bar.js')
|
28
|
+
allow(IO).to receive(:read).with('bar.js').and_return('bar')
|
29
|
+
|
30
|
+
allow(File).to receive(:expand_path).with('../haml-coffee/hamlcoffee_compiler.js', anything).and_return('baz.js')
|
31
|
+
allow(IO).to receive(:read).with('baz.js').and_return('baz')
|
32
|
+
|
33
|
+
allow(ExecJS).to receive(:compile).with('foo;bar;baz').and_return(runtime)
|
20
34
|
end
|
21
35
|
|
22
36
|
describe '#initialize' do
|
@@ -101,10 +115,46 @@ RSpec.describe Guard::HamlCoffee do
|
|
101
115
|
describe '#run_on_changes' do
|
102
116
|
context 'with changes' do
|
103
117
|
let(:files) { %w(foo bar) }
|
118
|
+
|
104
119
|
it 'compiles' do
|
105
120
|
expect(subject).to receive(:process).with(files)
|
106
121
|
subject.run_on_changes(files)
|
107
122
|
end
|
123
|
+
|
124
|
+
context "when compiling fails" do
|
125
|
+
before do
|
126
|
+
allow(Guard::Compat::UI).to receive(:error)
|
127
|
+
allow(subject).to receive(:throw).with(:task_has_failed)
|
128
|
+
allow(IO).to receive(:read).with('foo').and_return('foo data')
|
129
|
+
allow(runtime).to receive(:call).and_raise(Errno::ENOENT, 'foobar')
|
130
|
+
end
|
131
|
+
|
132
|
+
it "shows an error" do
|
133
|
+
expect(Guard::Compat::UI).to receive(:error)
|
134
|
+
.with("Guard Haml Coffee Error: No such file or directory - foobar")
|
135
|
+
subject.run_on_changes(files)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "throws :task_failed" do
|
139
|
+
expect(subject).to receive(:throw).with(:task_has_failed)
|
140
|
+
subject.run_on_changes(files)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when run outside Guard (without start called)' do
|
146
|
+
let(:files) { %w(foo.js.hamlc) }
|
147
|
+
let(:output) { 'js output' }
|
148
|
+
|
149
|
+
before do
|
150
|
+
allow(IO).to receive(:read).with('foo.js.hamlc').and_return('foo')
|
151
|
+
|
152
|
+
allow(runtime).to receive(:call).and_return(output)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'works' do
|
156
|
+
subject.run_on_changes(files)
|
157
|
+
end
|
108
158
|
end
|
109
159
|
end
|
110
160
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-haml-coffee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ouvrages
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".rubocop.yml"
|
79
79
|
- ".rubocop_todo.yml"
|
80
|
+
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- Guardfile
|
82
83
|
- LICENSE
|