carta 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carta/cli/compile.rb +24 -5
- data/lib/carta/cli/html_renderer.rb +26 -11
- data/lib/carta/util.rb +1 -1
- data/lib/carta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45dde63c7083042b1838f16713a79bf4d92c7b08
|
4
|
+
data.tar.gz: 66a564f43517c7fcee5b1b18482e4e4d97c4a35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0de778da2ade591568fb4ea46c5726fc81b414041ec5f40efa0d7cb934e34d4d2cf311a16d8ec7f1718e1fa8838230b291ff34cfe903b1e9413e872f19fa167
|
7
|
+
data.tar.gz: 4ef74bc8d82009a48efc8117f9a9d9ed9180a67350c53ef1a59fa5b36dff287b4404e2012d1bd7d5142ddcdc7e137cdd9a0820db98090babe05aa436610baae9
|
data/lib/carta/cli/compile.rb
CHANGED
@@ -16,6 +16,8 @@ module Carta
|
|
16
16
|
:FIGURE_DIR,
|
17
17
|
:ASSET_DIR,
|
18
18
|
:BUILD_DIR,
|
19
|
+
:EPUB_DIR,
|
20
|
+
:HTML_DIR,
|
19
21
|
:ASSET_FILES
|
20
22
|
|
21
23
|
def initialize(thor)
|
@@ -27,6 +29,8 @@ module Carta
|
|
27
29
|
@MANUSCRIPT_DIR = "#{@PROJECT_DIR}/manuscript"
|
28
30
|
@FIGURE_DIR = "#{@MANUSCRIPT_DIR}/figures"
|
29
31
|
@ASSET_DIR = "#{@PROJECT_DIR}/assets"
|
32
|
+
@EPUB_DIR = "#{@PROJECT_DIR}/assets"
|
33
|
+
@HTML_DIR = "#{@PROJECT_DIR}/assets"
|
30
34
|
@ASSET_FILES = 'css,otf,woff,mov,m4v,mp4,mp3,jpeg,jpg,png,svg,gif'
|
31
35
|
@book = YAML.load_file("#{@MANUSCRIPT_DIR}/book.yaml")
|
32
36
|
else
|
@@ -38,22 +42,25 @@ module Carta
|
|
38
42
|
clean
|
39
43
|
generate_html if Dir.exists?('manuscript')
|
40
44
|
end
|
45
|
+
|
41
46
|
def clean
|
42
47
|
thor.remove_dir "#{@PROJECT_DIR}/build"
|
43
48
|
end
|
49
|
+
|
44
50
|
# Generates our HTML from markdown files and creates an outline
|
45
51
|
def generate_html
|
46
52
|
html_renderer = Carta::CLI::HTMLRenderer.new(@PROJECT_DIR)
|
47
53
|
# puts @MANUSCRIPT_DIR
|
48
54
|
book['html'] = html_renderer.manuscript_html
|
49
55
|
book['outline'] = html_renderer.outline
|
50
|
-
book['
|
56
|
+
book['epub_toc_html'] = html_renderer.epub_toc_html
|
57
|
+
book['html_toc_html'] = html_renderer.html_toc_html
|
51
58
|
|
52
|
-
|
59
|
+
generate_epub_manifest
|
53
60
|
end
|
54
61
|
|
55
62
|
# Runs through our ERBs
|
56
|
-
def
|
63
|
+
def render_epub_layouts
|
57
64
|
FileList.new("#{@LAYOUT_DIR}/epub/**/*.erb").each do |layout|
|
58
65
|
filename = layout.pathmap("%{^#{@LAYOUT_DIR},#{@BUILD_DIR}}X")
|
59
66
|
path = filename.pathmap('%d')
|
@@ -65,9 +72,21 @@ module Carta
|
|
65
72
|
handle.write template.result(binding)
|
66
73
|
end
|
67
74
|
end
|
75
|
+
|
76
|
+
FileList.new("#{@LAYOUT_DIR}/html/**/*.erb").each do |layout|
|
77
|
+
filename = layout.pathmap("%{^#{@LAYOUT_DIR},#{@BUILD_DIR}}X")
|
78
|
+
path = filename.pathmap('%d')
|
79
|
+
|
80
|
+
FileUtils.mkpath(path) unless File.exists? path
|
81
|
+
|
82
|
+
template = ERB.new(File.read(layout), nil, '-')
|
83
|
+
File.open(filename, 'w+') do |handle|
|
84
|
+
handle.write template.result(binding)
|
85
|
+
end
|
86
|
+
end
|
68
87
|
end
|
69
88
|
|
70
|
-
def
|
89
|
+
def generate_epub_manifest
|
71
90
|
files = FileList.new("#{@LAYOUT_DIR}/epub/EPUB/*.erb")
|
72
91
|
.pathmap("%{^#{@LAYOUT_DIR}/epub/EPUB/,}X")
|
73
92
|
.exclude('**/*.opf*')
|
@@ -90,7 +109,7 @@ module Carta
|
|
90
109
|
end
|
91
110
|
end
|
92
111
|
copy_files
|
93
|
-
|
112
|
+
render_epub_layouts
|
94
113
|
generate_epub
|
95
114
|
end
|
96
115
|
|
@@ -4,12 +4,14 @@ module Carta
|
|
4
4
|
class CLI::HTMLRenderer
|
5
5
|
attr_accessor :markdown,
|
6
6
|
:manuscript_html,
|
7
|
-
:
|
7
|
+
:epub_toc_html,
|
8
|
+
:html_toc_html,
|
8
9
|
:outline
|
9
10
|
|
10
11
|
def initialize(path)
|
11
12
|
@markdown = ''
|
12
|
-
@
|
13
|
+
@epub_toc_html = ''
|
14
|
+
@html_toc_html = ''
|
13
15
|
@manuscript_html = ''
|
14
16
|
@outline = nil
|
15
17
|
load_markdown(path)
|
@@ -28,28 +30,41 @@ module Carta
|
|
28
30
|
r = Redcarpet::Markdown.new(renderer)
|
29
31
|
manuscript_html << r.render(markdown)
|
30
32
|
@outline = renderer.outline
|
31
|
-
render_outline
|
33
|
+
@epub_toc_html = render_outline
|
34
|
+
@html_toc_html = render_outline('toc',true)
|
35
|
+
|
36
|
+
|
32
37
|
end
|
33
38
|
|
34
|
-
def render_outline(html_class='toc')
|
39
|
+
def render_outline(html_class = 'toc', for_html = false)
|
35
40
|
final_class = "class='#{html_class}'"
|
41
|
+
html = ''
|
36
42
|
outline.each_with_index do |data, i|
|
37
43
|
level, text, link, *children = data
|
38
|
-
|
39
|
-
|
44
|
+
html << "<ol #{final_class}>" if i == 0
|
45
|
+
if for_html
|
46
|
+
html << "\n <li><a href='##{link}'>#{text}</a>"
|
47
|
+
else
|
48
|
+
html << "\n <li><a href='content.xhtml##{link}'>#{text}</a>"
|
49
|
+
end
|
40
50
|
|
41
51
|
if children.empty?
|
42
|
-
|
52
|
+
html << '</li>'
|
43
53
|
else
|
44
54
|
children.each_with_index do |child, j|
|
45
55
|
level, text, link = child
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
html << "\n <ol>" if j == 0
|
57
|
+
if for_html
|
58
|
+
html << "\n <li><a href='##{link}'>#{text}</a></li>"
|
59
|
+
else
|
60
|
+
html << "\n <li><a href='content.xhtml##{link}'>#{text}</a></li>"
|
61
|
+
end
|
62
|
+
html << "\n </ol>\n </li>" if j == children.length - 1
|
49
63
|
end
|
50
64
|
end
|
51
|
-
|
65
|
+
html << "\n</ol>" if i == outline.length - 1
|
52
66
|
end
|
67
|
+
return html
|
53
68
|
end
|
54
69
|
end
|
55
70
|
end
|
data/lib/carta/util.rb
CHANGED
data/lib/carta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Wreggelsworth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|