docify 1.0.0 → 1.0.1
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/.gitignore +24 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/bin/docify +3 -0
- data/docify.gemspec +29 -0
- data/lib/docify.rb +1 -3
- data/lib/docify/document.rb +1 -1
- data/lib/docify/markup.rb +62 -0
- data/lib/docify/style.rb +2 -1
- data/lib/docify/version.rb +1 -1
- data/spec/docify_spec.rb +14 -0
- data/spec/document_spec.rb +22 -0
- data/spec/spec_helper.rb +18 -0
- metadata +75 -46
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.swp
|
4
|
+
*.tmproj
|
5
|
+
*~
|
6
|
+
.DS_Store
|
7
|
+
.\#*
|
8
|
+
.bundle
|
9
|
+
.config
|
10
|
+
.yardoc
|
11
|
+
Gemfile.lock
|
12
|
+
InstalledFiles
|
13
|
+
\#*
|
14
|
+
_yardoc
|
15
|
+
coverage
|
16
|
+
doc/
|
17
|
+
lib/bundler/man
|
18
|
+
pkg
|
19
|
+
rdoc
|
20
|
+
spec/reports
|
21
|
+
test/tmp
|
22
|
+
test/version_tmp
|
23
|
+
tmp
|
24
|
+
tmtags
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/bin/docify
CHANGED
data/docify.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../lib/docify/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "docify"
|
5
|
+
s.version = Docify::VERSION.dup
|
6
|
+
s.summary = "Terminal tool to render markups into html"
|
7
|
+
s.description = "Docify provides a command line tool to render documentation files (RDoc, Markdown, Textile) into nice-looking html."
|
8
|
+
s.homepage = "http://github.com/sosedoff/docify"
|
9
|
+
s.authors = ["Dan Sosedoff"]
|
10
|
+
s.email = ["dan.sosedoff@gmail.com"]
|
11
|
+
|
12
|
+
s.add_development_dependency 'rake', '~> 0.8'
|
13
|
+
s.add_development_dependency 'rspec', '~> 2.5'
|
14
|
+
s.add_development_dependency 'ZenTest', '~> 4.5'
|
15
|
+
s.add_development_dependency 'simplecov', '~> 0.4'
|
16
|
+
s.add_development_dependency 'yard', '~> 0.6'
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'rdiscount', '~> 1.6.8'
|
19
|
+
s.add_runtime_dependency 'RedCloth', '~> 4.2.3'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.default_executable = 'docify'
|
26
|
+
|
27
|
+
s.platform = Gem::Platform::RUBY
|
28
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
29
|
+
end
|
data/lib/docify.rb
CHANGED
data/lib/docify/document.rb
CHANGED
@@ -14,7 +14,7 @@ module Docify
|
|
14
14
|
# Render document by specified format
|
15
15
|
def render(format, embed_css=true)
|
16
16
|
raise ArgumentError, 'Invalid format!' unless FORMATS.include?(format)
|
17
|
-
result =
|
17
|
+
result = Docify::Markup.render("doc.#{format}", File.read(@path))
|
18
18
|
if embed_css
|
19
19
|
params = {:title => File.basename(@path), :content => result}
|
20
20
|
params[:css] = Docify::CSS if embed_css
|
@@ -0,0 +1,62 @@
|
|
1
|
+
if RUBY_VERSION.include?('1.9')
|
2
|
+
require 'rdoc/markup/to_html'
|
3
|
+
else
|
4
|
+
require 'rdoc/generators/html_generator'
|
5
|
+
require 'ostruct'
|
6
|
+
end
|
7
|
+
|
8
|
+
module Docify
|
9
|
+
module Markup
|
10
|
+
extend self
|
11
|
+
|
12
|
+
# Auto-detect format from filename and render content
|
13
|
+
def render(filename, content)
|
14
|
+
name = File.basename(filename.to_s.strip)
|
15
|
+
raise ArgumentError, 'Filename required!' if name.empty?
|
16
|
+
format = detect_format(name)
|
17
|
+
format == :text ? content : self.send(format, content)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Render content for Markdown
|
21
|
+
def markdown(content)
|
22
|
+
Markdown.new(content).to_html
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_VERSION.include?('1.9')
|
26
|
+
# Render content for RDoc
|
27
|
+
def rdoc(content)
|
28
|
+
RDoc::Markup::ToHtml.new.convert(content)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
# Render content for RDoc
|
32
|
+
def rdoc(content)
|
33
|
+
simple_markup = SM::SimpleMarkup.new
|
34
|
+
generator = Generators::HyperlinkHtml.new('', OpenStruct.new)
|
35
|
+
simple_markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
|
36
|
+
simple_markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\.\S+?\])/, :TIDYLINK)
|
37
|
+
simple_markup.convert(content, generator)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Render content for Textile
|
42
|
+
def textile(content)
|
43
|
+
RedCloth.new(content).to_html
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
# Detect markup format from filename
|
49
|
+
def detect_format(filename)
|
50
|
+
case(filename)
|
51
|
+
when /\.rdoc/i
|
52
|
+
:rdoc
|
53
|
+
when /\.(md|mkdn?|mdown|markdown)/i
|
54
|
+
:markdown
|
55
|
+
when /\.textile/i
|
56
|
+
:textile
|
57
|
+
else
|
58
|
+
:text
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/docify/style.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Docify
|
2
|
-
REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i
|
2
|
+
REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i
|
3
3
|
|
4
4
|
TEMPLATE = <<END_TEMPLATE
|
5
5
|
<html>
|
6
6
|
<head>
|
7
7
|
<title>{{title}}</title>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
9
|
{{css}}
|
9
10
|
</head>
|
10
11
|
<body>
|
data/lib/docify/version.rb
CHANGED
data/spec/docify_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Docify' do
|
4
|
+
it 'should validate format' do
|
5
|
+
Docify::FORMATS.each { |f| Docify.valid_format?(f).should == true }
|
6
|
+
Docify.valid_format?('txt').should == false
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should detect valid format' do
|
10
|
+
README_FILES.each do |k,v|
|
11
|
+
Docify.detect_format(k).should == v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Document' do
|
4
|
+
it 'should raise exception on invalid input file' do
|
5
|
+
proc { Docify::Document.new('qwe123')}.should raise_error ArgumentError, "File [qwe123] does not exist!"
|
6
|
+
proc { Docify::Document.new('/tmp') }.should raise_error ArgumentError, "File required!"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should render correct layout' do
|
10
|
+
doc = Docify::Document.new('README.rdoc')
|
11
|
+
output = doc.render('rdoc')
|
12
|
+
output.should match(/<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8" \/>/)
|
13
|
+
output.should match(/<title>README.rdoc<\/title>/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should raise an exception on invalid output path' do
|
17
|
+
doc = Docify::Document.new('README.rdoc')
|
18
|
+
doc.render('rdoc')
|
19
|
+
proc { doc.save_to('~/blah') }.should raise_error ArgumentError, "Output path does not exist!"
|
20
|
+
proc { doc.save_to('/tmp') }.should raise_error ArgumentError, "Output path should be a file!"
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.expand_path("../..", __FILE__)
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_group 'Docify', 'lib/docify'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'docify'
|
9
|
+
|
10
|
+
README_FILES = {
|
11
|
+
'README' => 'rdoc',
|
12
|
+
'README.rdoc' => 'rdoc',
|
13
|
+
'README.md' => 'markdown',
|
14
|
+
'README.markdown' => 'markdown',
|
15
|
+
'README.textile' => 'textile',
|
16
|
+
'README.txt' => 'rdoc',
|
17
|
+
'README.foo' => 'rdoc'
|
18
|
+
}
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
5
|
+
version: 1.0.1
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Dan Sosedoff
|
@@ -15,59 +10,89 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-06-13 00:00:00 -05:00
|
19
14
|
default_executable: docify
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
17
|
+
name: rake
|
23
18
|
prerelease: false
|
24
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
20
|
none: false
|
26
21
|
requirements:
|
27
|
-
- -
|
22
|
+
- - ~>
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
- 0
|
32
|
-
- 5
|
33
|
-
- 3
|
34
|
-
version: 0.5.3
|
35
|
-
type: :runtime
|
24
|
+
version: "0.8"
|
25
|
+
type: :development
|
36
26
|
version_requirements: *id001
|
37
27
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
28
|
+
name: rspec
|
39
29
|
prerelease: false
|
40
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
31
|
none: false
|
42
32
|
requirements:
|
43
|
-
- -
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "2.5"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: ZenTest
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "4.5"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: simplecov
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0.4"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: yard
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0.6"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rdiscount
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
44
78
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 31
|
46
|
-
segments:
|
47
|
-
- 1
|
48
|
-
- 6
|
49
|
-
- 8
|
50
79
|
version: 1.6.8
|
51
80
|
type: :runtime
|
52
|
-
version_requirements: *
|
81
|
+
version_requirements: *id006
|
53
82
|
- !ruby/object:Gem::Dependency
|
54
83
|
name: RedCloth
|
55
84
|
prerelease: false
|
56
|
-
requirement: &
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
57
86
|
none: false
|
58
87
|
requirements:
|
59
|
-
- -
|
88
|
+
- - ~>
|
60
89
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 49
|
62
|
-
segments:
|
63
|
-
- 4
|
64
|
-
- 2
|
65
|
-
- 3
|
66
90
|
version: 4.2.3
|
67
91
|
type: :runtime
|
68
|
-
version_requirements: *
|
92
|
+
version_requirements: *id007
|
69
93
|
description: Docify provides a command line tool to render documentation files (RDoc, Markdown, Textile) into nice-looking html.
|
70
|
-
email:
|
94
|
+
email:
|
95
|
+
- dan.sosedoff@gmail.com
|
71
96
|
executables:
|
72
97
|
- docify
|
73
98
|
extensions: []
|
@@ -75,14 +100,22 @@ extensions: []
|
|
75
100
|
extra_rdoc_files: []
|
76
101
|
|
77
102
|
files:
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- Gemfile
|
106
|
+
- README.rdoc
|
78
107
|
- Rakefile
|
79
108
|
- bin/docify
|
109
|
+
- docify.gemspec
|
110
|
+
- lib/docify.rb
|
80
111
|
- lib/docify/document.rb
|
81
112
|
- lib/docify/format.rb
|
113
|
+
- lib/docify/markup.rb
|
82
114
|
- lib/docify/style.rb
|
83
115
|
- lib/docify/version.rb
|
84
|
-
-
|
85
|
-
-
|
116
|
+
- spec/docify_spec.rb
|
117
|
+
- spec/document_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
86
119
|
has_rdoc: true
|
87
120
|
homepage: http://github.com/sosedoff/docify
|
88
121
|
licenses: []
|
@@ -97,25 +130,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
130
|
requirements:
|
98
131
|
- - ">="
|
99
132
|
- !ruby/object:Gem::Version
|
100
|
-
hash: 3
|
101
|
-
segments:
|
102
|
-
- 0
|
103
133
|
version: "0"
|
104
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
135
|
none: false
|
106
136
|
requirements:
|
107
137
|
- - ">="
|
108
138
|
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
segments:
|
111
|
-
- 0
|
112
|
-
version: "0"
|
139
|
+
version: 1.3.6
|
113
140
|
requirements: []
|
114
141
|
|
115
142
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.6.2
|
117
144
|
signing_key:
|
118
145
|
specification_version: 3
|
119
|
-
summary:
|
120
|
-
test_files:
|
121
|
-
|
146
|
+
summary: Terminal tool to render markups into html
|
147
|
+
test_files:
|
148
|
+
- spec/docify_spec.rb
|
149
|
+
- spec/document_spec.rb
|
150
|
+
- spec/spec_helper.rb
|