rocco 0.7 → 0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES.md CHANGED
@@ -1,6 +1,16 @@
1
1
  CHANGES
2
2
  =======
3
3
 
4
+ 0.8 (2011-06-19)
5
+ ----------------
6
+
7
+ https://github.com/rtomayko/rocco/compare/0.7...0.8
8
+
9
+ 0.7 (2011-05-22)
10
+ ----------------
11
+
12
+ https://github.com/rtomayko/rocco/compare/0.6...0.7
13
+
4
14
  0.6 (2011-03-05)
5
15
  ----------------
6
16
 
@@ -31,16 +31,15 @@
31
31
 
32
32
  #### Prerequisites
33
33
 
34
- # We'll need a Markdown library. [RDiscount][rd], if we're lucky. Otherwise,
35
- # issue a warning and fall back on using BlueCloth.
36
- #
37
- # [rd]: http://github.com/rtomayko/rdiscount
38
- begin
39
- require 'rdiscount'
40
- rescue LoadError => boom
41
- warn "WARNING: #{boom}. Trying bluecloth."
42
- require 'bluecloth'
43
- Markdown = BlueCloth
34
+ # We'll need a Markdown library. Try to load one if not already established.
35
+ if !defined?(Markdown)
36
+ libs = %w[redcarpet rdiscount bluecloth]
37
+ begin
38
+ require libs.shift
39
+ rescue LoadError => boom
40
+ retry if libs.any?
41
+ raise
42
+ end
44
43
  end
45
44
 
46
45
  # We use [{{ mustache }}](http://defunkt.github.com/mustache/) for
@@ -73,7 +72,7 @@ end
73
72
  # to `nil` (that is, Mustache will use `./lib/rocco/layout.mustache`)_.
74
73
  #
75
74
  class Rocco
76
- VERSION = '0.7'
75
+ VERSION = '0.8'
77
76
 
78
77
  def initialize(filename, sources=[], options={}, &block)
79
78
  @file = filename
@@ -207,56 +206,8 @@ class Rocco
207
206
  #
208
207
  # At the moment, we're only returning `:single`. Consider this
209
208
  # groundwork for block comment parsing.
210
- C_STYLE_COMMENTS = {
211
- :single => "//",
212
- :multi => { :start => "/**", :middle => "*", :end => "*/" },
213
- :heredoc => nil
214
- }
215
- COMMENT_STYLES = {
216
- "bash" => { :single => "#", :multi => nil },
217
- "c" => C_STYLE_COMMENTS,
218
- "coffee-script" => {
219
- :single => "#",
220
- :multi => { :start => "###", :middle => nil, :end => "###" },
221
- :heredoc => nil
222
- },
223
- "cpp" => C_STYLE_COMMENTS,
224
- "csharp" => C_STYLE_COMMENTS,
225
- "css" => {
226
- :single => nil,
227
- :multi => { :start => "/**", :middle => "*", :end => "*/" },
228
- :heredoc => nil
229
- },
230
- "html" => {
231
- :single => nil,
232
- :multi => { :start => '<!--', :middle => nil, :end => '-->' },
233
- :heredoc => nil
234
- },
235
- "java" => C_STYLE_COMMENTS,
236
- "js" => C_STYLE_COMMENTS,
237
- "lua" => {
238
- :single => "--",
239
- :multi => nil,
240
- :heredoc => nil
241
- },
242
- "php" => C_STYLE_COMMENTS,
243
- "python" => {
244
- :single => "#",
245
- :multi => { :start => '"""', :middle => nil, :end => '"""' },
246
- :heredoc => nil
247
- },
248
- "rb" => {
249
- :single => "#",
250
- :multi => { :start => '=begin', :middle => nil, :end => '=end' },
251
- :heredoc => "<<-"
252
- },
253
- "scheme" => { :single => ";;", :multi => nil, :heredoc => nil },
254
- "xml" => {
255
- :single => nil,
256
- :multi => { :start => '<!--', :middle => nil, :end => '-->' },
257
- :heredoc => nil
258
- },
259
- }
209
+ require 'rocco/comment_styles'
210
+ include CommentStyles
260
211
 
261
212
  def generate_comment_chars
262
213
  @_commentchar ||=
@@ -437,8 +388,7 @@ class Rocco
437
388
  # dividers and run through the Markdown processor. Then split it back out
438
389
  # into separate sections.
439
390
  markdown = docs_blocks.join("\n\n##### DIVIDER\n\n")
440
- docs_html = Markdown.new(markdown, :smart).
441
- to_html.
391
+ docs_html = process_markdown(markdown).
442
392
  split(/\n*<h5>DIVIDER<\/h5>\n*/m)
443
393
 
444
394
  # Combine all code blocks into a single big stream with section dividers and
@@ -492,6 +442,11 @@ class Rocco
492
442
  docs_html.zip(code_html)
493
443
  end
494
444
 
445
+ # Convert Markdown to classy HTML.
446
+ def process_markdown(text)
447
+ Markdown.new(text, :smart).to_html
448
+ end
449
+
495
450
  # We `popen` a read/write pygmentize process in the parent and
496
451
  # then fork off a child process to write the input.
497
452
  def highlight_pygmentize(code)
