RedCloth 4.1.0-universal-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of RedCloth might be problematic. Click here for more details.

Files changed (59) hide show
  1. data/CHANGELOG +103 -0
  2. data/COPYING +18 -0
  3. data/Manifest +57 -0
  4. data/README +156 -0
  5. data/Rakefile +205 -0
  6. data/RedCloth.gemspec +141 -0
  7. data/bin/redcloth +28 -0
  8. data/ext/mingw-rbconfig.rb +176 -0
  9. data/ext/redcloth_scan/extconf.rb +9 -0
  10. data/ext/redcloth_scan/redcloth.h +164 -0
  11. data/ext/redcloth_scan/redcloth_attributes.c.rl +56 -0
  12. data/ext/redcloth_scan/redcloth_attributes.java.rl +96 -0
  13. data/ext/redcloth_scan/redcloth_attributes.rl +33 -0
  14. data/ext/redcloth_scan/redcloth_common.c.rl +18 -0
  15. data/ext/redcloth_scan/redcloth_common.java.rl +18 -0
  16. data/ext/redcloth_scan/redcloth_common.rl +111 -0
  17. data/ext/redcloth_scan/redcloth_inline.c.rl +159 -0
  18. data/ext/redcloth_scan/redcloth_inline.java.rl +108 -0
  19. data/ext/redcloth_scan/redcloth_inline.rl +157 -0
  20. data/ext/redcloth_scan/redcloth_scan.c.rl +227 -0
  21. data/ext/redcloth_scan/redcloth_scan.java.rl +555 -0
  22. data/ext/redcloth_scan/redcloth_scan.rl +323 -0
  23. data/extras/ragel_profiler.rb +73 -0
  24. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  25. data/lib/redcloth.rb +37 -0
  26. data/lib/redcloth/erb_extension.rb +27 -0
  27. data/lib/redcloth/formatters/base.rb +57 -0
  28. data/lib/redcloth/formatters/html.rb +349 -0
  29. data/lib/redcloth/formatters/latex.rb +249 -0
  30. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  31. data/lib/redcloth/textile_doc.rb +105 -0
  32. data/lib/redcloth/version.rb +28 -0
  33. data/lib/redcloth_scan.jar +0 -0
  34. data/setup.rb +1585 -0
  35. data/test/basic.yml +870 -0
  36. data/test/code.yml +229 -0
  37. data/test/definitions.yml +82 -0
  38. data/test/extra_whitespace.yml +64 -0
  39. data/test/filter_html.yml +177 -0
  40. data/test/filter_pba.yml +20 -0
  41. data/test/helper.rb +108 -0
  42. data/test/html.yml +305 -0
  43. data/test/images.yml +246 -0
  44. data/test/instiki.yml +38 -0
  45. data/test/links.yml +259 -0
  46. data/test/lists.yml +283 -0
  47. data/test/poignant.yml +89 -0
  48. data/test/sanitize_html.yml +42 -0
  49. data/test/table.yml +267 -0
  50. data/test/test_custom_tags.rb +46 -0
  51. data/test/test_erb.rb +13 -0
  52. data/test/test_extensions.rb +31 -0
  53. data/test/test_formatters.rb +24 -0
  54. data/test/test_parser.rb +73 -0
  55. data/test/test_restrictions.rb +41 -0
  56. data/test/textism.yml +480 -0
  57. data/test/threshold.yml +772 -0
  58. data/test/validate_fixtures.rb +73 -0
  59. metadata +139 -0
