guard-haml-coffee 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Guard::Haml::Coffee
2
2
 
3
- TODO: Write a gem description
3
+ Guard gem to generate Javascript code from [Haml Coffee](https://github.com/netzpirat/haml-coffee) templates. Inspired by [haml_coffee_assets](https://github.com/netzpirat/haml_coffee_assets).
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ As a prerequisite, you must have [Guard](https://github.com/guard/guard) installed and initialized already.
22
+
23
+ Add the haml-coffee instructions to the `Guardfile`:
24
+
25
+ $ bundle exec guard init haml-coffee
26
+
27
+ Restart guard if it's running and that's it.
22
28
 
23
29
  ## Contributing
24
30
 
@@ -4,7 +4,7 @@ require File.expand_path('../lib/guard/haml-coffee/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Ouvrages"]
6
6
  gem.email = ["contact@ouvrages-web.fr"]
7
- gem.description = %q{Compiles a HamlCoffee .js.hamlc file to a .js javascript template}
7
+ gem.description = %q{Compiles HamlCoffee templates to javascript}
8
8
  gem.summary = %q{Guard gem for HamlCoffee}
9
9
  gem.homepage = "https://github.com/ouvrages/guard-haml-coffee"
10
10
 
@@ -9,7 +9,10 @@ module Guard
9
9
  class HamlCoffee < Guard
10
10
 
11
11
  def initialize(watchers=[], options={})
12
- super
12
+ @options = {
13
+ :notifications => true
14
+ }.merge(options)
15
+ super(watchers, @options)
13
16
  end
14
17
 
15
18
  def start
@@ -20,6 +23,28 @@ module Guard
20
23
  @runtime = ExecJS.compile(source)
21
24
  end
22
25
 
26
+ # Get the file path to output the html based on the file being
27
+ # built. The output path is relative to where guard is being run.
28
+ #
29
+ # @param file [String] path to file being built
30
+ # @return [String] path to file where output should be written
31
+ #
32
+ def get_output(file)
33
+ file_dir = File.dirname(file)
34
+ file_name = File.basename(file).split('.')[0..-2].join('.')
35
+
36
+ file_name = "#{file_name}.js" if file_name.match("\.js").nil?
37
+
38
+ file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
39
+ file_dir = File.join(@options[:output], file_dir) if @options[:output]
40
+
41
+ if file_dir == ''
42
+ file_name
43
+ else
44
+ File.join(file_dir, file_name)
45
+ end
46
+ end
47
+
23
48
  def run_all
24
49
  run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
25
50
  end
@@ -27,7 +52,8 @@ module Guard
27
52
  def run_on_changes(paths)
28
53
  paths.each do |path|
29
54
  basename = File.basename(path, '.js.hamlc')
30
- output_file = File.join(File.dirname(path), basename + ".js")
55
+ output_file = get_output(path)
56
+ FileUtils.mkdir_p File.dirname(output_file)
31
57
  options = [
32
58
  basename,
33
59
  File.read(path),
@@ -1,7 +1,7 @@
1
1
  module Guard
2
2
  module Haml
3
3
  module Coffee
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  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: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
16
- requirement: &86586000 !ruby/object:Gem::Requirement
16
+ requirement: &85692160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *86586000
24
+ version_requirements: *85692160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: execjs
27
- requirement: &86585790 !ruby/object:Gem::Requirement
27
+ requirement: &85691740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *86585790
35
+ version_requirements: *85691740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: coffee-script
38
- requirement: &86585580 !ruby/object:Gem::Requirement
38
+ requirement: &85691220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,8 +43,8 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *86585580
47
- description: Compiles a HamlCoffee .js.hamlc file to a .js javascript template
46
+ version_requirements: *85691220
47
+ description: Compiles HamlCoffee templates to javascript
48
48
  email:
49
49
  - contact@ouvrages-web.fr
50
50
  executables: []