@@ -0,0 +1,56 @@
1
+ class Rocco
2
+ module CommentStyles
3
+ C_STYLE_COMMENTS = {
4
+ :single => "//",
5
+ :multi => { :start => "/**", :middle => "*", :end => "*/" },
6
+ :heredoc => nil
7
+ }
8
+
9
+ COMMENT_STYLES = {
10
+ "bash" => { :single => "#", :multi => nil },
11
+ "c" => C_STYLE_COMMENTS,
12
+ "coffee-script" => {
13
+ :single => "#",
14
+ :multi => { :start => "###", :middle => nil, :end => "###" },
15
+ :heredoc => nil
16
+ },
17
+ "cpp" => C_STYLE_COMMENTS,
18
+ "csharp" => C_STYLE_COMMENTS,
19
+ "css" => {
20
+ :single => nil,
21
+ :multi => { :start => "/**", :middle => "*", :end => "*/" },
22
+ :heredoc => nil
23
+ },
24
+ "html" => {
25
+ :single => nil,
26
+ :multi => { :start => '<!--', :middle => nil, :end => '-->' },
27
+ :heredoc => nil
28
+ },
29
+ "java" => C_STYLE_COMMENTS,
30
+ "js" => C_STYLE_COMMENTS,
31
+ "lua" => {
32
+ :single => "--",
33
+ :multi => nil,
34
+ :heredoc => nil
35
+ },
36
+ "php" => C_STYLE_COMMENTS,
37
+ "python" => {
38
+ :single => "#",
39
+ :multi => { :start => '"""', :middle => nil, :end => '"""' },
40
+ :heredoc => nil
41
+ },
42
+ "rb" => {
43
+ :single => "#",
44
+ :multi => { :start => '=begin', :middle => nil, :end => '=end' },
45
+ :heredoc => "<<-"
46
+ },
47
+ "scala" => C_STYLE_COMMENTS,
48
+ "scheme" => { :single => ";;", :multi => nil, :heredoc => nil },
49
+ "xml" => {
50
+ :single => nil,
51
+ :multi => { :start => '<!--', :middle => nil, :end => '-->' },
52
+ :heredoc => nil
53
+ },
54
+ }
55
+ end
56
+ end
@@ -15,9 +15,14 @@ class Rocco::Layout < Mustache
15
15
  File.basename(@doc.file)
16
16
  end
17
17
 
18
+ def file
19
+ @doc.file
20
+ end
21
+
18
22
  def sections
19
23
  num = 0
20
24
  @doc.sections.map do |docs,code|
25
+ code ||= ''
21
26
  is_header = /^<h.>(.+)<\/h.>$/.match( docs )
22
27
  header_text = is_header && is_header[1].split.join("_")
23
28
  num += 1
@@ -58,6 +58,8 @@ class Rocco
58
58
  # `Rocco::Task.new` takes a task name, the destination directory docs
59
59
  # should be built under, and a source file pattern or file list.
60
60
  class Task
61
+ include Rake::DSL if defined?(Rake::DSL)
62
+
61
63
  def initialize(task_name, dest='docs/', sources='lib/**/*.rb', options={})
62
64
  @name = task_name
63
65
  @dest = dest[-1] == ?/ ? dest : "#{dest}/"
@@ -1,10 +1,15 @@
1
+ # rocco.gemspec
2
+ #
3
+ # To update this file's version, date, and file list, change the VERSION
4
+ # constant in lib/rocco.rb and run `rake rocco.gemspec`.
5
+
1
6
  Gem::Specification.new do |s|
2
7
  s.specification_version = 2 if s.respond_to? :specification_version=
3
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
9
 
5
10
  s.name = 'rocco'
6
- s.version = '0.7'
7
- s.date = '2011-05-22'
11
+ s.version = '0.8'
12
+ s.date = '2011-06-19'
8
13
 
9
14
  s.description = "Docco in Ruby"
10
15
  s.summary = s.description
@@ -20,6 +25,7 @@ Gem::Specification.new do |s|
20
25
  Rakefile
21
26
  bin/rocco
22
27
  lib/rocco.rb
28
+ lib/rocco/comment_styles.rb
23
29
  lib/rocco/layout.mustache
24
30
  lib/rocco/layout.rb
25
31
  lib/rocco/tasks.rb
@@ -46,7 +52,7 @@ Gem::Specification.new do |s|
46
52
  s.executables = ["rocco"]
47
53
 
48
54
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
49
- s.add_dependency 'rdiscount'
55
+ s.add_dependency 'redcarpet'
50
56
  s.add_dependency 'mustache'
51
57
 
52
58
  s.has_rdoc = false
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- version: "0.7"
8
+ - 8
9
+ version: "0.8"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Tomayko
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-22 00:00:00 -07:00
18
+ date: 2011-06-19 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rdiscount
22
+ name: redcarpet
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -63,6 +63,7 @@ files:
63
63
  - Rakefile
64
64
  - bin/rocco
65
65
  - lib/rocco.rb
66
+ - lib/rocco/comment_styles.rb
66
67
  - lib/rocco/layout.mustache
67
68
  - lib/rocco/layout.rb
68
69
  - lib/rocco/tasks.rb