distil 0.14.4 → 0.14.5.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/VERSION +1 -1
  2. data/bin/distil +10 -0
  3. data/lib/distil/project.rb +10 -7
  4. data/lib/distil/source-file.rb +1 -1
  5. metadata +28 -164
  6. data/Buildfile +0 -33
  7. data/distil.gemspec +0 -783
  8. data/lib/distil/javascript-documentation-generator.rb +0 -49
  9. data/vendor/pdoc/LICENSE +0 -16
  10. data/vendor/pdoc/PDoc.tmbundle/Commands/Continue PDoc Comment.tmCommand +0 -39
  11. data/vendor/pdoc/PDoc.tmbundle/Macros/Collapse PDoc Blocks.tmMacro +0 -4084
  12. data/vendor/pdoc/PDoc.tmbundle/Macros/Expand PDoc Blocks.tmMacro +0 -1388
  13. data/vendor/pdoc/PDoc.tmbundle/Preferences/PDoc.tmPreferences +0 -50
  14. data/vendor/pdoc/PDoc.tmbundle/Snippets/class.tmSnippet +0 -24
  15. data/vendor/pdoc/PDoc.tmbundle/Snippets/constant.tmSnippet +0 -22
  16. data/vendor/pdoc/PDoc.tmbundle/Snippets/event.tmSnippet +0 -16
  17. data/vendor/pdoc/PDoc.tmbundle/Snippets/method.tmSnippet +0 -22
  18. data/vendor/pdoc/PDoc.tmbundle/Snippets/mixin.tmSnippet +0 -23
  19. data/vendor/pdoc/PDoc.tmbundle/Snippets/namespace.tmSnippet +0 -24
  20. data/vendor/pdoc/PDoc.tmbundle/Snippets/param.tmSnippet +0 -16
  21. data/vendor/pdoc/PDoc.tmbundle/Snippets/property.tmSnippet +0 -22
  22. data/vendor/pdoc/PDoc.tmbundle/Snippets/section.tmSnippet +0 -23
  23. data/vendor/pdoc/PDoc.tmbundle/Syntaxes/PDoc.tmLanguage +0 -33
  24. data/vendor/pdoc/PDoc.tmbundle/info.plist +0 -22
  25. data/vendor/pdoc/README.markdown +0 -34
  26. data/vendor/pdoc/Rakefile +0 -46
  27. data/vendor/pdoc/bin/pdoc +0 -58
  28. data/vendor/pdoc/lib/pdoc.rb +0 -32
  29. data/vendor/pdoc/lib/pdoc/error.rb +0 -4
  30. data/vendor/pdoc/lib/pdoc/generators.rb +0 -6
  31. data/vendor/pdoc/lib/pdoc/generators/abstract_generator.rb +0 -16
  32. data/vendor/pdoc/lib/pdoc/generators/html.rb +0 -8
  33. data/vendor/pdoc/lib/pdoc/generators/html/helpers.rb +0 -256
  34. data/vendor/pdoc/lib/pdoc/generators/html/page.rb +0 -71
  35. data/vendor/pdoc/lib/pdoc/generators/html/syntax_highlighter.rb +0 -41
  36. data/vendor/pdoc/lib/pdoc/generators/html/template.rb +0 -37
  37. data/vendor/pdoc/lib/pdoc/generators/html/website.rb +0 -194
  38. data/vendor/pdoc/lib/pdoc/generators/json.rb +0 -15
  39. data/vendor/pdoc/lib/pdoc/generators/pythonesque.rb +0 -105
  40. data/vendor/pdoc/lib/pdoc/models.rb +0 -47
  41. data/vendor/pdoc/lib/pdoc/models/argument.rb +0 -37
  42. data/vendor/pdoc/lib/pdoc/models/base.rb +0 -107
  43. data/vendor/pdoc/lib/pdoc/models/callable.rb +0 -19
  44. data/vendor/pdoc/lib/pdoc/models/class.rb +0 -28
  45. data/vendor/pdoc/lib/pdoc/models/class_method.rb +0 -18
  46. data/vendor/pdoc/lib/pdoc/models/class_property.rb +0 -9
  47. data/vendor/pdoc/lib/pdoc/models/constant.rb +0 -9
  48. data/vendor/pdoc/lib/pdoc/models/constructor.rb +0 -14
  49. data/vendor/pdoc/lib/pdoc/models/container.rb +0 -114
  50. data/vendor/pdoc/lib/pdoc/models/entity.rb +0 -54
  51. data/vendor/pdoc/lib/pdoc/models/instance_method.rb +0 -18
  52. data/vendor/pdoc/lib/pdoc/models/instance_property.rb +0 -9
  53. data/vendor/pdoc/lib/pdoc/models/mixin.rb +0 -10
  54. data/vendor/pdoc/lib/pdoc/models/namespace.rb +0 -10
  55. data/vendor/pdoc/lib/pdoc/models/root.rb +0 -27
  56. data/vendor/pdoc/lib/pdoc/models/section.rb +0 -19
  57. data/vendor/pdoc/lib/pdoc/models/signature.rb +0 -27
  58. data/vendor/pdoc/lib/pdoc/models/utility.rb +0 -11
  59. data/vendor/pdoc/lib/pdoc/parser.rb +0 -109
  60. data/vendor/pdoc/lib/pdoc/parser/argument_description_nodes.rb +0 -21
  61. data/vendor/pdoc/lib/pdoc/parser/basic_nodes.rb +0 -31
  62. data/vendor/pdoc/lib/pdoc/parser/description_nodes.rb +0 -42
  63. data/vendor/pdoc/lib/pdoc/parser/documentation_nodes.rb +0 -483
  64. data/vendor/pdoc/lib/pdoc/parser/ebnf_arguments_nodes.rb +0 -58
  65. data/vendor/pdoc/lib/pdoc/parser/ebnf_expression_nodes.rb +0 -227
  66. data/vendor/pdoc/lib/pdoc/parser/fragment.rb +0 -55
  67. data/vendor/pdoc/lib/pdoc/parser/section_content_nodes.rb +0 -19
  68. data/vendor/pdoc/lib/pdoc/parser/tags_nodes.rb +0 -14
  69. data/vendor/pdoc/lib/pdoc/parser/treetop_files/argument_description.treetop +0 -31
  70. data/vendor/pdoc/lib/pdoc/parser/treetop_files/basic.treetop +0 -41
  71. data/vendor/pdoc/lib/pdoc/parser/treetop_files/description.treetop +0 -7
  72. data/vendor/pdoc/lib/pdoc/parser/treetop_files/documentation.treetop +0 -75
  73. data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_arguments.treetop +0 -33
  74. data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_expression.treetop +0 -70
  75. data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_javascript.treetop +0 -54
  76. data/vendor/pdoc/lib/pdoc/parser/treetop_files/events.treetop +0 -17
  77. data/vendor/pdoc/lib/pdoc/parser/treetop_files/section_content.treetop +0 -8
  78. data/vendor/pdoc/lib/pdoc/parser/treetop_files/tags.treetop +0 -31
  79. data/vendor/pdoc/lib/pdoc/runner.rb +0 -110
  80. data/vendor/pdoc/lib/pdoc/treemaker.rb +0 -94
  81. data/vendor/pdoc/pdoc.gemspec +0 -31
  82. data/vendor/pdoc/templates/html/assets/images/pdoc/alias.png +0 -0
  83. data/vendor/pdoc/templates/html/assets/images/pdoc/class.png +0 -0
  84. data/vendor/pdoc/templates/html/assets/images/pdoc/class_deprecated.png +0 -0
  85. data/vendor/pdoc/templates/html/assets/images/pdoc/class_method.png +0 -0
  86. data/vendor/pdoc/templates/html/assets/images/pdoc/class_property.png +0 -0
  87. data/vendor/pdoc/templates/html/assets/images/pdoc/constant.png +0 -0
  88. data/vendor/pdoc/templates/html/assets/images/pdoc/constructor.png +0 -0
  89. data/vendor/pdoc/templates/html/assets/images/pdoc/deprecated.png +0 -0
  90. data/vendor/pdoc/templates/html/assets/images/pdoc/description.png +0 -0
  91. data/vendor/pdoc/templates/html/assets/images/pdoc/information.png +0 -0
  92. data/vendor/pdoc/templates/html/assets/images/pdoc/instance_method.png +0 -0
  93. data/vendor/pdoc/templates/html/assets/images/pdoc/instance_property.png +0 -0
  94. data/vendor/pdoc/templates/html/assets/images/pdoc/method.png +0 -0
  95. data/vendor/pdoc/templates/html/assets/images/pdoc/method_deprecated.png +0 -0
  96. data/vendor/pdoc/templates/html/assets/images/pdoc/mixin.png +0 -0
  97. data/vendor/pdoc/templates/html/assets/images/pdoc/namespace.png +0 -0
  98. data/vendor/pdoc/templates/html/assets/images/pdoc/property.png +0 -0
  99. data/vendor/pdoc/templates/html/assets/images/pdoc/related_to.png +0 -0
  100. data/vendor/pdoc/templates/html/assets/images/pdoc/search-background.png +0 -0
  101. data/vendor/pdoc/templates/html/assets/images/pdoc/section-background.png +0 -0
  102. data/vendor/pdoc/templates/html/assets/images/pdoc/section.png +0 -0
  103. data/vendor/pdoc/templates/html/assets/images/pdoc/selected-section-background.png +0 -0
  104. data/vendor/pdoc/templates/html/assets/images/pdoc/subclass.png +0 -0
  105. data/vendor/pdoc/templates/html/assets/images/pdoc/superclass.png +0 -0
  106. data/vendor/pdoc/templates/html/assets/images/pdoc/utility.png +0 -0
  107. data/vendor/pdoc/templates/html/assets/javascripts/pdoc/application.js +0 -478
  108. data/vendor/pdoc/templates/html/assets/javascripts/pdoc/prototype.js +0 -4874
  109. data/vendor/pdoc/templates/html/assets/javascripts/pdoc/tabs.js +0 -506
  110. data/vendor/pdoc/templates/html/assets/stylesheets/pdoc/api.css +0 -677
  111. data/vendor/pdoc/templates/html/assets/stylesheets/pdoc/pygments.css +0 -62
  112. data/vendor/pdoc/templates/html/helpers.rb +0 -35
  113. data/vendor/pdoc/templates/html/index.erb +0 -18
  114. data/vendor/pdoc/templates/html/item_index.js.erb +0 -6
  115. data/vendor/pdoc/templates/html/layout.erb +0 -67
  116. data/vendor/pdoc/templates/html/leaf.erb +0 -22
  117. data/vendor/pdoc/templates/html/node.erb +0 -30
  118. data/vendor/pdoc/templates/html/partials/class_relationships.erb +0 -19
  119. data/vendor/pdoc/templates/html/partials/classes.erb +0 -7
  120. data/vendor/pdoc/templates/html/partials/constructor.erb +0 -5
  121. data/vendor/pdoc/templates/html/partials/description.erb +0 -5
  122. data/vendor/pdoc/templates/html/partials/link_list.erb +0 -1
  123. data/vendor/pdoc/templates/html/partials/method_signatures.erb +0 -14
  124. data/vendor/pdoc/templates/html/partials/methodized_note.erb +0 -9
  125. data/vendor/pdoc/templates/html/partials/mixins.erb +0 -7
  126. data/vendor/pdoc/templates/html/partials/namespaces.erb +0 -7
  127. data/vendor/pdoc/templates/html/partials/related_utilities.erb +0 -5
  128. data/vendor/pdoc/templates/html/partials/relationships.erb +0 -11
  129. data/vendor/pdoc/templates/html/partials/short_description_list.erb +0 -7
  130. data/vendor/pdoc/templates/html/partials/title.erb +0 -22
  131. data/vendor/pdoc/templates/html/section.erb +0 -18
  132. data/vendor/pdoc/test/fixtures/ajax.js +0 -809
  133. data/vendor/pdoc/test/fixtures/prototype.js +0 -5789
  134. data/vendor/pdoc/test/fixtures/test.txt +0 -1
  135. data/vendor/pdoc/test/fixtures/text.txt +0 -13
  136. data/vendor/pdoc/test/unit/parser/argument_description_test.rb +0 -40
  137. data/vendor/pdoc/test/unit/parser/basic_test.rb +0 -55
  138. data/vendor/pdoc/test/unit/parser/description_test.rb +0 -34
  139. data/vendor/pdoc/test/unit/parser/documentation_test.rb +0 -520
  140. data/vendor/pdoc/test/unit/parser/ebnf_arguments_test.rb +0 -81
  141. data/vendor/pdoc/test/unit/parser/ebnf_expression_test.rb +0 -382
  142. data/vendor/pdoc/test/unit/parser/ebnf_javascript_test.rb +0 -37
  143. data/vendor/pdoc/test/unit/parser/events_test.rb +0 -27
  144. data/vendor/pdoc/test/unit/parser/section_content_test.rb +0 -44
  145. data/vendor/pdoc/test/unit/parser/tags_test.rb +0 -39
  146. data/vendor/pdoc/test/unit/parser/test_fragment.rb +0 -80
  147. data/vendor/pdoc/test/unit/parser_test_helper.rb +0 -62
  148. data/vendor/pdoc/test/unit/runner/basic_test.rb +0 -14
  149. data/vendor/pdoc/test/unit/templates/html_helpers_test.rb +0 -25
  150. data/vendor/pdoc/vendor/albino.rb +0 -122
  151. data/vendor/pdoc/website/html/documentation.html +0 -280
  152. data/vendor/pdoc/website/html/images/pdoc.jpg +0 -0
  153. data/vendor/pdoc/website/html/index.html +0 -84
  154. data/vendor/pdoc/website/html/stylesheets/main.css +0 -73
  155. data/vendor/pdoc/website/html/stylesheets/reset.css +0 -18
  156. data/vendor/pdoc/website/markdown/syntax.markdown +0 -226
  157. data/yuicompressor-2.4.6.zip +0 -0
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
-
3
- class EbnfJavascriptTest < Test::Unit::TestCase
4
- include PDocTestHelper
5
-
6
- def setup
7
- @parser = EbnfJavascriptParser.new
8
- end
9
-
10
- def test_variable
11
- assert_parsed "innerHTML"
12
- assert_parsed "extended"
13
- assert_parsed "getElementsByClassName"
14
- end
15
-
16
- def test_constant
17
- assert_parsed "Element"
18
- assert_parsed "DefaultOptions"
19
- end
20
-
21
- def test_all_caps_constant
22
- assert_parsed "CSS"
23
- assert_parsed "KEY_BACKSPACE"
24
- end
25
-
26
- def test_object # basic and non-recursive
27
- assert_parsed "{}"
28
- assert_parsed "{foo: 'bar'}"
29
- end
30
-
31
- def test_namespace # basic and non-recursive
32
- assert_parsed "Foo.Bar"
33
- assert_parsed "foo.bar"
34
- assert_parsed "foo.Bar"
35
- assert_parsed "Foo.bar"
36
- end
37
- end
@@ -1,27 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
-
3
- class EventsTest < Test::Unit::TestCase
4
- include PDocTestHelper
5
-
6
- def setup
7
- @parser = EventsParser.new
8
- end
9
-
10
- def test_single_event
11
- fixture = "\n * fires click"
12
- assert_parsed fixture
13
- assert_equal %w[click], parse(fixture).to_a
14
- end
15
-
16
- def test_single_namespaced_event
17
- fixture = "\n * fires element:updated"
18
- assert_parsed fixture
19
- assert_equal %w[element:updated], parse(fixture).to_a
20
- end
21
-
22
- def test_multiple_events
23
- fixture = "\n * fires click, element:updated"
24
- assert_parsed fixture
25
- assert_equal %w[click element:updated], parse(fixture).to_a
26
- end
27
- end
@@ -1,44 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
-
3
- class SectionContentTest < Test::Unit::TestCase
4
- include PDocTestHelper
5
- include Basic
6
- include Description
7
- include SectionContent
8
-
9
- def setup
10
- @parser = SectionContentParser.new
11
- end
12
-
13
- def test_parsing
14
- assert_parsed "\n* ==dom==\n * hello"
15
- assert_parsed "\n* == dom == \n * hello"
16
- end
17
-
18
- def test_section
19
- text = "\n* == dom == \n * hello"
20
- assert_equal Section, parse(text).class
21
- end
22
-
23
- def test_title
24
- text = "\n* == DOM == \n * hello"
25
- assert_equal "DOM", parse(text).name
26
- assert_equal "DOM", parse(text).full_name
27
- assert_equal "dom", parse(text).id
28
-
29
- text = "\n* == Some Section == \n * hello"
30
- assert_equal "Some Section", parse(text).name
31
- assert_equal "Some Section", parse(text).full_name
32
- assert_equal "some_section", parse(text).id
33
-
34
- text = "\n* == scripty2 == \n * hello"
35
- assert_equal "scripty2", parse(text).name
36
- assert_equal "scripty2", parse(text).full_name
37
- assert_equal "scripty2", parse(text).id
38
- end
39
-
40
- def test_description
41
- text = "\n* == Some Section == \n * hello"
42
- assert_equal "hello", parse(text).description
43
- end
44
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
-
3
- class TagsTest < Test::Unit::TestCase
4
- include PDocTestHelper
5
-
6
- def setup
7
- @parser = TagsParser.new
8
- end
9
-
10
- def test_valueless_tag
11
- tag = "deprecated"
12
- assert_parsed tag
13
- assert_equal "deprecated", parse(tag).to_a.first.name
14
- assert_equal nil, parse(tag).to_a.first.value
15
- end
16
-
17
- def test_tag_with_value
18
- tag = "section: dom"
19
- assert_parsed tag
20
- assert_equal "section", parse(tag).to_a.first.name
21
- assert_equal "dom", parse(tag).to_a.first.value
22
-
23
- tag = "alias of: $A"
24
- assert_parsed tag
25
- assert_equal "alias of", parse(tag).to_a.first.name
26
- assert_equal "$A", parse(tag).to_a.first.value
27
- end
28
-
29
- def test_tags
30
- tags = "deprecated, alias of: $A"
31
- assert_parsed tags
32
- assert_equal "deprecated", parse(tags).to_a.first.name
33
- assert_equal nil, parse(tags).to_a.first.value
34
- assert_equal "alias of", parse(tags).to_a.last.name
35
- assert_equal "$A", parse(tags).to_a.last.value
36
- assert parse(tags).include?("deprecated")
37
- assert !parse(tags).include?("foo")
38
- end
39
- end
@@ -1,80 +0,0 @@
1
- require "test/unit"
2
- require "../../../lib/pdoc/parser/fragment"
3
- require "../../../lib/pdoc/error"
4
-
5
- class TestFragment < Test::Unit::TestCase
6
-
7
- def test_normalize_empty_fragment
8
- fragment =<<EOF
9
- /**
10
- *
11
- *
12
- **/
13
- EOF
14
- fragment = PDoc::Fragment.new(fragment, 0)
15
- lines = fragment.normalize
16
- assert_equal("", lines[0])
17
- assert_equal("", lines[1])
18
- assert_equal("", lines.last)
19
- end
20
-
21
- def test_normalize_basic_fragment
22
- fragment =<<EOF
23
- /**
24
- * foo
25
- * bar
26
- **/
27
- EOF
28
- fragment = PDoc::Fragment.new(fragment, 0)
29
- lines = fragment.normalize
30
- assert_equal("", lines[0])
31
- assert_equal("foo", lines[1])
32
- assert_equal(" bar", lines[2])
33
- assert_equal("", lines.last)
34
- end
35
-
36
- def test_normalize_broken_fragment
37
- fragment =<<EOF
38
- /**
39
- * foo
40
- *bar
41
- **/
42
- EOF
43
- assert_raise PDoc::Fragment::InconsistentPrefixError do
44
- PDoc::Fragment.new(fragment, 0).normalize
45
- end
46
- end
47
-
48
- def test_empty_prefix
49
- fragment =<<EOF
50
- /**
51
- foo
52
- bar
53
- **/
54
- EOF
55
- fragment = PDoc::Fragment.new(fragment, 0)
56
- assert_equal("", fragment.prefix)
57
- end
58
-
59
- def test_whitespace_prefix
60
- fragment =<<EOF
61
- /**
62
- foo
63
- bar
64
- **/
65
- EOF
66
- fragment = PDoc::Fragment.new(fragment, 0)
67
- assert_equal(" ", fragment.prefix)
68
- end
69
-
70
- def test_mixed_prefix
71
- fragment =<<EOF
72
- /**
73
- * foo
74
- * bar
75
- **/
76
- EOF
77
- fragment = PDoc::Fragment.new(fragment, 0)
78
- assert_equal(" * ", fragment.prefix)
79
- end
80
- end
@@ -1,62 +0,0 @@
1
- require 'test/unit'
2
-
3
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "pdoc")) unless defined?(PDoc)
4
-
5
- class Treetop::Runtime::SyntaxNode
6
- def method_missing(method, *args)
7
- raise "Node representing '#{text_value}' does not respond to '#{method}'"
8
- end
9
- end
10
-
11
- module PDocTestHelper
12
- def parse(input)
13
- result = @parser.parse(input)
14
- unless result
15
- puts "\n" << @parser.terminal_failures.join("\n") << "\n"
16
- end
17
- assert !result.nil?
18
- result
19
- end
20
-
21
- def blank_line
22
- "\n * \n "
23
- end
24
-
25
- def parse_file(filename)
26
- path = File.expand_path(File.join(File.dirname(__FILE__), "..", "fixtures", filename))
27
- file = File.open(path){ |f| f.read }
28
- file.gsub!(/\r\n/, "\n")
29
- file = file.split("\n").map do |line|
30
- line.gsub(/\s+$/, '')
31
- end.join("\n")
32
- parse(file)
33
- end
34
-
35
- def assert_parsed(input)
36
- assert !parse(input).nil?
37
- end
38
-
39
- def assert_file_parsed(filename)
40
- assert !parse_file(filename).nil?
41
- end
42
-
43
- def assert_not_parsed(input)
44
- assert @parser.parse(input).nil?
45
- end
46
- end
47
-
48
- # Stolen from Rails
49
- unless :test.respond_to?(:to_proc)
50
- class Symbol
51
- # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
52
- #
53
- # # The same as people.collect { |p| p.name }
54
- # people.collect(&:name)
55
- #
56
- # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
57
- # people.select(&:manager?).collect(&:salary)
58
- def to_proc
59
- Proc.new { |*args| args.shift.__send__(self, *args) }
60
- end
61
- end
62
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
-
3
- class BasicTest < Test::Unit::TestCase
4
-
5
- def test_restores_original_dir
6
- original_dir = Dir.pwd
7
- puts "*** #{original_dir}"
8
- PDoc::Runner.new("test/fixtures/test.txt",
9
- :output => 'test/output',
10
- :templates => 'templates/html'
11
- ).run
12
- assert_equal original_dir, Dir.pwd
13
- end
14
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "parser_test_helper"))
2
- require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. templates html helpers]))
3
-
4
- class HtmlHelpersTest < Test::Unit::TestCase
5
- include PDocTestHelper
6
- # include EbnfExpression
7
-
8
- def setup
9
- @helper = Object.new
10
- class << @helper
11
- attr_accessor :root
12
- include PDoc::Generators::Html::Helpers::BaseHelper
13
- include PDoc::Generators::Html::Helpers::LinkHelper
14
- include PDoc::Generators::Html::Helpers::CodeHelper
15
-
16
- def path_to(foo)
17
- '/some/path' # Not tested here, although it should
18
- end
19
- end
20
- end
21
-
22
- def test_truth
23
- assert true
24
- end
25
- end
@@ -1,122 +0,0 @@
1
- ##
2
- # Wrapper for the Pygments command line tool, pygmentize.
3
- #
4
- # Pygments: http://pygments.org/
5
- #
6
- # Assumes pygmentize is in the path. If not, set its location
7
- # with Albino.bin = '/path/to/pygmentize'
8
- #
9
- # Use like so:
10
- #
11
- # @syntaxer = Albino.new('/some/file.rb', :ruby)
12
- # puts @syntaxer.colorize
13
- #
14
- # This'll print out an HTMLized, Ruby-highlighted version
15
- # of '/some/file.rb'.
16
- #
17
- # To use another formatter, pass it as the third argument:
18
- #
19
- # @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode)
20
- # puts @syntaxer.colorize
21
- #
22
- # You can also use the #colorize class method:
23
- #
24
- # puts Albino.colorize('/some/file.rb', :ruby)
25
- #
26
- # Another also: you get a #to_s, for somewhat nicer use in Rails views.
27
- #
28
- # ... helper file ...
29
- # def highlight(text)
30
- # Albino.new(text, :ruby)
31
- # end
32
- #
33
- # ... view file ...
34
- # <%= highlight text %>
35
- #
36
- # The default lexer is 'text'. You need to specify a lexer yourself;
37
- # because we are using STDIN there is no auto-detect.
38
- #
39
- # To see all lexers and formatters available, run `pygmentize -L`.
40
- #
41
- # Chris Wanstrath // chris@ozmm.org
42
- # GitHub // http://github.com
43
- #
44
- require 'open4'
45
-
46
- class Albino
47
- @@bin = Rails.development? ? 'pygmentize' : '/usr/bin/pygmentize' rescue 'pygmentize'
48
-
49
- def self.bin=(path)
50
- @@bin = path
51
- end
52
-
53
- def self.colorize(*args)
54
- new(*args).colorize
55
- end
56
-
57
- def initialize(target, lexer = :text, format = :html)
58
- @target = File.exists?(target) ? File.read(target) : target rescue target
59
- @options = { :l => lexer, :f => format, :O => 'encoding=utf-8' }
60
- end
61
-
62
- def execute(command)
63
- output = ''
64
- Open4.popen4(command) do |pid, stdin, stdout, stderr|
65
- stdin.puts @target
66
- stdin.close
67
- output = stdout.read.strip
68
- [stdout, stderr].each { |io| io.close }
69
- end
70
- output
71
- end
72
-
73
- def colorize(options = {})
74
- html = execute(@@bin + convert_options(options))
75
- # Work around an RDiscount bug: http://gist.github.com/97682
76
- html.to_s.sub(%r{</pre></div>\Z}, "</pre>\n</div>")
77
- end
78
- alias_method :to_s, :colorize
79
-
80
- def convert_options(options = {})
81
- @options.merge(options).inject('') do |string, (flag, value)|
82
- string + " -#{flag} #{value}"
83
- end
84
- end
85
- end
86
-
87
- if $0 == __FILE__
88
- require 'rubygems'
89
- require 'test/spec'
90
- require 'mocha'
91
- begin require 'redgreen'; rescue LoadError; end
92
-
93
- context "Albino" do
94
- setup do
95
- @syntaxer = Albino.new(__FILE__, :ruby)
96
- end
97
-
98
- specify "defaults to text" do
99
- syntaxer = Albino.new(__FILE__)
100
- syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
101
- syntaxer.colorize
102
- end
103
-
104
- specify "accepts options" do
105
- @syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
106
- @syntaxer.colorize
107
- end
108
-
109
- specify "works with strings" do
110
- syntaxer = Albino.new('class New; end', :ruby)
111
- assert_match %r(highlight), syntaxer.colorize
112
- end
113
-
114
- specify "aliases to_s" do
115
- assert_equal @syntaxer.colorize, @syntaxer.to_s
116
- end
117
-
118
- specify "class method colorize" do
119
- assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
120
- end
121
- end
122
- end