guard-ragel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.md +3 -0
- data/lib/guard/ragel.rb +94 -0
- data/lib/guard/ragel/templates/Guardfile +1 -0
- metadata +135 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by John Barker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/lib/guard/ragel.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Ragel < Guard
|
7
|
+
|
8
|
+
RagelError = Class.new(RuntimeError)
|
9
|
+
|
10
|
+
OUTPUT_FORMATS = {
|
11
|
+
:c => ['-C', 'c'],
|
12
|
+
:d => ['-D', 'd'],
|
13
|
+
:go => ['Z', 'go'],
|
14
|
+
:java => ['J', 'java'],
|
15
|
+
:ruby => ['-R', 'rb'],
|
16
|
+
:csharp => ['-A', 'cs'],
|
17
|
+
:ocaml => ['-O', 'caml'],
|
18
|
+
}
|
19
|
+
|
20
|
+
DEFAULTS = {
|
21
|
+
:output_format => :ruby, # Output format of ragel
|
22
|
+
:options => '', # Options to pass to ragel
|
23
|
+
:notification => true, # Enable notifications?
|
24
|
+
}
|
25
|
+
|
26
|
+
def initialize(watchers = [], options = {})
|
27
|
+
super(watchers, DEFAULTS.merge(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Runs ragel over the input file with specified options.
|
31
|
+
#
|
32
|
+
# @param file [String] path to file to build
|
33
|
+
# @return [String] filename generated by running ragel
|
34
|
+
#
|
35
|
+
def build_ragel(file)
|
36
|
+
# Determine name of the output file
|
37
|
+
filename = File.basename(file, File.extname(file))
|
38
|
+
output_dir = options[:output] || File.dir(file)
|
39
|
+
output_extension = options[:extension] || format_options[1]
|
40
|
+
output_file = File.join(output_dir, "#{filename}.#{output_extension}")
|
41
|
+
|
42
|
+
# Flag to make the chosen format
|
43
|
+
format_flag = format_options[0]
|
44
|
+
|
45
|
+
result = system "ragel #{options[:options]} #{format_flag} #{file} -o #{output_file}"
|
46
|
+
raise RagelError, $? unless result
|
47
|
+
|
48
|
+
output_file
|
49
|
+
end
|
50
|
+
|
51
|
+
# Build all files being watched
|
52
|
+
def run_all
|
53
|
+
run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Build the files given
|
57
|
+
def run_on_change(paths)
|
58
|
+
changed_files = paths.reject{ |f| File.basename(f)[0] == "_" }.map do |file|
|
59
|
+
begin
|
60
|
+
output_file = build_ragel(file)
|
61
|
+
::Guard::UI.info "-> rebuilt #{file}", :reset => true
|
62
|
+
::Guard::Notifier.notify("rebuilt #{file}", :title => "Guard::Ragel", :image => :success) if options[:notification]
|
63
|
+
output_file
|
64
|
+
|
65
|
+
rescue RagelError => error
|
66
|
+
::Guard::UI.error "Ragel > #{error.message}"
|
67
|
+
if options[:notification]
|
68
|
+
::Guard::Notifier.notify("rebuild failed > #{error.message}", :title => "Guard::Ragel", :image => :error)
|
69
|
+
end
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end.compact
|
73
|
+
notify changed_files
|
74
|
+
end
|
75
|
+
|
76
|
+
def notify(changed_files)
|
77
|
+
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
78
|
+
paths = Watcher.match_files(guard, changed_files)
|
79
|
+
guard.run_on_change paths unless paths.empty?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private #####################################################################
|
84
|
+
|
85
|
+
def format_options
|
86
|
+
format_type = options[:output_format]
|
87
|
+
unless OUTPUT_FORMATS.key?(format_type)
|
88
|
+
raise ArgumentError, "Unknown output format #{format_type}"
|
89
|
+
end
|
90
|
+
OUTPUT_FORMATS[format_type]
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
guard 'ragel', :input => 'ragel', :output => 'bin'
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-ragel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Barker
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-29 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: guard
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 21
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
- 1
|
34
|
+
version: 0.2.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 19
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
version: 1.0.2
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 7712058
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
- rc
|
67
|
+
version: 2.0.0.rc
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
description: Guard::Ragel automatically rebuilds ragel .rl files into their corresponding .rb files
|
85
|
+
email:
|
86
|
+
- jebarker@gmail.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files: []
|
92
|
+
|
93
|
+
files:
|
94
|
+
- lib/guard/ragel/templates/Guardfile
|
95
|
+
- lib/guard/ragel.rb
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
has_rdoc: true
|
99
|
+
homepage:
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 23
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 3
|
125
|
+
- 6
|
126
|
+
version: 1.3.6
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.6.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Guard gem for Ragel
|
134
|
+
test_files: []
|
135
|
+
|