docubot 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmNkOTU4ZTVmMzM5OGI0YTA5MmFhYjk2NmQyNDQ2NThiYmY0NGFhZA==
4
+ ZGFiNGM1OGVhYmEwYTgzNzk0NTUxMzQwNTBiYTcxYWVmOGY3NjU0ZA==
5
5
  data.tar.gz: !binary |-
6
- MjIwYzA0MDAzOGYzMTU1ZWJlOTM2NGQ0NjZmYWEzZDUzM2YxYmFiOQ==
6
+ ZDU3ZWM0OWJlZWExMWIzOGE5YTJmYTQ2NDU3NGE1NjAzMjZkMDNkZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzAxYzhjYzFhYWEyMGEyY2FhZWMyOGJmNWZlZmZjYjQxZDYyY2M4ZTk2NTZj
10
- MzAzZmQ2ZmRkNmRjZDllNjRhMmY5MWZiOGRlZWNiZTg0OWRlMTc4NmZiMWU0
11
- MTU0MDc2NDQ0NDllMjE3YzZkNzJlMDk4MTlmZDljYWIyZTc2N2U=
9
+ N2JmOGYwY2E5YWQyNzI3MjM0NzI0ZDI1ODI2YmRhMTYyZjE3YWY0ODk1Y2Jj
10
+ YmNlYzlkOWMxMzgyODk3OWFiOGQ4YTZkYTAzY2Q5MWQyZmE1ZWNlM2NlNjVm
11
+ ZTkxZThhMzFjYTE4YjY4ZjYwZWIxYzQ2OThhNzg4MjMyNGY5YzY=
12
12
  data.tar.gz: !binary |-
13
- NzY5YTYwMTFkNzNiOTk4YWE2ODU4ZDY4YjhiYjUzMmJlMGZlMjQxZDEyNWQ3
14
- NDdiZDAxMGY1NWZhYzM5MmExNmViODViZTBlZjgwNGViNjY5YzdkZGI0ODdk
15
- ZWFiZmZiMDMwYjQwOTVjMDJlNzBkYWFjZWUxMTI4ZTZlZWEyM2Q=
13
+ ZjJhOTE5ZTcyMGY4ZDRhNzhhYTZiZjVhZmYzOWEzYTFiNjc2OWVlODMzMjc4
14
+ OWRlYjY3MTlmYzYxMDEzMTY0YzMyZDMxNTAwODc0OGM2ODY2YjhkOGQ5NDhl
15
+ ZTBiZmJhOWU2ZThmNzJjZGFjMDAxODI3YmFhZTcwNDExYTI4Y2U=
@@ -20,7 +20,7 @@ module FileUtils
20
20
  end
21
21
 
22
22
  module DocuBot
23
- VERSION = '1.1.4'
23
+ VERSION = '1.2.0'
24
24
  DIR = File.expand_path( File.dirname( __FILE__ ) )
25
25
 
26
26
  TEMPLATE_DIR = DIR / 'docubot/templates'
@@ -1,5 +1,25 @@
1
1
  # encoding: UTF-8
2
+ begin
3
+ require 'coderay'
4
+ rescue LoadError
5
+ warn "Unable to load coderay gem; code blocks will not support syntax highlighting."
6
+ warn "(Use gem install coderay to fix this, if you desire syntax highlighting.)"
7
+ end
8
+
2
9
  DocuBot::Converter.to_convert :html, :htm do |page, source_html|
