docify 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/docify +1 -1
- data/docify.gemspec +1 -4
- data/lib/docify.rb +2 -5
- data/lib/docify/document.rb +2 -11
- data/lib/docify/style.rb +60 -9
- data/lib/docify/template.rb +22 -0
- data/lib/docify/utils.rb +14 -0
- data/lib/docify/version.rb +1 -1
- data/spec/document_spec.rb +13 -8
- data/spec/spec_helper.rb +5 -3
- data/spec/template_spec.rb +13 -0
- metadata +8 -4
data/bin/docify
CHANGED
data/docify.gemspec
CHANGED
@@ -17,14 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_runtime_dependency 'rdiscount', '~> 1.6.8'
|
19
19
|
s.add_runtime_dependency 'RedCloth', '~> 4.2.3'
|
20
|
-
s.add_runtime_dependency 'rdoc', '~> 3.
|
20
|
+
s.add_runtime_dependency 'rdoc', '~> 3.7'
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
23
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
25
25
|
s.require_paths = ["lib"]
|
26
26
|
s.default_executable = 'docify'
|
27
|
-
|
28
|
-
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
30
27
|
end
|
data/lib/docify.rb
CHANGED
data/lib/docify/document.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Docify
|
1
|
+
module Docify
|
2
2
|
class Document
|
3
3
|
attr_reader :path
|
4
4
|
attr_reader :content
|
@@ -18,7 +18,7 @@ module Docify
|
|
18
18
|
if embed_css
|
19
19
|
params = {:title => File.basename(@path), :content => result}
|
20
20
|
params[:css] = Docify::CSS if embed_css
|
21
|
-
@content =
|
21
|
+
@content = Docify::Template.new(Docify::TEMPLATE).render(params)
|
22
22
|
else
|
23
23
|
@content = result
|
24
24
|
end
|
@@ -35,14 +35,5 @@ module Docify
|
|
35
35
|
end
|
36
36
|
File.open(path, 'w') { |f| f.write(@content) }
|
37
37
|
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
# Render template with provided data
|
42
|
-
def template(params={})
|
43
|
-
TEMPLATE.gsub(REGEX) do |m|
|
44
|
-
m = params[m.scan(REGEX).flatten.last.to_sym]
|
45
|
-
end
|
46
|
-
end
|
47
38
|
end
|
48
39
|
end
|
data/lib/docify/style.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Docify
|
2
|
-
REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i
|
3
|
-
|
4
2
|
TEMPLATE = <<END_TEMPLATE
|
3
|
+
<!DOCTYPE html>
|
5
4
|
<html>
|
6
5
|
<head>
|
7
6
|
<title>{{title}}</title>
|
@@ -10,7 +9,6 @@ module Docify
|
|
10
9
|
</head>
|
11
10
|
<body>
|
12
11
|
<div id="content">{{content}}</div>
|
13
|
-
<!-- Generated with Docify -->
|
14
12
|
</body>
|
15
13
|
</html>
|
16
14
|
END_TEMPLATE
|
@@ -18,10 +16,48 @@ END_TEMPLATE
|
|
18
16
|
CSS = <<END_CSS
|
19
17
|
<style>
|
20
18
|
body {
|
21
|
-
background: #
|
19
|
+
background: #f8f8f8;
|
22
20
|
font: 13.34px helvetica,arial,freesans,clean,sans-serif;
|
23
21
|
}
|
24
|
-
|
22
|
+
|
23
|
+
body * { line-height: 1.4em; }
|
24
|
+
|
25
|
+
a { color: #4183C4; text-decoration: none; }
|
26
|
+
a:hover { text-decoration: underline; }
|
27
|
+
|
28
|
+
#content {
|
29
|
+
width: 800px; margin: 0px auto;
|
30
|
+
}
|
31
|
+
|
32
|
+
p {
|
33
|
+
margin: 1em 0!important;
|
34
|
+
line-height: 1.5em!important;
|
35
|
+
}
|
36
|
+
|
37
|
+
h1, h2, h3, h4, h5, h6 { border: 0 !important; }
|
38
|
+
|
39
|
+
h1 {
|
40
|
+
font-size: 170%!important;
|
41
|
+
border-top: 4px solid #AAA!important;
|
42
|
+
padding-top: .5em!important;
|
43
|
+
margin-top: 1.5em!important;
|
44
|
+
}
|
45
|
+
|
46
|
+
h1:first-child { border-top: none !important; }
|
47
|
+
|
48
|
+
h2 {
|
49
|
+
font-size: 150% !important;
|
50
|
+
margin-top: 1.5em !important;
|
51
|
+
border-top: 4px solid #E0E0E0 !important;
|
52
|
+
padding-top: .5em !important;
|
53
|
+
}
|
54
|
+
|
55
|
+
h3 { margin-top: 1em !important; }
|
56
|
+
|
57
|
+
pre, code {
|
58
|
+
font: 12px 'Bitstream Vera Sans Mono','Courier',monospace;
|
59
|
+
}
|
60
|
+
|
25
61
|
pre {
|
26
62
|
margin: 1em 0;
|
27
63
|
font-size: 12px;
|
@@ -31,10 +67,25 @@ END_TEMPLATE
|
|
31
67
|
line-height: 1.5em;
|
32
68
|
color: #444;
|
33
69
|
overflow: auto;
|
34
|
-
-webkit-box-shadow:rgba(0,0,0,0.07) 0 1px 2px inset;
|
35
|
-
-webkit-border-radius:3px;
|
36
|
-
-moz-border-radius:3px;
|
37
|
-
border-radius:3px;
|
70
|
+
-webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
|
71
|
+
-webkit-border-radius: 3px;
|
72
|
+
-moz-border-radius: 3px;
|
73
|
+
border-radius: 3px;
|
74
|
+
}
|
75
|
+
|
76
|
+
code {
|
77
|
+
font-size: 12px !important;
|
78
|
+
background-color: ghostWhite !important;
|
79
|
+
color: #444 !important;
|
80
|
+
padding: 0 .2em !important;
|
81
|
+
border: 1px solid #DEDEDE !important;
|
82
|
+
}
|
83
|
+
|
84
|
+
pre code {
|
85
|
+
padding: 0!important;
|
86
|
+
font-size: 12px!important;
|
87
|
+
background-color: #EEE!important;
|
88
|
+
border: none!important;
|
38
89
|
}
|
39
90
|
</style>
|
40
91
|
END_CSS
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Docify
|
2
|
+
class Template
|
3
|
+
REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i
|
4
|
+
|
5
|
+
# Initialize Template object with a string template
|
6
|
+
def initialize(content)
|
7
|
+
@template = content.strip.to_s
|
8
|
+
raise ArgumentError, "Template content required!" if @template.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
# Render template
|
12
|
+
# params - Hash of parameters.
|
13
|
+
# Each params in template should be wrapped with {{var}}.
|
14
|
+
def render(params={})
|
15
|
+
params.stringify_keys!
|
16
|
+
@template.gsub(REGEX) do |m|
|
17
|
+
key = m.scan(REGEX).flatten.last.to_s
|
18
|
+
m = params[key]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/docify/utils.rb
ADDED
data/lib/docify/version.rb
CHANGED
data/spec/document_spec.rb
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Document' do
|
4
|
-
it 'should raise exception on invalid input file' do
|
4
|
+
it 'should raise an exception on invalid input file' do
|
5
5
|
proc { Docify::Document.new('qwe123')}.should raise_error ArgumentError, "File [qwe123] does not exist!"
|
6
6
|
proc { Docify::Document.new('/tmp') }.should raise_error ArgumentError, "File required!"
|
7
7
|
end
|
8
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
9
|
it 'should raise an exception on invalid output path' do
|
17
10
|
doc = Docify::Document.new('README.rdoc')
|
18
11
|
doc.render('rdoc')
|
19
12
|
proc { doc.save_to('~/blah') }.should raise_error ArgumentError, "Output path does not exist!"
|
20
13
|
proc { doc.save_to('/tmp') }.should raise_error ArgumentError, "Output path should be a file!"
|
21
14
|
end
|
15
|
+
|
16
|
+
it 'should render content with styles' do
|
17
|
+
doc = Docify::Document.new(fixture_path('README.markdown'))
|
18
|
+
output = doc.render('markdown')
|
19
|
+
output.should match(/<meta http-equiv="Content-Type" content="text\/html; charset=UTF-8" \/>/)
|
20
|
+
output.should match(/<title>README.markdown<\/title>/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should render content with no styles' do
|
24
|
+
doc = Docify::Document.new(fixture_path('README.markdown')).render('markdown', false)
|
25
|
+
doc.should == Docify::Markup.markdown(fixture('README.markdown'))
|
26
|
+
end
|
22
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,10 +17,12 @@ README_FILES = {
|
|
17
17
|
'README.foo' => 'rdoc'
|
18
18
|
}
|
19
19
|
|
20
|
-
def fixture_path
|
21
|
-
File.expand_path("../fixtures", __FILE__)
|
20
|
+
def fixture_path(file=nil)
|
21
|
+
path = File.expand_path("../fixtures", __FILE__)
|
22
|
+
path = File.join(path, file) unless file.nil?
|
23
|
+
path
|
22
24
|
end
|
23
25
|
|
24
26
|
def fixture(file)
|
25
27
|
File.read(File.join(fixture_path, file))
|
26
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Template' do
|
4
|
+
it 'should raise ArgumentError if no template were provided' do
|
5
|
+
proc { Docify::Template.new }.should raise_error ArgumentError
|
6
|
+
proc { Docify::Template.new(" ") }.should raise_error ArgumentError
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should render a valid content' do
|
10
|
+
Docify::Template.new("{{a}}{{b}}").render(:a => 'a', :b => 'b').should == 'ab'
|
11
|
+
Docify::Template.new("{{a}}{{b}}").render('a' => 'a', 'b' => 'b').should == 'ab'
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: docify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Sosedoff
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-28 00:00:00 -05:00
|
14
14
|
default_executable: docify
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: "3.
|
101
|
+
version: "3.7"
|
102
102
|
type: :runtime
|
103
103
|
version_requirements: *id008
|
104
104
|
description: Docify provides a command line tool to render documentation files (RDoc, Markdown, Textile) into nice-looking html.
|
@@ -123,6 +123,8 @@ files:
|
|
123
123
|
- lib/docify/format.rb
|
124
124
|
- lib/docify/markup.rb
|
125
125
|
- lib/docify/style.rb
|
126
|
+
- lib/docify/template.rb
|
127
|
+
- lib/docify/utils.rb
|
126
128
|
- lib/docify/version.rb
|
127
129
|
- spec/docify_spec.rb
|
128
130
|
- spec/document_spec.rb
|
@@ -134,6 +136,7 @@ files:
|
|
134
136
|
- spec/fixtures/README.textile.html
|
135
137
|
- spec/markup_spec.rb
|
136
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/template_spec.rb
|
137
140
|
has_rdoc: true
|
138
141
|
homepage: http://github.com/sosedoff/docify
|
139
142
|
licenses: []
|
@@ -154,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
157
|
requirements:
|
155
158
|
- - ">="
|
156
159
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
160
|
+
version: "0"
|
158
161
|
requirements: []
|
159
162
|
|
160
163
|
rubyforge_project:
|
@@ -173,3 +176,4 @@ test_files:
|
|
173
176
|
- spec/fixtures/README.textile.html
|
174
177
|
- spec/markup_spec.rb
|
175
178
|
- spec/spec_helper.rb
|
179
|
+
- spec/template_spec.rb
|