jeremy-RedCloth 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +135 -0
  2. data/COPYING +18 -0
  3. data/Manifest +56 -0
  4. data/README +171 -0
  5. data/Rakefile +205 -0
  6. data/bin/redcloth +28 -0
  7. data/ext/mingw-rbconfig.rb +176 -0
  8. data/ext/redcloth_scan/extconf.rb +9 -0
  9. data/ext/redcloth_scan/redcloth.h +178 -0
  10. data/ext/redcloth_scan/redcloth_attributes.c.rl +56 -0
  11. data/ext/redcloth_scan/redcloth_attributes.java.rl +96 -0
  12. data/ext/redcloth_scan/redcloth_attributes.rl +33 -0
  13. data/ext/redcloth_scan/redcloth_common.c.rl +18 -0
  14. data/ext/redcloth_scan/redcloth_common.java.rl +18 -0
  15. data/ext/redcloth_scan/redcloth_common.rl +111 -0
  16. data/ext/redcloth_scan/redcloth_inline.c.rl +159 -0
  17. data/ext/redcloth_scan/redcloth_inline.java.rl +108 -0
  18. data/ext/redcloth_scan/redcloth_inline.rl +159 -0
  19. data/ext/redcloth_scan/redcloth_scan.c.rl +237 -0
  20. data/ext/redcloth_scan/redcloth_scan.java.rl +573 -0
  21. data/ext/redcloth_scan/redcloth_scan.rl +325 -0
  22. data/extras/ragel_profiler.rb +73 -0
  23. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  24. data/lib/redcloth.rb +37 -0
  25. data/lib/redcloth/erb_extension.rb +27 -0
  26. data/lib/redcloth/formatters/base.rb +57 -0
  27. data/lib/redcloth/formatters/html.rb +353 -0
  28. data/lib/redcloth/formatters/latex.rb +275 -0
  29. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  30. data/lib/redcloth/textile_doc.rb +103 -0
  31. data/lib/redcloth/version.rb +28 -0
  32. data/setup.rb +1585 -0
  33. data/test/basic.yml +922 -0
  34. data/test/code.yml +229 -0
  35. data/test/definitions.yml +82 -0
  36. data/test/extra_whitespace.yml +64 -0
  37. data/test/filter_html.yml +177 -0
  38. data/test/filter_pba.yml +20 -0
  39. data/test/helper.rb +108 -0
  40. data/test/html.yml +311 -0
  41. data/test/images.yml +254 -0
  42. data/test/instiki.yml +38 -0
  43. data/test/links.yml +275 -0
  44. data/test/lists.yml +283 -0
  45. data/test/poignant.yml +89 -0
  46. data/test/sanitize_html.yml +42 -0
  47. data/test/table.yml +336 -0
  48. data/test/test_custom_tags.rb +58 -0
  49. data/test/test_erb.rb +13 -0
  50. data/test/test_extensions.rb +31 -0
  51. data/test/test_formatters.rb +24 -0
  52. data/test/test_parser.rb +73 -0
  53. data/test/test_restrictions.rb +41 -0
  54. data/test/textism.yml +480 -0
  55. data/test/threshold.yml +772 -0
  56. data/test/validate_fixtures.rb +74 -0
  57. metadata +133 -0
