cg 0.0.1 → 0.0.2
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/README.rdoc +11 -0
- data/VERSION +1 -1
- data/cg.gemspec +4 -4
- data/lib/cg/convert.rb +31 -21
- data/lib/cg/rebuild.rb +0 -0
- data/skel/styles/cg.css +18 -12
- data/skel/templates/html.rb +4 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -44,6 +44,17 @@ cg is A Ruby based HTML "contents generator".
|
|
44
44
|
$ cg convert markdown_file
|
45
45
|
|
46
46
|
|
47
|
+
== Tips
|
48
|
+
|
49
|
+
1. After save hook for Vim
|
50
|
+
|
51
|
+
$ vi .vimrc
|
52
|
+
autocmd BufWritePost *.mkd :silent !cg convert %
|
53
|
+
|
54
|
+
|
55
|
+
2. After save hoook for Emacs
|
56
|
+
|
57
|
+
|
47
58
|
== Note on Patches/Pull Requests
|
48
59
|
|
49
60
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/cg.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cg}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tomohiro, TAIRA"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-27}
|
13
13
|
s.default_executable = %q{cg}
|
14
14
|
s.description = %q{cg is A Ruby based contents generator}
|
15
15
|
s.email = %q{tomohiro.t+github@gmail.com}
|
@@ -52,8 +52,8 @@ Gem::Specification.new do |s|
|
|
52
52
|
s.rubygems_version = %q{1.3.6}
|
53
53
|
s.summary = %q{HTML Contents Generator}
|
54
54
|
s.test_files = [
|
55
|
-
"spec/
|
56
|
-
"spec/
|
55
|
+
"spec/spec_helper.rb",
|
56
|
+
"spec/cg_spec.rb"
|
57
57
|
]
|
58
58
|
|
59
59
|
if s.respond_to? :specification_version then
|
data/lib/cg/convert.rb
CHANGED
@@ -14,7 +14,11 @@ module CG
|
|
14
14
|
|
15
15
|
def initialize(source)
|
16
16
|
@source = source || ARGV.first
|
17
|
-
|
17
|
+
|
18
|
+
@root = File.expand_path(File.dirname(@source)).gsub('markdown', '')
|
19
|
+
@domain = @root.split('/').last
|
20
|
+
|
21
|
+
@templates_dir = templates_dir
|
18
22
|
end
|
19
23
|
|
20
24
|
def self.start!(source = nil)
|
@@ -23,15 +27,13 @@ module CG
|
|
23
27
|
|
24
28
|
def start
|
25
29
|
dir_path, html_name = gen_output_path(@source)
|
26
|
-
|
27
|
-
template = load_template
|
28
|
-
@article = article_rendering(load_markdown(@source))
|
29
|
-
@relative = relative_path(dir_path)
|
30
|
-
|
31
30
|
mkdir_p dir_path
|
32
31
|
|
33
32
|
open(File.join(dir_path, html_name), 'w') do |f|
|
34
|
-
|
33
|
+
@article = article_rendering(load_markdown(@source))
|
34
|
+
@relative = relative_path(dir_path)
|
35
|
+
|
36
|
+
f.write page_build(load_template)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -39,45 +41,53 @@ module CG
|
|
39
41
|
markdown_base = File.dirname(source)
|
40
42
|
expand_path = source.gsub(/-|\+/, '/')
|
41
43
|
|
42
|
-
dir_path = File.expand_path("#{@
|
44
|
+
dir_path = File.expand_path("#{@root}/#{File.dirname(expand_path).gsub(markdown_base, '')}")
|
43
45
|
html_name = File.basename(expand_path).gsub('.mkd', '.html')
|
44
46
|
|
45
47
|
[dir_path, html_name]
|
46
48
|
end
|
47
49
|
|
48
50
|
def relative_path(dir_path)
|
49
|
-
point = dir_path.gsub(@
|
51
|
+
point = dir_path.gsub(@root, '').split('/').count
|
50
52
|
'../' * point
|
51
53
|
end
|
52
54
|
|
53
55
|
def load_template(template_name = 'html.rb')
|
54
|
-
Tilt::ErubisTemplate.new
|
55
|
-
File.read("#{@site_base_path}/templates/#{template_name}")
|
56
|
-
end
|
56
|
+
Tilt::ErubisTemplate.new { File.read("#{@templates_dir}/#{template_name}") }
|
57
57
|
end
|
58
58
|
|
59
59
|
def load_markdown(source)
|
60
60
|
Tilt::RDiscountTemplate.new { File.read(source) }
|
61
61
|
end
|
62
62
|
|
63
|
+
def templates_dir
|
64
|
+
if File.directory? "#{@root}/templates"
|
65
|
+
"#{@root}/templates"
|
66
|
+
else
|
67
|
+
File.expand_path('../../skel/templates', File.dirname(__FILE__))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
63
71
|
def article_rendering(markdown)
|
64
|
-
@
|
65
|
-
@disqus = disqus_template
|
72
|
+
@disqus = comment_rendering
|
66
73
|
|
67
74
|
article = Tilt::ErubisTemplate.new { markdown.render }
|
68
75
|
article.render(self)
|
69
76
|
end
|
70
77
|
|
71
|
-
def
|
72
|
-
|
78
|
+
def comment_rendering
|
79
|
+
return unless File.exist? "#{@templates_dir}/disqus.rb"
|
73
80
|
|
74
|
-
|
81
|
+
@disqus_subdomain = @domain.gsub('.', '-')
|
82
|
+
|
83
|
+
comment = Tilt::ErubisTemplate.new { File.read("#{@templates_dir}/disqus.rb") }
|
84
|
+
comment.render(self)
|
75
85
|
end
|
76
86
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
def page_build(page)
|
88
|
+
@title = [(Nokogiri::HTML(@article)/'h1').text, @domain].join(' - ')
|
89
|
+
|
90
|
+
page.render(self)
|
81
91
|
end
|
82
92
|
end
|
83
93
|
end
|
data/lib/cg/rebuild.rb
CHANGED
File without changes
|
data/skel/styles/cg.css
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
@charset 'utf-8';
|
2
|
-
/* 自由に編集可 */
|
3
2
|
|
4
3
|
body {
|
5
4
|
font-family: Times, 'Times New Roman', 'メイリオ', 'FreeSerif', serif;
|
@@ -21,27 +20,32 @@ h1, h3, h5 {
|
|
21
20
|
font-family: Times, 'Times New Roman', 'メイリオ', 'FreeSerif', sans-serif;
|
22
21
|
}
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
header {
|
24
|
+
margin-top: 30px;
|
26
25
|
}
|
27
|
-
|
28
|
-
|
29
|
-
margin: 30px 0 40px 0;
|
30
|
-
padding: 2px 30px;
|
31
|
-
width: 30px;
|
26
|
+
header h1 a {
|
27
|
+
padding: 5px 20px;
|
32
28
|
background-color: #000;
|
33
29
|
color: #fff;
|
34
30
|
-moz-border-radius: 12px;
|
35
31
|
-webkit-border-radius: 12px;
|
36
32
|
font-size: 240%;
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
article h1 {
|
37
|
+
margin: 50px 0px 30px;
|
38
|
+
border-bottom: double solid #000;
|
39
|
+
text-align: center;
|
40
|
+
font-size: 200%;
|
37
41
|
}
|
38
42
|
|
39
43
|
h2 {
|
40
44
|
margin: 20px 0;
|
41
|
-
|
42
|
-
|
43
|
-
line-height: 150%;
|
45
|
+
font-size: 150%;
|
46
|
+
line-height: 130%;
|
44
47
|
border-bottom: 2px solid #000;
|
48
|
+
font-family: Helvetica, Verdana, 'メイリオ', 'FreeSans', sans-serif;
|
45
49
|
}
|
46
50
|
|
47
51
|
h3 {
|
@@ -140,9 +144,11 @@ blockquote {
|
|
140
144
|
}
|
141
145
|
|
142
146
|
blockquote p {
|
143
|
-
|
147
|
+
padding-left: 10px;
|
144
148
|
line-height: 2em;
|
145
149
|
text-align: left;
|
150
|
+
border-left: 5px solid #ddd;
|
151
|
+
background-color: #fff;
|
146
152
|
}
|
147
153
|
|
148
154
|
blockquote pre {
|
data/skel/templates/html.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tomohiro, TAIRA
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-27 00:00:00 +09:00
|
18
18
|
default_executable: cg
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -154,5 +154,5 @@ signing_key:
|
|
154
154
|
specification_version: 3
|
155
155
|
summary: HTML Contents Generator
|
156
156
|
test_files:
|
157
|
-
- spec/cg_spec.rb
|
158
157
|
- spec/spec_helper.rb
|
158
|
+
- spec/cg_spec.rb
|