@@ -0,0 +1,103 @@
1
+ === 4.1.0 / October 31, 2008
2
+
3
+ * JRuby support! [olabini]
4
+ To run the tests with JRuby, you only need to: jruby -S rake
5
+ To compile the jruby version of the gem: jruby -S rake compile
6
+
7
+ * Added textilize ERB utility method. [edraut]
8
+ Use it in an ERB template like this: <%=t my_textile_string %> or
9
+ <%=r %{Some *textile* if you please!} %>
10
+
11
+ * Fix extended blockcode stripping whitespace following blank line. #78
12
+
13
+
14
+ === 4.0.4 / October 1, 2008
15
+
16
+ * Added some very basic support for images in LaTeX. [virtualfunction]
17
+
18
+ * Fixed missed caps and inline modifiers wrapped in parentheses. #43, #45
19
+
20
+ * Removed indication of quotes explicitly with square brackets. Textile 2.0 does not support this and it wasn't in RedCloth 3. #46
21
+
22
+ * Made percent signs less greedy. They must surround a phrase or else they must be surrounded with square brackets, just like sup, sub, and del phrases. #47
23
+
24
+ * Reduced link eagerness so it wouldn't include preceding quoted phrases. #48
25
+
26
+ * Fixed compatibility issues with Ruby 1.9 [Keita Yamaguchi]. #52, 53, 54
27
+
28
+ * Fixed an error when a link was badly nested in parentheses. #55
29
+
30
+ * Fixed an error on superscript/subscript parenthetical phrase. #56
31
+
32
+ * Fixed bold phrases starting with a number being recognized as unordered lists. #60
33
+
34
+ * Fixed behavior of unclosed (multi-paragraph) quotes and incorrect handling of links inside double quotations. #59, #63
35
+
36
+ * Fixed empty block HTML disappearing. #64
37
+
38
+
39
+ === 4.0.3 / August 18, 2008
40
+
41
+ * Fix NoMethodError: private method gsub!' called for nil:NilClass when two dimensions followed by a space. #38
42
+
43
+ * Fixed unititialized constant RedCloth::TextileDoc with Rails 2.1. Came from a workaround for Rails bug #320 that was applied even when not necessary. #42
44
+
45
+
46
+ === 4.0.2 / August 15, 2008
47
+
48
+ * Fixed link references/aliases not being recognized when they include hyphens. #36
49
+
50
+ * Dimensions in feet and inches use correct typographic characters. #25
51
+
52
+ * Limit overzealous superscript and subscript. Sup/sub phrases must be surrounded by spaces or square brackets, as in Textile 2. #35
53
+
54
+ * Fixed HTML before tables causing the opening table tag to be emitted twice. #33
55
+
56
+ * Cleaned up unused code that was causing a warning. #28
57
+
58
+ * Workaround for Rails 2.1 bug that loads a previous version of RedCloth before loading the unpacked gem. Has since been fixed in edge rails. #30
59
+
60
+ * Added a RedCloth::VERSION.to_s and .== methods so you can puts and compare RedCloth::VERSION just like in previous RedCloth releases. #26
61
+
62
+ * Fixed HTML block ending tags terminating blocks prematurely. #22
63
+
64
+
65
+ === 4.0.1 / July 24, 2008
66
+
67
+ * Fixed lines starting with dashes being recognized as a definition list when there were no definitions.
68
+
69
+ * Created alias RedCloth.rb so Rails 2.1 gem dependency works on case-sensitive operating systems .
70
+ * Fixed parsing sentences that had two em dashes surrounded by spaces from becoming del phrases. #19
71
+
72
+ * Fixed links including prior quoted phrases. #17
73
+
74
+
75
+ === 4.0.0 / July 21, 2008
76
+
77
+ * New SuperRedCloth (RedCloth 4.0) is a total rewrite using Ragel for the parsing.
78
+
79
+ * Markdown support has been removed.
80
+
81
+ * Single newlines become <br> tags, just as in traditional RedCloth and other Textile parsers.
82
+
83
+ * HTML special characters are automatically escaped inside code signatures, like Textile 2. This means you can simply write @<br />@ and the symbols are escaped whereas in RedCloth 3 you had to write @&lt;br /&gt;@ to make the code fragment readable.
84
+
85
+ * The restrictions parameter is observed just like previous versions (except :hard_breaks is now the default).
86
+
87
+ * Arguments to RedCloth#to_html are called so extensions made for prior versions can work. Note: extensions need to be included rather than defined directly within the RedCloth class as was previously possible.
88
+
89
+ * Custom block tags can be implemented as in the previous version, though the means of implementing them differs.
90
+
91
+ * HTML embedded in the Textile input does not often need to be escaped from Textile parsing.
92
+
93
+ * The parser will not wrap lines that begin with a space in paragraph tags.
94
+
95
+ * Rudimentary support for LaTeX is built in.
96
+
97
+ * RedCloth::VERSION on a line by itself inserts the version number into the output.
98
+
99
+ * Output (less newlines and tabs) is identical to Textile 2 except a few cases where the RedCloth way was preferable.
100
+
101
+ * Over 500 tests prevent regression
102
+
103
+ * It's 40 times faster than the previous version.
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Jason Garber
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
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell 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
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ bin/redcloth
2
+ CHANGELOG
3
+ COPYING
4
+ ext/mingw-rbconfig.rb
5
+ ext/redcloth_scan/extconf.rb
6
+ ext/redcloth_scan/redcloth.h
7
+ ext/redcloth_scan/redcloth_attributes.c.rl
8
+ ext/redcloth_scan/redcloth_attributes.java.rl
9
+ ext/redcloth_scan/redcloth_attributes.rl
10
+ ext/redcloth_scan/redcloth_common.c.rl
11
+ ext/redcloth_scan/redcloth_common.java.rl
12
+ ext/redcloth_scan/redcloth_common.rl
13
+ ext/redcloth_scan/redcloth_inline.c.rl
14
+ ext/redcloth_scan/redcloth_inline.java.rl
15
+ ext/redcloth_scan/redcloth_inline.rl
16
+ ext/redcloth_scan/redcloth_scan.c.rl
17
+ ext/redcloth_scan/redcloth_scan.java.rl
18
+ ext/redcloth_scan/redcloth_scan.rl
19
+ extras/ragel_profiler.rb
20
+ lib/case_sensitive_require/RedCloth.rb
21
+ lib/redcloth/erb_extension.rb
22
+ lib/redcloth/formatters/base.rb
23
+ lib/redcloth/formatters/html.rb
24
+ lib/redcloth/formatters/latex.rb
25
+ lib/redcloth/formatters/latex_entities.yml
26
+ lib/redcloth/textile_doc.rb
27
+ lib/redcloth/version.rb
28
+ lib/redcloth.rb
29
+ Manifest
30
+ Rakefile
31
+ README
32
+ RedCloth.gemspec
33
+ setup.rb
34
+ test/basic.yml
35
+ test/code.yml
36
+ test/definitions.yml
37
+ test/extra_whitespace.yml
38
+ test/filter_html.yml
39
+ test/filter_pba.yml
40
+ test/helper.rb
41
+ test/html.yml
42
+ test/images.yml
43
+ test/instiki.yml
44
+ test/links.yml
45
+ test/lists.yml
46
+ test/poignant.yml
47
+ test/sanitize_html.yml
48
+ test/table.yml
49
+ test/test_custom_tags.rb
50
+ test/test_erb.rb
51
+ test/test_extensions.rb
52
+ test/test_formatters.rb
53
+ test/test_parser.rb
54
+ test/test_restrictions.rb
55
+ test/textism.yml
56
+ test/threshold.yml
57
+ test/validate_fixtures.rb
data/README ADDED
@@ -0,0 +1,156 @@
1
+ = RedCloth - Textile parser for Ruby
2
+
3
+ Homepage:: http://redcloth.org
4
+ Author:: Jason Garber
5
+ Copyright:: (c) 2008 Jason Garber
6
+ License:: MIT
7
+
8
+ (See http://redcloth.org/textile/ for a Textile reference.)
9
+
10
+ = RedCloth
11
+
12
+ RedCloth is a Ruby library for converting Textile into HTML.
13
+
14
+ == Installing
15
+
16
+ RedCloth can be installed via RubyGems:
17
+
18
+ sudo gem install RedCloth
19
+
20
+ Or can be compiled from its Ragel source with <tt>rake compile</tt>. Ragel 6.2
21
+ or greater is required to build RedCloth.
22
+
23
+ == What is Textile?
24
+
25
+ Textile is a simple formatting style for text
26
+ documents, loosely based on some HTML conventions.
27
+
28
+ == Sample Textile Text
29
+
30
+ h2. This is a title
31
+
32
+ h3. This is a subhead
33
+
34
+ This is a bit of paragraph.
35
+
36
+ bq. This is a blockquote.
37
+
38
+ = Writing Textile
39
+
40
+ A Textile document consists of paragraphs. Paragraphs
41
+ can be specially formatted by adding a small instruction
42
+ to the beginning of the paragraph.
43
+
44
+ h3. Header 3.
45
+ bq. Blockquote.
46
+ # Numeric list.
47
+ * Bulleted list.
48
+
49
+ == Quick Phrase Modifiers
50
+
51
+ Quick phrase modifiers are also included, to allow formatting
52
+ of small portions of text within a paragraph.
53
+
54
+ _emphasis_
55
+ __italicized__
56
+ *strong*
57
+ **bold**
58
+ ??citation??
59
+ -deleted text-
60
+ +inserted text+
61
+ ^superscript^
62
+ ~subscript~
63
+ @code@
64
+ %(classname)span%
65
+
66
+ ==notextile== (leave text alone)
67
+
68
+ == Links
69
+
70
+ To make a hypertext link, put the link text in "quotation
71
+ marks" followed immediately by a colon and the URL of the link.
72
+
73
+ Optional: text in (parentheses) following the link text,
74
+ but before the closing quotation mark, will become a title
75
+ attribute for the link, visible as a tool tip when a cursor is above it.
76
+
77
+ Example:
78
+
79
+ "This is a link (This is a title)":http://www.textism.com
80
+
81
+ Will become:
82
+
83
+ <a href="http://www.textism.com" title="This is a title">This is a link</a>
84
+
85
+ == Images
86
+
87
+ To insert an image, put the URL for the image inside exclamation marks.
88
+
89
+ Optional: text that immediately follows the URL in (parentheses) will
90
+ be used as the Alt text for the image. Images on the web should always
91
+ have descriptive Alt text for the benefit of readers using non-graphical
92
+ browsers.
93
+
94
+ Optional: place a colon followed by a URL immediately after the
95
+ closing ! to make the image into a link.
96
+
97
+ Example:
98
+
99
+ !http://www.textism.com/common/textist.gif(Textist)!
100
+
101
+ Will become:
102
+
103
+ <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
104
+
105
+ With a link:
106
+
107
+ !/common/textist.gif(Textist)!:http://textism.com
108
+
109
+ Will become:
110
+
111
+ <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
112
+
113
+ == Defining Acronyms
114
+
115
+ HTML allows authors to define acronyms via the tag. The definition appears as a
116
+ tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
117
+ this should be used at least once for each acronym in documents where they appear.
118
+
119
+ To quickly define an acronym in Textile, place the full text in (parentheses)
120
+ immediately following the acronym.
121
+
122
+ Example:
123
+
124
+ ACLU(American Civil Liberties Union)
125
+
126
+ Will become:
127
+
128
+ <acronym title="American Civil Liberties Union">ACLU</acronym>
129
+
130
+ == Adding Tables
131
+
132
+ In Textile, simple tables can be added by separating each column by
133
+ a pipe.
134
+
135
+ |a|simple|table|row|
136
+ |And|Another|table|row|
137
+
138
+ Styles are applied with curly braces.
139
+
140
+ table{border:1px solid black}.
141
+ {background:#ddd;color:red}. |a|red|row|
142
+
143
+ == Using RedCloth
144
+
145
+ RedCloth is simply an extension of the String class, which can handle
146
+ Textile formatting. Use it like a String and output HTML with its
147
+ RedCloth#to_html method.
148
+
149
+ doc = RedCloth.new "
150
+
151
+ h2. Test document
152
+
153
+ Just a simple test."
154
+
155
+ puts doc.to_html
156
+
@@ -0,0 +1,205 @@
1
+ require 'lib/redcloth/version'
2
+
3
+ begin
4
+ require 'rubygems'
5
+ gem 'echoe', '>=2.7.11'
6
+ require 'echoe'
7
+ rescue LoadError
8
+ abort "You'll need to have `echoe' installed to use RedCloth's Rakefile"
9
+ end
10
+
11
+ e = Echoe.new('RedCloth', RedCloth::VERSION.to_s) do |p|
12
+ p.summary = RedCloth::DESCRIPTION
13
+ p.author = "Jason Garber"
14
+ p.email = 'redcloth-upwards@rubyforge.org'
15
+ p.clean_pattern += ['ext/redcloth_scan/**/*.{bundle,so,obj,pdb,lib,def,exp,c,o,xml,class,jar,java}', 'lib/*.{bundle,so,o,obj,pdb,lib,def,exp,jar}', 'ext/redcloth_scan/Makefile']
16
+ p.url = "http://redcloth.org"
17
+ p.project = "redcloth"
18
+ p.rdoc_pattern = ['README', 'COPING', 'CHANGELOG', 'lib/**/*.rb', 'doc/**/*.rdoc']
19
+ p.ignore_pattern = /^(pkg|site|projects|doc|log)|CVS|\.log/
20
+ p.ruby_version = '>=1.8.4'
21
+ p.extension_pattern = nil
22
+
23
+
24
+ if RUBY_PLATFORM =~ /mingw|mswin|java/
25
+ p.need_tar_gz = false
26
+ else
27
+ p.need_zip = true
28
+ p.need_tar_gz = true
29
+ p.extension_pattern = ["ext/**/extconf.rb"]
30
+ end
31
+
32
+ p.eval = proc do
33
+ case RUBY_PLATFORM
34
+ when /mingw/
35
+ self.files += ['lib/redcloth_scan.so']
36
+ self.platform = 'x86-mswin32-60'
37
+ when /java/
38
+ self.files += ['lib/redcloth_scan.jar']
39
+ self.platform = 'universal-java'
40
+ else
41
+ self.files += %w[attributes inline scan].map {|f| "ext/redcloth_scan/redcloth_#{f}.c"}
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ #### Pre-compiled extensions for alternative platforms
48
+
49
+ def move_extensions
50
+ Dir["ext/**/*.{bundle,so,jar}"].each { |file| mv file, "lib/" }
51
+ end
52
+
53
+ def java_classpath_arg
54
+ # A myriad of ways to discover the JRuby classpath
55
+ classpath = begin
56
+ require 'java'
57
+ # Already running in a JRuby JVM
58
+ Java::java.lang.System.getProperty('java.class.path')
59
+ rescue LoadError
60
+ ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] && FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
61
+ end
62
+ classpath ? "-cp #{classpath}" : ""
63
+ end
64
+
65
+ ext = "ext/redcloth_scan"
66
+
67
+ case RUBY_PLATFORM
68
+ when /mingw/
69
+
70
+ filename = "lib/redcloth_scan.so"
71
+ file filename => FileList["#{ext}/redcloth_scan.c", "#{ext}/redcloth_inline.c", "#{ext}/redcloth_attributes.c"] do
72
+ cp "ext/mingw-rbconfig.rb", "#{ext}/rbconfig.rb"
73
+ Dir.chdir("ext/redcloth_scan") do
74
+ ruby "-I. extconf.rb"
75
+ system(PLATFORM =~ /mswin/ ? 'nmake' : 'make')
76
+ end
77
+ move_extensions
78
+ rm "#{ext}/rbconfig.rb"
79
+ end
80
+
81
+ when /java/
82
+
83
+ filename = "lib/redcloth_scan.jar"
84
+ file filename => FileList["#{ext}/RedclothScanService.java", "#{ext}/RedclothInline.java", "#{ext}/RedclothAttributes.java"] do
85
+ sources = FileList["#{ext}/**/*.java"].join(' ')
86
+ sh "javac -target 1.5 -source 1.5 -d #{ext} #{java_classpath_arg} #{sources}"
87
+ sh "jar cf lib/redcloth_scan.jar -C #{ext} ."
88
+ move_extensions
89
+ end
90
+
91
+ else
92
+ filename = "#{ext}/redcloth_scan.#{Config::CONFIG['DLEXT']}"
93
+ file filename => FileList["#{ext}/redcloth_scan.c", "#{ext}/redcloth_inline.c", "#{ext}/redcloth_attributes.c"]
94
+ end
95
+
96
+ task :compile => [filename]
97
+
98
+ def ragel(target_file, source_file)
99
+ host_language = (target_file =~ /java$/) ? "J" : "C"
100
+ code_style = (host_language == "C") ? " -" + (@code_style || "T0") : ""
101
+ ensure_ragel_version(target_file) do
102
+ sh %{ragel #{source_file} -#{host_language}#{code_style} -o #{target_file}}
103
+ end
104
+ end
105
+
106
+ # Make sure the .c files exist if you try the Makefile, otherwise Ragel will have to generate them.
107
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb", "#{ext}/redcloth_scan.c","#{ext}/redcloth_inline.c","#{ext}/redcloth_attributes.c","#{ext}/redcloth_scan.o","#{ext}/redcloth_inline.o","#{ext}/redcloth_attributes.o"]
108
+
109
+ # Ragel-generated C files
110
+ file "#{ext}/redcloth_scan.c" => ["#{ext}/redcloth_scan.c.rl", "#{ext}/redcloth_scan.rl", "#{ext}/redcloth_common.c.rl", "#{ext}/redcloth_common.rl", "#{ext}/redcloth.h"] do
111
+ ragel "#{ext}/redcloth_scan.c", "#{ext}/redcloth_scan.c.rl"
112
+ end
113
+ file "#{ext}/redcloth_inline.c" => ["#{ext}/redcloth_inline.c.rl", "#{ext}/redcloth_inline.rl", "#{ext}/redcloth_common.c.rl", "#{ext}/redcloth_common.rl", "#{ext}/redcloth.h"] do
114
+ ragel "#{ext}/redcloth_inline.c", "#{ext}/redcloth_inline.c.rl"
115
+ end
116
+ file "#{ext}/redcloth_attributes.c" => ["#{ext}/redcloth_attributes.c.rl", "#{ext}/redcloth_attributes.rl", "#{ext}/redcloth_common.c.rl", "#{ext}/redcloth_common.rl", "#{ext}/redcloth.h"] do
117
+ ragel "#{ext}/redcloth_attributes.c", "#{ext}/redcloth_attributes.c.rl"
118
+ end
119
+
120
+ # Ragel-generated Java files
121
+ file "#{ext}/RedclothScanService.java" => ["#{ext}/redcloth_scan.java.rl", "#{ext}/redcloth_scan.rl", "#{ext}/redcloth_common.java.rl", "#{ext}/redcloth_common.rl"] do
122
+ ragel "#{ext}/RedclothScanService.java", "#{ext}/redcloth_scan.java.rl"
123
+ end
124
+ file "#{ext}/RedclothInline.java" => ["#{ext}/redcloth_inline.java.rl", "#{ext}/redcloth_inline.rl", "#{ext}/redcloth_common.java.rl", "#{ext}/redcloth_common.rl", "#{ext}/redcloth_scan.java.rl"] do
125
+ ragel "#{ext}/RedclothInline.java", "#{ext}/redcloth_inline.java.rl"
126
+ end
127
+ file "#{ext}/RedclothAttributes.java" => ["#{ext}/redcloth_attributes.java.rl", "#{ext}/redcloth_attributes.rl", "#{ext}/redcloth_common.java.rl", "#{ext}/redcloth_common.rl", "#{ext}/redcloth_scan.java.rl"] do
128
+ ragel "#{ext}/RedclothAttributes.java", "#{ext}/redcloth_attributes.java.rl"
129
+ end
130
+
131
+
132
+ #### Optimization
133
+
134
+ RAGEL_CODE_GENERATION_STYLES = {
135
+ 'T0' => "Table driven FSM (default)",
136
+ 'T1' => "Faster table driven FSM",
137
+ 'F0' => "Flat table driven FSM",
138
+ 'F1' => "Faster flat table-driven FSM",
139
+ 'G0' => "Goto-driven FSM",
140
+ 'G1' => "Faster goto-driven FSM",
141
+ 'G2' => "Really fast goto-driven FSM"
142
+ }
143
+
144
+ desc "Find the fastest code generation style for Ragel"
145
+ task :optimize do
146
+ require 'extras/ragel_profiler'
147
+ results = []
148
+ RAGEL_CODE_GENERATION_STYLES.each do |style, name|
149
+ @code_style = style
150
+ profiler = RagelProfiler.new(style + " " + name)
151
+
152
+ # Hack to get everything to invoke again. Could use #execute, but then it
153
+ # doesn't execute prerequisites the second+ time
154
+ Rake::Task.tasks.each {|t| t.instance_eval "@already_invoked = false" }
155
+
156
+ Rake::Task['clobber'].invoke
157
+
158
+ profiler.measure(:compile) do
159
+ Rake::Task['compile'].invoke
160
+ end
161
+ profiler.measure(:test) do
162
+ Rake::Task['test'].invoke
163
+ end
164
+ profiler.ext_size(ext_so)
165
+
166
+ end
167
+ puts RagelProfiler.results
168
+ end
169
+
170
+
171
+ #### Custom testing tasks
172
+
173
+ task :test => [:compile]
174
+
175
+ # Run specific tests or test files
176
+ #
177
+ # rake test:parser
178
+ # => Runs the full TestParser unit test
179
+ #
180
+ # rake test:parser:textism
181
+ # => Runs the tests matching /textism/ in the TestParser unit test
182
+ rule "" do |t|
183
+ # test:file:method
184
+ if /test:(.*)(:([^.]+))?$/.match(t.name)
185
+ arguments = t.name.split(":")[1..-1]
186
+ file_name = arguments.first
187
+ test_name = arguments[1..-1]
188
+
189
+ if File.exist?("test/test_#{file_name}.rb")
190
+ run_file_name = "test_#{file_name}.rb"
191
+ end
192
+
193
+ sh "ruby -Ilib:test test/#{run_file_name} -n /#{test_name}/"
194
+ end
195
+ end
196
+
197
+ def ensure_ragel_version(name)
198
+ @ragel_v ||= `ragel -v`[/(version )(\S*)/,2].split('.').map{|s| s.to_i}
199
+ if @ragel_v[0] > 6 || (@ragel_v[0] == 6 && @ragel_v[1] >= 3)
200
+ yield
201
+ else
202
+ STDERR.puts "Ragel 6.3 or greater is required to generate #{name}."
203
+ exit(1)
204
+ end
205
+ end