guard-ragel 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/lib/guard/ragel.rb +44 -24
- metadata +40 -10
data/README.md
CHANGED
@@ -34,11 +34,20 @@ Defaults to writing to the same directory in the ruby output format.
|
|
34
34
|
|
35
35
|
An input file of ragel.rl will output a file of ragel.rb in the same directory.
|
36
36
|
|
37
|
+
The output format can be inferred from the input filename if it has multiple
|
38
|
+
extensions, e.g:
|
39
|
+
|
40
|
+
example.rb.rl
|
41
|
+
|
42
|
+
will generate
|
43
|
+
|
44
|
+
example.rb
|
37
45
|
|
38
46
|
## Options
|
39
47
|
|
40
48
|
```ruby
|
41
|
-
:output_format => :ruby # The output format to generate,
|
49
|
+
:output_format => :ruby # The default output format to generate, if
|
50
|
+
# one cannot be determined from the filename
|
42
51
|
#
|
43
52
|
# :c The host language is C, C++, Obj-C or Obj-C++
|
44
53
|
# :d The host language is D
|
data/lib/guard/ragel.rb
CHANGED
@@ -7,20 +7,31 @@ module Guard
|
|
7
7
|
|
8
8
|
RagelError = Class.new(RuntimeError)
|
9
9
|
|
10
|
-
|
11
|
-
:c =>
|
12
|
-
:d =>
|
13
|
-
:go =>
|
14
|
-
:java =>
|
15
|
-
:ruby =>
|
16
|
-
:csharp =>
|
17
|
-
:ocaml =>
|
10
|
+
EXTENSIONS = {
|
11
|
+
:c => 'c',
|
12
|
+
:d => 'd',
|
13
|
+
:go => 'go',
|
14
|
+
:java => 'java',
|
15
|
+
:ruby => 'rb',
|
16
|
+
:csharp => 'cs',
|
17
|
+
:ocaml => 'caml',
|
18
|
+
}
|
19
|
+
FORMAT_FLAGS = {
|
20
|
+
'c' => '-C',
|
21
|
+
'd' => '-D',
|
22
|
+
'go' => '-Z',
|
23
|
+
'java' => '-J',
|
24
|
+
'rb' => '-R',
|
25
|
+
'cs' => '-A',
|
26
|
+
'caml' => '-O'
|
18
27
|
}
|
19
28
|
|
20
29
|
DEFAULTS = {
|
21
|
-
:output_format => :ruby, # Output format
|
30
|
+
:output_format => :ruby, # Output format to use if it cannot be
|
31
|
+
# determined from the original filename
|
22
32
|
:options => '', # Options to pass to ragel
|
23
33
|
:notification => true, # Enable notifications?
|
34
|
+
:extension => nil, # Override output extension
|
24
35
|
}
|
25
36
|
|
26
37
|
def initialize(watchers = [], options = {})
|
@@ -33,14 +44,21 @@ module Guard
|
|
33
44
|
# @return [String] filename generated by running ragel
|
34
45
|
#
|
35
46
|
def build_ragel(file)
|
36
|
-
# Determine name of the output file
|
37
|
-
filename = File.basename(file, File.extname(file))
|
38
47
|
output_dir = options[:output] || File.dir(file)
|
39
|
-
|
40
|
-
|
48
|
+
|
49
|
+
filename, extension = output_filename(file)
|
50
|
+
format_type = options[:output_format]
|
51
|
+
extension ||= EXTENSIONS[format_type]
|
52
|
+
if extension.nil?
|
53
|
+
raise ArgumentError, "Unable to determine output format from #{filename} with default output #{format_type}"
|
54
|
+
end
|
55
|
+
format_flag = FORMAT_FLAGS[extension]
|
41
56
|
|
42
|
-
|
43
|
-
|
57
|
+
if override_extension = options[:extension]
|
58
|
+
extension = override_extension
|
59
|
+
end
|
60
|
+
|
61
|
+
output_file = File.join(output_dir, "#{filename}.#{extension}")
|
44
62
|
|
45
63
|
result = system "ragel #{options[:options]} #{format_flag} #{file} -o #{output_file}"
|
46
64
|
raise RagelError, $? unless result
|
@@ -59,16 +77,16 @@ module Guard
|
|
59
77
|
|
60
78
|
begin
|
61
79
|
output_file = build_ragel(file)
|
62
|
-
message = "
|
63
|
-
::Guard::UI.info "Guard::Ragel #{message}", :reset => true
|
80
|
+
message = "generated '#{output_file}' from '#{file}'"
|
81
|
+
::Guard::UI.info "Guard::Ragel -> #{message}", :reset => true
|
64
82
|
if options[:notification]
|
65
83
|
::Guard::Notifier.notify(message, :title => "Guard::Ragel", :image => :success)
|
66
84
|
end
|
67
85
|
output_file
|
68
86
|
|
69
87
|
rescue RagelError => error
|
70
|
-
message = "
|
71
|
-
::Guard::UI.error "Guard::Ragel #{message}"
|
88
|
+
message = "failed to generate '#{output_file}' from '#{file}', error #{error.message}"
|
89
|
+
::Guard::UI.error "Guard::Ragel -> #{message}"
|
72
90
|
if options[:notification]
|
73
91
|
::Guard::Notifier.notify(message, :title => "Guard::Ragel", :image => :error)
|
74
92
|
end
|
@@ -90,12 +108,14 @@ module Guard
|
|
90
108
|
|
91
109
|
private #####################################################################
|
92
110
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
|
111
|
+
def output_filename(input_filename)
|
112
|
+
basename = File.basename(input_filename, File.extname(input_filename))
|
113
|
+
extension = File.extname(basename)
|
114
|
+
|
115
|
+
if extension[0, 1].eql?('.')
|
116
|
+
return [File.basename(basename, extension), extension.slice(1..-1)]
|
97
117
|
end
|
98
|
-
|
118
|
+
[basename]
|
99
119
|
end
|
100
120
|
|
101
121
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-ragel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Barker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-05 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,9 +51,25 @@ dependencies:
|
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: rake
|
55
55
|
prerelease: false
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 63
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 9
|
65
|
+
- 2
|
66
|
+
version: 0.9.2
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
57
73
|
none: false
|
58
74
|
requirements:
|
59
75
|
- - ">"
|
@@ -66,11 +82,25 @@ dependencies:
|
|
66
82
|
- rc
|
67
83
|
version: 2.0.0.rc
|
68
84
|
type: :development
|
69
|
-
version_requirements: *
|
85
|
+
version_requirements: *id004
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rdoc
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
type: :development
|
99
|
+
version_requirements: *id005
|
70
100
|
- !ruby/object:Gem::Dependency
|
71
101
|
name: guard-rspec
|
72
102
|
prerelease: false
|
73
|
-
requirement: &
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
104
|
none: false
|
75
105
|
requirements:
|
76
106
|
- - ">="
|
@@ -80,7 +110,7 @@ dependencies:
|
|
80
110
|
- 0
|
81
111
|
version: "0"
|
82
112
|
type: :development
|
83
|
-
version_requirements: *
|
113
|
+
version_requirements: *id006
|
84
114
|
description: Guard::Ragel automatically rebuilds ragel .rl files into their corresponding .rb files
|
85
115
|
email:
|
86
116
|
- jebarker@gmail.com
|
@@ -127,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
157
|
requirements: []
|
128
158
|
|
129
159
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
160
|
+
rubygems_version: 1.3.7
|
131
161
|
signing_key:
|
132
162
|
specification_version: 3
|
133
163
|
summary: Guard gem for Ragel
|