ouvrages-guard-haml2erb 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/lib/guard/haml2erb.rb +72 -0
- data/lib/guard/haml2erb.rb~ +72 -0
- data/lib/guard/haml2erb/templates/Guardfile +3 -0
- data/lib/guard/haml2erb/templates/Guardfile~ +3 -0
- data/lib/guard/haml2erb/version.rb +5 -0
- data/lib/guard/haml2erb/version.rb~ +5 -0
- metadata +88 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael Witrant
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Guard::Haml2erb
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'guard-haml2erb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install guard-haml2erb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'haml2erb'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Haml2erb < Guard
|
7
|
+
# Initialize a Guard.
|
8
|
+
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
9
|
+
# @param [Hash] options the custom Guard options
|
10
|
+
def initialize(watchers = [], options = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the file path to output the erb based on the file being
|
15
|
+
# built. The output path is relative to where guard is being run.
|
16
|
+
#
|
17
|
+
# @param file [String] path to file being built
|
18
|
+
# @return [String] path to file where output should be written
|
19
|
+
#
|
20
|
+
def get_output(file)
|
21
|
+
file_dir = File.dirname(file)
|
22
|
+
file_name = File.basename(file).split('.')[0..-2].join('.')
|
23
|
+
|
24
|
+
file_name = "#{file_name}.erb" if file_name.match(/\.erb/).nil?
|
25
|
+
|
26
|
+
file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
|
27
|
+
file_dir = File.join(@options[:output], file_dir) if @options[:output]
|
28
|
+
|
29
|
+
if file_dir == ''
|
30
|
+
file_name
|
31
|
+
else
|
32
|
+
File.join(file_dir, file_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Called when just `enter` is pressed
|
38
|
+
# This method should be principally used for long action like running all specs/tests/...
|
39
|
+
# @raise [:task_has_failed] when run_all has failed
|
40
|
+
def run_all
|
41
|
+
run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called on file(s) modifications that the Guard watches.
|
45
|
+
# @param [Array<String>] paths the changes files or paths
|
46
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
47
|
+
def run_on_changes(paths)
|
48
|
+
paths.each do |file|
|
49
|
+
output_file = get_output(file)
|
50
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
51
|
+
File.open(output_file, 'w') { |f| f.write(compile_haml2erb(file)) }
|
52
|
+
::Guard::UI.info "# compiled haml in '#{file}' to erb in '#{output_file}'"
|
53
|
+
::Guard::Notifier.notify("# compiled haml to erb in #{file}", :title => "Guard::Haml2erb", :image => :success) if @options[:notifications]
|
54
|
+
end
|
55
|
+
notify paths
|
56
|
+
end
|
57
|
+
|
58
|
+
# Called on file(s) deletions that the Guard watches.
|
59
|
+
# @param [Array<String>] paths the deleted files or paths
|
60
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
61
|
+
def run_on_removals(paths)
|
62
|
+
end
|
63
|
+
|
64
|
+
def compile_haml2erb(file)
|
65
|
+
template = File.read(file)
|
66
|
+
output = ::Haml2Erb.convert(template)
|
67
|
+
rescue StandardError => error
|
68
|
+
::Guard::UI.error "haml2erb error: " + error.message
|
69
|
+
throw :task_has_failed
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'haml2erb'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Haml2erb < Guard
|
7
|
+
# Initialize a Guard.
|
8
|
+
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
9
|
+
# @param [Hash] options the custom Guard options
|
10
|
+
def initialize(watchers = [], options = {})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the file path to output the html based on the file being
|
15
|
+
# built. The output path is relative to where guard is being run.
|
16
|
+
#
|
17
|
+
# @param file [String] path to file being built
|
18
|
+
# @return [String] path to file where output should be written
|
19
|
+
#
|
20
|
+
def get_output(file)
|
21
|
+
file_dir = File.dirname(file)
|
22
|
+
file_name = File.basename(file).split('.')[0..-2].join('.')
|
23
|
+
|
24
|
+
file_name = "#{file_name}.erb" if file_name.match("\.erb").nil?
|
25
|
+
|
26
|
+
file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
|
27
|
+
file_dir = File.join(@options[:output], file_dir) if @options[:output]
|
28
|
+
|
29
|
+
if file_dir == ''
|
30
|
+
file_name
|
31
|
+
else
|
32
|
+
File.join(file_dir, file_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Called when just `enter` is pressed
|
38
|
+
# This method should be principally used for long action like running all specs/tests/...
|
39
|
+
# @raise [:task_has_failed] when run_all has failed
|
40
|
+
def run_all
|
41
|
+
run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called on file(s) modifications that the Guard watches.
|
45
|
+
# @param [Array<String>] paths the changes files or paths
|
46
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
47
|
+
def run_on_changes(paths)
|
48
|
+
paths.each do |file|
|
49
|
+
output_file = get_output(file)
|
50
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
51
|
+
File.open(output_file, 'w') { |f| f.write(compile_haml2erb(file)) }
|
52
|
+
::Guard::UI.info "# compiled haml in '#{file}' to erb in '#{output_file}'"
|
53
|
+
::Guard::Notifier.notify("# compiled haml to erb in #{file}", :title => "Guard::Haml2erb", :image => :success) if @options[:notifications]
|
54
|
+
end
|
55
|
+
notify paths
|
56
|
+
end
|
57
|
+
|
58
|
+
# Called on file(s) deletions that the Guard watches.
|
59
|
+
# @param [Array<String>] paths the deleted files or paths
|
60
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
61
|
+
def run_on_removals(paths)
|
62
|
+
end
|
63
|
+
|
64
|
+
def compile_haml2erb(file)
|
65
|
+
template = File.read(file)
|
66
|
+
output = ::Haml2Erb.convert(template)
|
67
|
+
rescue StandardError => error
|
68
|
+
::Guard::UI.error "haml2erb error: " + error.message
|
69
|
+
throw :task_has_failed
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ouvrages-guard-haml2erb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ouvrages
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: &86833300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *86833300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ouvrages-haml2erb
|
27
|
+
requirement: &86830880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.3'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *86830880
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &86828790 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *86828790
|
47
|
+
description: Compiles file.erb.haml into file.erb
|
48
|
+
email:
|
49
|
+
- contact@ouvrages-web.fr
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/guard/haml2erb/version.rb
|
55
|
+
- lib/guard/haml2erb/templates/Guardfile
|
56
|
+
- lib/guard/haml2erb/templates/Guardfile~
|
57
|
+
- lib/guard/haml2erb/version.rb~
|
58
|
+
- lib/guard/haml2erb.rb~
|
59
|
+
- lib/guard/haml2erb.rb
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Gemfile
|
63
|
+
homepage: ''
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project: guard-haml2erb
|
83
|
+
rubygems_version: 1.8.11
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Guard gem for haml2erb
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|