@@ -0,0 +1,135 @@
1
+ === Edge
2
+
3
+ * Don't allow square brackets inside lang attribute so double square brackets are interpreted like Textile 2 and RedCloth 3. #101
4
+
5
+ * Improve LaTeX output for tables. #96
6
+
7
+ * Fix bad parsing of bracketed image links (which would hang the interpreter in some cases). #97
8
+
9
+ * Handle links containing parentheses. Brackets are no longer required. #82 [Ryan Alyea]
10
+
11
+ * Made italics use the correct LaTeX tag: textit rather than emph. #98
12
+
13
+ * Fixed custom block signatures calling built-in Ruby String methods. #92
14
+
15
+ * Mentioned the three supported platforms and what's necessary to build RedCloth in the README file.
16
+
17
+ * Fixed a require problem that caused an error when you would gem check --test RedCloth. #91
18
+
19
+ === 4.1.1 / November 19, 2008
20
+
21
+ * Added 'lib/case_sensitive_require' back into gemspec. It got left out in the conversion to echoe, so "require 'RedCloth'" didn't work. #88
22
+
23
+ * Fixed <embed> being recognized as a block-level element when using the twice-cooked method of flash embedding. #87
24
+
25
+ * Added horizontal rules from RedCloth 3. Three or more asterisks, dashes, or underscores between blocks triggers the HR tag.
26
+
27
+ * echoe was not being properly registered as a development dependency; a bug in RubyGems was making it a runtime dependency
28
+
29
+ * Fixed "No definition for redcloth_to Installing RDoc documentation"
30
+
31
+ * Fixed wrong platform names when cross-compiling java and win32 versions
32
+
33
+ === 4.1.0 / October 31, 2008
34
+
35
+ * JRuby support! [olabini]
36
+ To run the tests with JRuby, you only need to: jruby -S rake
37
+ To compile the jruby version of the gem: jruby -S rake compile
38
+
39
+ * Added textilize ERB utility method. [edraut]
40
+ Use it in an ERB template like this: <%=t my_textile_string %> or
41
+ <%=r %{Some *textile* if you please!} %>
42
+
43
+ * Fix extended blockcode stripping whitespace following blank line. #78
44
+
45
+
46
+ === 4.0.4 / October 1, 2008
47
+
48
+ * Added some very basic support for images in LaTeX. [virtualfunction]
49
+
50
+ * Fixed missed caps and inline modifiers wrapped in parentheses. #43, #45
51
+
52
+ * Removed indication of quotes explicitly with square brackets. Textile 2.0 does not support this and it wasn't in RedCloth 3. #46
53
+
54
+ * 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
55
+
56
+ * Reduced link eagerness so it wouldn't include preceding quoted phrases. #48
57
+
58
+ * Fixed compatibility issues with Ruby 1.9 [Keita Yamaguchi]. #52, 53, 54
59
+
60
+ * Fixed an error when a link was badly nested in parentheses. #55
61
+
62
+ * Fixed an error on superscript/subscript parenthetical phrase. #56
63
+
64
+ * Fixed bold phrases starting with a number being recognized as unordered lists. #60
65
+
66
+ * Fixed behavior of unclosed (multi-paragraph) quotes and incorrect handling of links inside double quotations. #59, #63
67
+
68
+ * Fixed empty block HTML disappearing. #64
69
+
70
+
71
+ === 4.0.3 / August 18, 2008
72
+
73
+ * Fix NoMethodError: private method gsub!' called for nil:NilClass when two dimensions followed by a space. #38
74
+
75
+ * 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
76
+
77
+
78
+ === 4.0.2 / August 15, 2008
79
+
80
+ * Fixed link references/aliases not being recognized when they include hyphens. #36
81
+
82
+ * Dimensions in feet and inches use correct typographic characters. #25
83
+
84
+ * Limit overzealous superscript and subscript. Sup/sub phrases must be surrounded by spaces or square brackets, as in Textile 2. #35
85
+
86
+ * Fixed HTML before tables causing the opening table tag to be emitted twice. #33
87
+
88
+ * Cleaned up unused code that was causing a warning. #28
89
+
90
+ * 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
91
+
92
+ * Added a RedCloth::VERSION.to_s and .== methods so you can puts and compare RedCloth::VERSION just like in previous RedCloth releases. #26
93
+
94
+ * Fixed HTML block ending tags terminating blocks prematurely. #22
95
+
96
+
97
+ === 4.0.1 / July 24, 2008
98
+
99
+ * Fixed lines starting with dashes being recognized as a definition list when there were no definitions.
100
+
101
+ * Created alias RedCloth.rb so Rails 2.1 gem dependency works on case-sensitive operating systems .
102
+ * Fixed parsing sentences that had two em dashes surrounded by spaces from becoming del phrases. #19
103
+
104
+ * Fixed links including prior quoted phrases. #17
105
+
106
+
107
+ === 4.0.0 / July 21, 2008
108
+
109
+ * New SuperRedCloth (RedCloth 4.0) is a total rewrite using Ragel for the parsing.
110
+
111
+ * Markdown support has been removed.
112
+
113
+ * Single newlines become <br> tags, just as in traditional RedCloth and other Textile parsers.
114
+
115
+ * 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.
116
+
117
+ * The restrictions parameter is observed just like previous versions (except :hard_breaks is now the default).
118
+
119
+ * 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.
120
+
121
+ * Custom block tags can be implemented as in the previous version, though the means of implementing them differs.
122
+
123
+ * HTML embedded in the Textile input does not often need to be escaped from Textile parsing.
124
+
125
+ * The parser will not wrap lines that begin with a space in paragraph tags.
126
+
127
+ * Rudimentary support for LaTeX is built in.
128
+
129
+ * RedCloth::VERSION on a line by itself inserts the version number into the output.
130
+
131
+ * Output (less newlines and tabs) is identical to Textile 2 except a few cases where the RedCloth way was preferable.
132
+
133
+ * Over 500 tests prevent regression
134
+
135
+ * 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,56 @@
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
+ setup.rb
33
+ test/basic.yml
34
+ test/code.yml
35
+ test/definitions.yml
36
+ test/extra_whitespace.yml
37
+ test/filter_html.yml
38
+ test/filter_pba.yml
39
+ test/helper.rb
40
+ test/html.yml
41
+ test/images.yml
42
+ test/instiki.yml
43
+ test/links.yml
44
+ test/lists.yml
45
+ test/poignant.yml
46
+ test/sanitize_html.yml
47
+ test/table.yml
48
+ test/test_custom_tags.rb
49
+ test/test_erb.rb
50
+ test/test_extensions.rb
51
+ test/test_formatters.rb
52
+ test/test_parser.rb
53
+ test/test_restrictions.rb
54
+ test/textism.yml
55
+ test/threshold.yml
56
+ test/validate_fixtures.rb
data/README ADDED
@@ -0,0 +1,171 @@
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
+ gem install RedCloth
19
+
20
+ It will install the appropriate Ruby, JRuby, or Win32 gem. If using JRuby, version 1.1.5 or greater is required.
21
+
22
+ == Compiling
23
+
24
+ If you just want to use RedCloth, you do NOT need to build/compile it. It is compiled from C sources automatically when you install the gem on the ruby platform. Binary gems are provided for JRuby and Win32 platforms.
25
+
26
+ RedCloth can be compiled with <tt>rake compile</tt>. Ragel 6.3 or greater and the
27
+ echoe gem are needed to build, compile, and package RedCloth. Again, Ragel and echoe are NOT needed to simply use RedCloth.
28
+
29
+ You can cross-compile for JRuby with rake java compile and for Win32 with rake mingw compile.
30
+
31
+ == Using RedCloth
32
+
33
+ RedCloth is simply an extension of the String class, which can handle
34
+ Textile formatting. Use it like a String and output HTML with its
35
+ RedCloth#to_html method.
36
+
37
+ Simple use:
38
+ text = "This is *my* text."
39
+ RedCloth.new(text).to_html
40
+
41
+ Multi-line example:
42
+
43
+ doc = RedCloth.new <<EOD
44
+ h2. Test document
45
+
46
+ Just a simple test.
47
+ EOD
48
+ puts doc.to_html
49
+
50
+
51
+ == What is Textile?
52
+
53
+ Textile is a simple formatting style for text
54
+ documents, loosely based on some HTML conventions.
55
+
56
+ == Sample Textile Text
57
+
58
+ h2. This is a title
59
+
60
+ h3. This is a subhead
61
+
62
+ This is a bit of paragraph.
63
+
64
+ bq. This is a blockquote.
65
+
66
+ = Writing Textile
67
+
68
+ A Textile document consists of paragraphs. Paragraphs
69
+ can be specially formatted by adding a small instruction
70
+ to the beginning of the paragraph.
71
+
72
+ h3. Header 3.
73
+ bq. Blockquote.
74
+ # Numeric list.
75
+ * Bulleted list.
76
+
77
+ == Quick Phrase Modifiers
78
+
79
+ Quick phrase modifiers are also included, to allow formatting
80
+ of small portions of text within a paragraph.
81
+
82
+ _emphasis_
83
+ __italicized__
84
+ *strong*
85
+ **bold**
86
+ ??citation??
87
+ -deleted text-
88
+ +inserted text+
89
+ ^superscript^
90
+ ~subscript~
91
+ @code@
92
+ %(classname)span%
93
+
94
+ ==notextile== (leave text alone)
95
+
96
+ == Links
97
+
98
+ To make a hypertext link, put the link text in "quotation
99
+ marks" followed immediately by a colon and the URL of the link.
100
+
101
+ Optional: text in (parentheses) following the link text,
102
+ but before the closing quotation mark, will become a title
103
+ attribute for the link, visible as a tool tip when a cursor is above it.
104
+
105
+ Example:
106
+
107
+ "This is a link (This is a title)":http://www.textism.com
108
+
109
+ Will become:
110
+
111
+ <a href="http://www.textism.com" title="This is a title">This is a link</a>
112
+
113
+ == Images
114
+
115
+ To insert an image, put the URL for the image inside exclamation marks.
116
+
117
+ Optional: text that immediately follows the URL in (parentheses) will
118
+ be used as the Alt text for the image. Images on the web should always
119
+ have descriptive Alt text for the benefit of readers using non-graphical
120
+ browsers.
121
+
122
+ Optional: place a colon followed by a URL immediately after the
123
+ closing ! to make the image into a link.
124
+
125
+ Example:
126
+
127
+ !http://www.textism.com/common/textist.gif(Textist)!
128
+
129
+ Will become:
130
+
131
+ <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
132
+
133
+ With a link:
134
+
135
+ !/common/textist.gif(Textist)!:http://textism.com
136
+
137
+ Will become:
138
+
139
+ <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
140
+
141
+ == Defining Acronyms
142
+
143
+ HTML allows authors to define acronyms via the tag. The definition appears as a
144
+ tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
145
+ this should be used at least once for each acronym in documents where they appear.
146
+
147
+ To quickly define an acronym in Textile, place the full text in (parentheses)
148
+ immediately following the acronym.
149
+
150
+ Example:
151
+
152
+ ACLU(American Civil Liberties Union)
153
+
154
+ Will become:
155
+
156
+ <acronym title="American Civil Liberties Union">ACLU</acronym>
157
+
158
+ == Adding Tables
159
+
160
+ In Textile, simple tables can be added by separating each column by
161
+ a pipe.
162
+
163
+ |a|simple|table|row|
164
+ |And|Another|table|row|
165
+
166
+ Styles are applied with curly braces.
167
+
168
+ table{border:1px solid black}.
169
+ {background:#ddd;color:red}. |a|red|row|
170
+
171
+
@@ -0,0 +1,205 @@
1
+ require 'lib/redcloth/version'
2
+ require 'rubygems'
3
+ gem 'echoe', '>= 3.0.1'
4
+ require 'echoe'
5
+
6
+ e = Echoe.new('RedCloth', RedCloth::VERSION.to_s) do |p|
7
+ p.summary = RedCloth::DESCRIPTION
8
+ p.author = "Jason Garber"
9
+ p.email = 'redcloth-upwards@rubyforge.org'
10
+ 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']
11
+ p.url = "http://redcloth.org"
12
+ p.project = "redcloth"
13
+ p.rdoc_pattern = ['README', 'COPING', 'CHANGELOG', 'lib/**/*.rb', 'doc/**/*.rdoc']
14
+ p.ignore_pattern = /^(pkg|site|projects|doc|log)|CVS|\.log/
15
+ p.ruby_version = '>=1.8.4'
16
+ p.extension_pattern = nil
17
+
18
+ if Platform.gcc?
19
+ p.platform = 'x86-mswin32-60'
20
+ elsif Platform.java?
21
+ p.platform = 'universal-java'
22
+ end
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
+ when /java/
37
+ self.files += ['lib/redcloth_scan.jar']
38
+ else
39
+ self.files += %w[attributes inline scan].map {|f| "ext/redcloth_scan/redcloth_#{f}.c"}
40
+ end
41
+
42
+ self.require_paths << "lib/case_sensitive_require"
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