asset_watcher 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.md +21 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/asset_watcher.gemspec +77 -0
- data/lib/asset_watcher/filewatcher_ext.rb +20 -0
- data/lib/asset_watcher/tasks/watch.rake +21 -0
- data/lib/asset_watcher.rb +111 -0
- data/spec/asset_watcher_spec.rb +147 -0
- data/spec/spec_helper.rb +12 -0
- metadata +198 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'haml'
|
4
|
+
gem 'coffee-haml-filter'
|
5
|
+
gem 'activesupport'
|
6
|
+
gem 'filewatcher'
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.3)
|
5
|
+
coffee-haml-filter (0.4.0)
|
6
|
+
haml
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
filewatcher (0.1.1)
|
9
|
+
git (1.2.5)
|
10
|
+
haml (3.0.25)
|
11
|
+
jeweler (1.5.2)
|
12
|
+
bundler (~> 1.0.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rake (0.8.7)
|
16
|
+
rcov (0.9.9)
|
17
|
+
rspec (2.3.0)
|
18
|
+
rspec-core (~> 2.3.0)
|
19
|
+
rspec-expectations (~> 2.3.0)
|
20
|
+
rspec-mocks (~> 2.3.0)
|
21
|
+
rspec-core (2.3.1)
|
22
|
+
rspec-expectations (2.3.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.3.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
activesupport
|
31
|
+
bundler (~> 1.0.0)
|
32
|
+
coffee-haml-filter
|
33
|
+
filewatcher
|
34
|
+
haml
|
35
|
+
jeweler (~> 1.5.2)
|
36
|
+
rcov
|
37
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 yamada996
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# asset_watcher
|
2
|
+
|
3
|
+
watch and auto-compile .coffee and .haml files.
|
4
|
+
Need node.js and coffee-script to compile .coffee file and haml to compile .haml.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
Add a statement to your Rakefile.
|
8
|
+
|
9
|
+
require 'asset_watcher'
|
10
|
+
load 'asset_watcher/tasks/watch.rake'
|
11
|
+
|
12
|
+
and execute rake task.
|
13
|
+
|
14
|
+
rake asset:watch
|
15
|
+
|
16
|
+
|
17
|
+
## Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2011 yamada996. See LICENSE.txt for
|
20
|
+
further details.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "asset_watcher"
|
16
|
+
gem.homepage = "http://github.com/yamada996/asset_watcher"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{watch and auto-compile .coffee and .haml files}
|
19
|
+
gem.description = %Q{watch and auto-compile .coffee and .haml files. Need node.js and coffee-script to compile .coffee file and haml to compile .haml.}
|
20
|
+
gem.email = "t.yamada.996@gmail.com"
|
21
|
+
gem.authors = ["yamada996"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "asset_watcher #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{asset_watcher}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["yamada996"]
|
12
|
+
s.date = %q{2011-02-05}
|
13
|
+
s.description = %q{watch and auto-compile .coffee and .haml files. Need node.js and coffee-script to compile .coffee file and haml to compile .haml.}
|
14
|
+
s.email = %q{t.yamada.996@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"asset_watcher.gemspec",
|
28
|
+
"lib/asset_watcher.rb",
|
29
|
+
"lib/asset_watcher/filewatcher_ext.rb",
|
30
|
+
"lib/asset_watcher/tasks/watch.rake",
|
31
|
+
"spec/asset_watcher_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/yamada996/asset_watcher}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.4.1}
|
38
|
+
s.summary = %q{watch and auto-compile .coffee and .haml files}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/asset_watcher_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<haml>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<coffee-haml-filter>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
51
|
+
s.add_runtime_dependency(%q<filewatcher>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<haml>, [">= 0"])
|
58
|
+
s.add_dependency(%q<coffee-haml-filter>, [">= 0"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
60
|
+
s.add_dependency(%q<filewatcher>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<haml>, [">= 0"])
|
68
|
+
s.add_dependency(%q<coffee-haml-filter>, [">= 0"])
|
69
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
70
|
+
s.add_dependency(%q<filewatcher>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class FileWatcher
|
2
|
+
def file_updated?
|
3
|
+
@filenames.each do |filename|
|
4
|
+
# Wait for the file's update.
|
5
|
+
while not File.exist? filename
|
6
|
+
puts "'#{filename}' is not found!"
|
7
|
+
sleep 0.5
|
8
|
+
end
|
9
|
+
|
10
|
+
mtime = File.stat(filename).mtime
|
11
|
+
updated = @last_mtimes[filename] < mtime
|
12
|
+
@last_mtimes[filename] = mtime
|
13
|
+
if(updated)
|
14
|
+
@updated_file = filename
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'filewatcher'
|
2
|
+
require 'asset_watcher/filewatcher_ext'
|
3
|
+
require 'asset_watcher'
|
4
|
+
|
5
|
+
namespace :asset do
|
6
|
+
desc "Watch .coffee and .haml file and compile when it changes"
|
7
|
+
task :watch do
|
8
|
+
watcher = AssetWatcher.new
|
9
|
+
FileWatcher.new(watcher.target_files, "Watching files:").watch do |src_path|
|
10
|
+
watcher.compile src_path
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Compile .coffee and .haml file when it changes"
|
15
|
+
task :compile do
|
16
|
+
watcher = AssetWatcher.new
|
17
|
+
watcher.target_files.each do |src_path|
|
18
|
+
watcher.compile src_path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "haml"
|
2
|
+
require "coffee-haml-filter"
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
require "active_support/core_ext/hash/keys"
|
5
|
+
require "yaml"
|
6
|
+
require "open3"
|
7
|
+
|
8
|
+
class AssetWatcher
|
9
|
+
@@yaml_path = "config/asset_watch.yml"
|
10
|
+
|
11
|
+
@@attributes = %w|src_dir dest_dir|.map(&:to_sym).freeze
|
12
|
+
@@attributes.each do |attribute|
|
13
|
+
define_method attribute, Proc.new { @config[attribute] }
|
14
|
+
end
|
15
|
+
|
16
|
+
@@ext_map = {
|
17
|
+
'coffee' => 'js',
|
18
|
+
'haml' => 'html',
|
19
|
+
}
|
20
|
+
|
21
|
+
def exts
|
22
|
+
@@ext_map.keys
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize config = {}
|
26
|
+
current_dir = `pwd`.strip
|
27
|
+
default_config = {
|
28
|
+
:src_dir => current_dir + "/src",
|
29
|
+
:dest_dir => current_dir,
|
30
|
+
}
|
31
|
+
_config = default_config.dup
|
32
|
+
|
33
|
+
_config[:src_dir] = ARGV[1] if ARGV.count >= 2
|
34
|
+
_config[:dest_dir] = ARGV[2] if ARGV.count >= 3
|
35
|
+
|
36
|
+
# configuration file
|
37
|
+
yaml_path = current_dir + '/' + @@yaml_path
|
38
|
+
if File.exist? yaml_path
|
39
|
+
yaml_config = YAML.load_file yaml_path
|
40
|
+
yaml_config.symbolize_keys!
|
41
|
+
_config.merge! yaml_config
|
42
|
+
end
|
43
|
+
|
44
|
+
@config = _config.merge config
|
45
|
+
end
|
46
|
+
|
47
|
+
def target_files
|
48
|
+
Dir[*exts.map { |ext| "#{src_dir}/**/*\.#{ext}" }]
|
49
|
+
end
|
50
|
+
|
51
|
+
def destination full_path
|
52
|
+
if File.exist? full_path and full_path =~ /\.(#{exts.join '|'})/
|
53
|
+
ext = $1
|
54
|
+
relative_path = full_path.sub src_dir, ''
|
55
|
+
relative_path.sub! /#{ext}$/, @@ext_map[ext]
|
56
|
+
dest_dir + relative_path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def compile src_path
|
61
|
+
if src_path =~ /\.(#{exts.join '|'})$/
|
62
|
+
case $1
|
63
|
+
when 'coffee' then compile_coffee src_path
|
64
|
+
when 'haml' then compile_haml src_path
|
65
|
+
else false
|
66
|
+
end
|
67
|
+
else
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def compile_coffee src_path
|
73
|
+
return false unless File.exist? src_path and src_path =~ /\.coffee/
|
74
|
+
|
75
|
+
dest_dir = File.dirname destination(src_path)
|
76
|
+
puts "Compile '#{src_path}' to '#{dest_dir}'"
|
77
|
+
|
78
|
+
if `which coffee`.blank?
|
79
|
+
raise "'coffee' command is not found!"
|
80
|
+
end
|
81
|
+
|
82
|
+
command = "coffee -b -o #{dest_dir} #{src_path}"
|
83
|
+
stdin, stdout, stderr = *Open3.popen3(command)
|
84
|
+
stdout.each { |line| puts line }
|
85
|
+
error = stderr.read
|
86
|
+
|
87
|
+
unless result = error.empty?
|
88
|
+
puts error
|
89
|
+
puts "fail to compile '#{src_path}'"
|
90
|
+
end
|
91
|
+
return result
|
92
|
+
end
|
93
|
+
|
94
|
+
def compile_haml src_path
|
95
|
+
return false unless File.exist? src_path and src_path =~ /\.haml/
|
96
|
+
|
97
|
+
dest_path = destination src_path
|
98
|
+
puts "Compile '#{src_path}' to '#{dest_path}'"
|
99
|
+
|
100
|
+
# http://stackoverflow.com/questions/4549598/using-haml-with-custom-filters
|
101
|
+
haml_engine = Haml::Engine.new File.read(src_path)
|
102
|
+
|
103
|
+
dest_dir = File.dirname dest_path
|
104
|
+
FileUtils.makedirs dest_dir unless File.directory? dest_dir
|
105
|
+
|
106
|
+
File.open dest_path, 'w' do |file|
|
107
|
+
file.write haml_engine.render
|
108
|
+
end
|
109
|
+
true
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe AssetWatcher do
|
4
|
+
before :all do
|
5
|
+
@target_dir = File.expand_path "sample", File.dirname(__FILE__)
|
6
|
+
|
7
|
+
@config = {
|
8
|
+
:src_dir => @target_dir + "/src",
|
9
|
+
:dest_dir => @target_dir,
|
10
|
+
}
|
11
|
+
|
12
|
+
FileUtils.makedirs @config[:src_dir]
|
13
|
+
|
14
|
+
@coffee_file = @config[:src_dir] + "/test.coffee"
|
15
|
+
content =<<-Coffee
|
16
|
+
class CoffeeKlass
|
17
|
+
constructor: ->
|
18
|
+
square: (x) -> x * x
|
19
|
+
Coffee
|
20
|
+
File.open(@coffee_file, 'w') { |io| io.write content }
|
21
|
+
|
22
|
+
@haml_file = @config[:src_dir] + "/test.haml"
|
23
|
+
content =<<-HAML
|
24
|
+
!!! 5
|
25
|
+
%html
|
26
|
+
%head
|
27
|
+
%title test page
|
28
|
+
%body
|
29
|
+
AssetWatcher test.
|
30
|
+
HAML
|
31
|
+
|
32
|
+
File.open(@haml_file, 'w') { |io| io.write content }
|
33
|
+
end
|
34
|
+
|
35
|
+
after :all do
|
36
|
+
FileUtils.rm_rf @target_dir if File.directory? @target_dir
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
@watcher = AssetWatcher.new @config
|
41
|
+
end
|
42
|
+
|
43
|
+
context "configurations" do
|
44
|
+
subject { @watcher }
|
45
|
+
|
46
|
+
its(:src_dir) { should == @config[:src_dir] }
|
47
|
+
its(:dest_dir) { should == @config[:dest_dir] }
|
48
|
+
|
49
|
+
context "default values" do
|
50
|
+
before do
|
51
|
+
current_dir = `pwd`.strip
|
52
|
+
@default_config = {
|
53
|
+
:src_dir => current_dir + "/src",
|
54
|
+
:dest_dir => current_dir,
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
subject { AssetWatcher.new }
|
59
|
+
its(:src_dir) { should == @default_config[:src_dir] }
|
60
|
+
its(:dest_dir) { should == @default_config[:dest_dir] }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "yaml file values" do
|
64
|
+
before do
|
65
|
+
@yaml_config = {
|
66
|
+
:src_dir => "/test/src/dir",
|
67
|
+
:dest_dir => "/test/dest/dir",
|
68
|
+
}
|
69
|
+
File.stub(:exist?).and_return true
|
70
|
+
YAML.stub(:load_file).and_return @yaml_config
|
71
|
+
end
|
72
|
+
|
73
|
+
subject { AssetWatcher.new }
|
74
|
+
its(:src_dir) { should == @yaml_config[:src_dir] }
|
75
|
+
its(:dest_dir) { should == @yaml_config[:dest_dir] }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#target_files" do
|
80
|
+
before do
|
81
|
+
@dummy_file = @config[:src_dir] + "/dummy.html"
|
82
|
+
|
83
|
+
content = '<html><body>non-target file.</body></html>'
|
84
|
+
File.open(@dummy_file, 'w') { |io| io.write content }
|
85
|
+
end
|
86
|
+
|
87
|
+
it { File.should be_exist @haml_file }
|
88
|
+
|
89
|
+
subject { @watcher.target_files }
|
90
|
+
it { should be_include @haml_file }
|
91
|
+
it { should be_include @coffee_file }
|
92
|
+
it { should_not be_include @dummy_file }
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#destination" do
|
96
|
+
it { @watcher.destination(@haml_file).should == @config[:dest_dir] + "/test.html" }
|
97
|
+
it { @watcher.destination("/foo/dummy.haml").should be_nil }
|
98
|
+
it { @watcher.destination("/foo/dummy.html").should be_nil }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#compile_haml" do
|
102
|
+
it { @watcher.compile_haml('dummy.haml').should be_false }
|
103
|
+
|
104
|
+
it "should use Haml::Engine" do
|
105
|
+
mock_engine = mock 'Haml Engine'
|
106
|
+
Haml::Engine.stub!(:new).and_return mock_engine
|
107
|
+
mock_engine.should_receive(:render).once
|
108
|
+
|
109
|
+
@watcher.compile_haml @haml_file
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should compile .haml file" do
|
113
|
+
dest_file = @watcher.destination @haml_file
|
114
|
+
|
115
|
+
@watcher.compile_haml @haml_file
|
116
|
+
File.should be_exist dest_file
|
117
|
+
|
118
|
+
output = File.open(dest_file, 'r') { |io| io.read }
|
119
|
+
output.should =~ /test page/
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#compile_coffee" do
|
124
|
+
it { @watcher.compile_coffee('dummy.coffee').should be_false }
|
125
|
+
|
126
|
+
it "should compile .coffee file" do
|
127
|
+
dest_file = @watcher.destination @coffee_file
|
128
|
+
|
129
|
+
begin
|
130
|
+
@watcher.compile_coffee @coffee_file
|
131
|
+
File.should be_exist dest_file
|
132
|
+
|
133
|
+
output = File.open(dest_file, 'r') { |io| io.read }
|
134
|
+
output.should =~ /CoffeeKlass/
|
135
|
+
rescue => e
|
136
|
+
puts e.message
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "#compile" do
|
142
|
+
it "should call :compile_coffee when receives .coffee file path" do
|
143
|
+
@watcher.should_receive(:compile_coffee).with(@coffee_file).once
|
144
|
+
@watcher.compile @coffee_file
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'asset_watcher'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asset_watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- yamada996
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-05 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
prerelease: false
|
33
|
+
name: haml
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
requirement: *id002
|
46
|
+
prerelease: false
|
47
|
+
name: coffee-haml-filter
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirement: *id003
|
60
|
+
prerelease: false
|
61
|
+
name: activesupport
|
62
|
+
type: :runtime
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirement: *id004
|
74
|
+
prerelease: false
|
75
|
+
name: filewatcher
|
76
|
+
type: :runtime
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 2
|
86
|
+
- 3
|
87
|
+
- 0
|
88
|
+
version: 2.3.0
|
89
|
+
requirement: *id005
|
90
|
+
prerelease: false
|
91
|
+
name: rspec
|
92
|
+
type: :development
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 23
|
100
|
+
segments:
|
101
|
+
- 1
|
102
|
+
- 0
|
103
|
+
- 0
|
104
|
+
version: 1.0.0
|
105
|
+
requirement: *id006
|
106
|
+
prerelease: false
|
107
|
+
name: bundler
|
108
|
+
type: :development
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ~>
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 7
|
116
|
+
segments:
|
117
|
+
- 1
|
118
|
+
- 5
|
119
|
+
- 2
|
120
|
+
version: 1.5.2
|
121
|
+
requirement: *id007
|
122
|
+
prerelease: false
|
123
|
+
name: jeweler
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirement: *id008
|
136
|
+
prerelease: false
|
137
|
+
name: rcov
|
138
|
+
type: :development
|
139
|
+
description: watch and auto-compile .coffee and .haml files. Need node.js and coffee-script to compile .coffee file and haml to compile .haml.
|
140
|
+
email: t.yamada.996@gmail.com
|
141
|
+
executables: []
|
142
|
+
|
143
|
+
extensions: []
|
144
|
+
|
145
|
+
extra_rdoc_files:
|
146
|
+
- LICENSE.txt
|
147
|
+
- README.md
|
148
|
+
files:
|
149
|
+
- .document
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- VERSION
|
156
|
+
- asset_watcher.gemspec
|
157
|
+
- lib/asset_watcher.rb
|
158
|
+
- lib/asset_watcher/filewatcher_ext.rb
|
159
|
+
- lib/asset_watcher/tasks/watch.rake
|
160
|
+
- spec/asset_watcher_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
has_rdoc: true
|
163
|
+
homepage: http://github.com/yamada996/asset_watcher
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
hash: 3
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
version: "0"
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 3
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
requirements: []
|
190
|
+
|
191
|
+
rubyforge_project:
|
192
|
+
rubygems_version: 1.4.1
|
193
|
+
signing_key:
|
194
|
+
specification_version: 3
|
195
|
+
summary: watch and auto-compile .coffee and .haml files
|
196
|
+
test_files:
|
197
|
+
- spec/asset_watcher_spec.rb
|
198
|
+
- spec/spec_helper.rb
|