3
- # TODO: If the html is inside a body, strip out the surrounds.
4
- source_html
10
+ body = Nokogiri.HTML( source_html ).at('body')
11
+ if page.meta.highlight!='off' && defined? CodeRay
12
+ @coderay_languages ||= {}.tap do |h|
13
+ # Valid as of CodeRay 1.1
14
+ langs = h[:all] = %w[cpp cplusplus ecmascript java_script ecma_script rhtml erb eruby irb ruby javascript js pascal delphi patch diff plain text plaintext xhtml html yml yaml default c css clojure debug java groovy haml json php python raydebug sql xml]
15
+ h[:regex] = /(?<=\A|\s)language-(#{Regexp.union(langs)})(?=\s|\z)/
16
+ h[:css] = langs.map{ |l| ".language-#{l}" }.join(',')
17
+ end
18
+ body.css(@coderay_languages[:css]).each do |possible|
19
+ if lang=possible['class'][@coderay_languages[:regex],1]
20
+ possible.inner_html = CodeRay.scan( possible.text, lang.to_sym ).html
21
+ end
22
+ end
23
+ end
24
+ body.inner_html
5
25
  end
@@ -2,7 +2,8 @@
2
2
  begin
3
3
  require 'kramdown'
4
4
  DocuBot::Converter.to_convert :md, :markdown do |page, source|
5
- Kramdown::Document.new(source,coderay_line_numbers:nil, coderay_css: :class).to_html
5
+ options = page.meta.highlight=='off' ? {enable_coderay:false} : {coderay_line_numbers:nil, coderay_css: :class}
6
+ Kramdown::Document.new(source,options).to_html
6
7
  end
7
8
  rescue LoadError
8
9
  warn "Unable to load kramdown gem; *.markdown/*.md markup will not be recognized as a page."
@@ -0,0 +1,45 @@
1
+ title: Highlighting HTML
2
+ +++
3
+ <p>Here's some HTML to highlight:</p>
4
+ <pre class="language-cpp">
5
+ #include &lt;AtlasUtils/Plugin.h&gt;
6
+ #include &lt;AtlasUtils/PluginRegistry.h&gt;
7
+
8
+ #include "Cube.h"
9
+
10
+ class CUBE_Plugin: public AtlasUtils::Plugin&lt;AtlasSG::NodePtr&gt;
11
+ {
12
+ public:
13
+ // The constructor calls the super-class constructor
14
+ // passing it the plug-in's name "cube"
15
+ CUBE_Plugin():
16
+ AtlasUtils::Plugin&lt;AtlasSG::NodePtr&gt;("cube")
17
+ {
18
+ }
19
+
20
+ // The read method will be called whenever a request is
21
+ // made to open a file with an extension ".cube"
22
+ virtual AtlasSG::NodePtr read( const std::string &amp;filename )
23
+ {
24
+ // Since this is a pseudo-plug-in we can ignore the filename
25
+
26
+ return AtlasSG::NodePtr( new Cube );
27
+ }
28
+
29
+ virtual bool write( AtlasSG::NodePtr, const std::string &amp;)
30
+ {
31
+ return false;
32
+ }
33
+ };
34
+
35
+
36
+ // The PLUGIN_PROXY macro instantiates an object of class CUBE_Plugin
37
+ // when the dynamic shared object is loaded.
38
+
39
+ PLUGIN_PROXY( CUBE_Plugin )
40
+ </pre>
41
+
42
+ <p>And here's an inline <code class="language-ruby">def call; end</code></p>
43
+ <p>Here's one that's left untouched: <code id="untouched1">def call; end</code></p>
44
+ <p>Here's another that's left untouched: <span id="untouched2" class="ruby">def call; end</span></p>
45
+
@@ -0,0 +1,47 @@
1
+ title: Highlighting Markdown
2
+ +++
3
+ Here's some code to highlight:
4
+
5
+ ~~~ cpp
6
+ #include <AtlasUtils/Plugin.h>
7
+ #include <AtlasUtils/PluginRegistry.h>
8
+
9
+ #include "Cube.h"
10
+
11
+ class CUBE_Plugin: public AtlasUtils::Plugin<AtlasSG::NodePtr>
12
+ {
13
+ public:
14
+ // The constructor calls the super-class constructor
15
+ // passing it the plug-in's name "cube"
16
+ CUBE_Plugin():
17
+ AtlasUtils::Plugin<AtlasSG::NodePtr>("cube")
18
+ {
19
+ }
20
+
21
+ // The read method will be called whenever a request is
22
+ // made to open a file with an extension ".cube"
23
+ virtual AtlasSG::NodePtr read( const std::string &amp;filename )
24
+ {
25
+ // Since this is a pseudo-plug-in we can ignore the filename
26
+
27
+ return AtlasSG::NodePtr( new Cube );
28
+ }
29
+
30
+ virtual bool write( AtlasSG::NodePtr, const std::string &amp;)
31
+ {
32
+ return false;
33
+ }
34
+ };
35
+
36
+
37
+ // The PLUGIN_PROXY macro instantiates an object of class CUBE_Plugin
38
+ // when the dynamic shared object is loaded.
39
+
40
+ PLUGIN_PROXY( CUBE_Plugin )
41
+ ~~~
42
+
43
+ And here's an inline `def call; end`{: .language-ruby} Ruby code.
44
+
45
+ Here's one that's left untouched: `def call; end`{: #untouched1}
46
+
47
+ Here's another that's left untouched: <span id="untouched2" class="language-ruby">def call; end</span>
@@ -0,0 +1,46 @@
1
+ title: Highlighting No HTML
2
+ highlight: off
3
+ +++
4
+ <p>Here's some HTML to highlight:</p>
5
+ <pre class="language-cpp">
6
+ #include &lt;AtlasUtils/Plugin.h&gt;
7
+ #include &lt;AtlasUtils/PluginRegistry.h&gt;
8
+
9
+ #include "Cube.h"
10
+
11
+ class CUBE_Plugin: public AtlasUtils::Plugin&lt;AtlasSG::NodePtr&gt;
12
+ {
13
+ public:
14
+ // The constructor calls the super-class constructor
15
+ // passing it the plug-in's name "cube"
16
+ CUBE_Plugin():
17
+ AtlasUtils::Plugin&lt;AtlasSG::NodePtr&gt;("cube")
18
+ {
19
+ }
20
+
21
+ // The read method will be called whenever a request is
22
+ // made to open a file with an extension ".cube"
23
+ virtual AtlasSG::NodePtr read( const std::string &amp;filename )
24
+ {
25
+ // Since this is a pseudo-plug-in we can ignore the filename
26
+
27
+ return AtlasSG::NodePtr( new Cube );
28
+ }
29
+
30
+ virtual bool write( AtlasSG::NodePtr, const std::string &amp;)
31
+ {
32
+ return false;
33
+ }
34
+ };
35
+
36
+
37
+ // The PLUGIN_PROXY macro instantiates an object of class CUBE_Plugin
38
+ // when the dynamic shared object is loaded.
39
+
40
+ PLUGIN_PROXY( CUBE_Plugin )
41
+ </pre>
42
+
43
+ <p>And here's an inline <code class="language-ruby">def call; end</code></p>
44
+ <p>Here's one that's left untouched: <code id="untouched1">def call; end</code></p>
45
+ <p>Here's another that's left untouched: <span id="untouched2" class="ruby">def call; end</span></p>
46
+
@@ -0,0 +1,48 @@
1
+ title: Highlighting No Markdown
2
+ highlight:off
3
+ +++
4
+ Here's some code to highlight:
5
+
6
+ ~~~ cpp
7
+ #include <AtlasUtils/Plugin.h>
8
+ #include <AtlasUtils/PluginRegistry.h>
9
+
10
+ #include "Cube.h"
11
+
12
+ class CUBE_Plugin: public AtlasUtils::Plugin<AtlasSG::NodePtr>
13
+ {
14
+ public:
15
+ // The constructor calls the super-class constructor
16
+ // passing it the plug-in's name "cube"
17
+ CUBE_Plugin():
18
+ AtlasUtils::Plugin<AtlasSG::NodePtr>("cube")
19
+ {
20
+ }
21
+
22
+ // The read method will be called whenever a request is
23
+ // made to open a file with an extension ".cube"
24
+ virtual AtlasSG::NodePtr read( const std::string &amp;filename )
25
+ {
26
+ // Since this is a pseudo-plug-in we can ignore the filename
27
+
28
+ return AtlasSG::NodePtr( new Cube );
29
+ }
30
+
31
+ virtual bool write( AtlasSG::NodePtr, const std::string &amp;)
32
+ {
33
+ return false;
34
+ }
35
+ };
36
+
37
+
38
+ // The PLUGIN_PROXY macro instantiates an object of class CUBE_Plugin
39
+ // when the dynamic shared object is loaded.
40
+
41
+ PLUGIN_PROXY( CUBE_Plugin )
42
+ ~~~
43
+
44
+ And here's an inline `def call; end`{: .language-ruby} Ruby code.
45
+
46
+ Here's one that's left untouched: `def call; end`{: #untouched1}
47
+
48
+ Here's another that's left untouched: <span id="untouched2" class="language-ruby">def call; end</span>
@@ -0,0 +1,51 @@
1
+ #encoding: UTF-8
2
+ require_relative '_helper'
3
+
4
+ describe "Applying syntax highlighting" do
5
+ before do
6
+ @bundle = DocuBot::Bundle.new SAMPLES/'highlighting'
7
+ end
8
+
9
+ it "should highlight code in HTML" do
10
+ doc = @bundle.pages.find{ |p| p.meta.title=="Highlighting HTML" }.nokodoc
11
+ cpp_class = doc.at_css('pre.language-cpp span.class')
12
+ cpp_class.wont_be_nil
13
+ cpp_class.text.must_equal "CUBE_Plugin"
14
+
15
+ ruby_key = doc.at_css('code.language-ruby span.keyword')
16
+ ruby_key.wont_be_nil
17
+ ruby_key.text.must_equal "def"
18
+ end
19
+
20
+ it "should highlight code in Markdown" do
21
+ doc = @bundle.pages.find{ |p| p.meta.title=="Highlighting Markdown" }.nokodoc
22
+ cpp_class = doc.at_css('pre span.class')
23
+ cpp_class.wont_be_nil
24
+ cpp_class.text.must_equal "CUBE_Plugin"
25
+
26
+ ruby_key = doc.at_css('code.language-ruby span.keyword')
27
+ ruby_key.wont_be_nil
28
+ ruby_key.text.must_equal "def"
29
+ end
30
+
31
+ it "should not highlight code without a matching class" do
32
+ %w[ HTML Markdown ].each do |title|
33
+ doc = @bundle.pages.find{ |p| p.meta.title=="Highlighting #{title}" }.nokodoc
34
+ no_touch = doc.at_css('#untouched1')
35
+ no_touch.wont_be_nil
36
+ no_touch.inner_html.must_equal "def call; end"
37
+ end
38
+ end
39
+
40
+ it "should not highlight if turned off" do
41
+ %w[ HTML Markdown ].each do |title|
42
+ doc = @bundle.pages.find{ |p| p.meta.title=="Highlighting No #{title}" }.nokodoc
43
+ cpp_class = doc.at_css('pre.language-cpp span.class')
44
+ cpp_class.must_be_nil
45
+
46
+ ruby_key = doc.at_css('code.language-ruby span.keyword')
47
+ ruby_key.must_be_nil
48
+ end
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docubot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Kistner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-05 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: coderay
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  description: DocuBot creates HTML or CHM documentation from a hierarchy of files,
85
99
  supporting markups like Markdown, Textile, and Haml.
86
100
  email: gavin@phrogz.net
@@ -255,6 +269,10 @@ files:
255
269
  - spec/samples/hierarchy/main.css
256
270
  - spec/samples/hierarchy/main.haml
257
271
  - spec/samples/hierarchy/toc.md
272
+ - spec/samples/highlighting/HTML.html
273
+ - spec/samples/highlighting/Markdown.md
274
+ - spec/samples/highlighting/NOHTML.html
275
+ - spec/samples/highlighting/NOMarkdown.md
258
276
  - spec/samples/links/index.txt
259
277
  - spec/samples/links/one two three.textile
260
278
  - spec/samples/links/pending.md
@@ -302,6 +320,7 @@ files:
302
320
  - spec/samples/underscores/_static/Foo/_ignoremore.txt
303
321
  - spec/samples/underscores/_static/_Bar/_ignoreevenmore.txt
304
322
  - spec/samples/underscores/subsection/_andignoreme.md
323
+ - spec/syntaxhighlighting.rb
305
324
  - spec/templates.rb
306
325
  - spec/toc.rb
307
326
  - spec/writer/chm.rb
@@ -331,6 +350,7 @@ requirements:
331
350
  - kramdown gem for Markdown conversion.
332
351
  - RedCloth gem for Textile conversion.
333
352
  - MiniTest gem for running specifications.
353
+ - CodeRay gem for syntax highlighting.
334
354
  rubyforge_project:
335
355
  rubygems_version: 2.2.2
336
356
  signing_key: