mint 0.5.1 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/README.md +3 -3
- data/bin/mint +27 -27
- data/bin/mint-epub +6 -6
- data/config/syntax.yaml +12 -12
- data/{templates → config/templates}/base/style.sass +11 -4
- data/config/templates/default/css/style.css +158 -0
- data/config/templates/default/layout.haml +8 -0
- data/{templates → config/templates}/default/style.sass +0 -0
- data/{templates/default → config/templates/protocol}/layout.haml +0 -0
- data/config/templates/protocol/style.sass +20 -0
- data/config/templates/reset.css +92 -0
- data/config/templates/zen/css/style.css +145 -0
- data/{templates/pro → config/templates/zen}/layout.haml +0 -0
- data/config/templates/zen/style.sass +24 -0
- data/features/config.feature +21 -0
- data/features/publish.feature +3 -3
- data/features/support/env.rb +9 -27
- data/features/templates.feature +79 -0
- data/lib/mint.rb +11 -11
- data/lib/mint/{commandline.rb → command_line.rb} +96 -80
- data/lib/mint/css.rb +43 -34
- data/lib/mint/document.rb +99 -93
- data/lib/mint/helpers.rb +21 -17
- data/lib/mint/layout.rb +1 -1
- data/lib/mint/mint.rb +92 -36
- data/lib/mint/plugin.rb +5 -5
- data/lib/mint/plugins/epub.rb +51 -51
- data/lib/mint/resource.rb +2 -2
- data/lib/mint/style.rb +2 -2
- data/lib/mint/version.rb +1 -1
- data/spec/command_line_spec.rb +87 -0
- data/spec/css_spec.rb +46 -0
- data/spec/document_spec.rb +38 -40
- data/spec/helpers_spec.rb +101 -83
- data/spec/layout_spec.rb +1 -1
- data/spec/mint_spec.rb +184 -60
- data/spec/plugin_spec.rb +61 -67
- data/spec/plugins/epub_spec.rb +47 -47
- data/spec/resource_spec.rb +9 -9
- data/spec/spec_helper.rb +20 -93
- data/spec/style_spec.rb +6 -8
- data/spec/support/fixtures/content.md +16 -0
- data/spec/support/fixtures/dynamic.sass +3 -0
- data/spec/support/fixtures/layout.haml +3 -0
- data/spec/support/fixtures/static.css +3 -0
- data/spec/support/matchers.rb +15 -0
- metadata +160 -70
- data/spec/commandline_spec.rb +0 -91
- data/templates/pro/style.sass +0 -0
data/lib/mint/helpers.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "tempfile"
|
3
|
+
require "yaml"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
5
|
|
6
6
|
module Mint
|
7
7
|
module Helpers
|
8
8
|
def self.underscore(obj, opts={})
|
9
|
-
namespaces = obj.to_s.split(
|
9
|
+
namespaces = obj.to_s.split("::").map do |namespace|
|
10
10
|
if opts[:ignore_prefix]
|
11
11
|
namespace[0..1].downcase + namespace[2..-1]
|
12
12
|
else
|
@@ -14,7 +14,7 @@ module Mint
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
string = opts[:namespaces] ? namespaces.join(
|
17
|
+
string = opts[:namespaces] ? namespaces.join("::") : namespaces.last
|
18
18
|
string.underscore
|
19
19
|
end
|
20
20
|
|
@@ -25,10 +25,10 @@ module Mint
|
|
25
25
|
# @return [String] a URL-ready slug
|
26
26
|
def self.slugize(obj)
|
27
27
|
obj.to_s.downcase.
|
28
|
-
gsub(/&/,
|
29
|
-
gsub(/[\s-]+/,
|
30
|
-
gsub(/[^a-z0-9-]/,
|
31
|
-
gsub(/[-]+/,
|
28
|
+
gsub(/&/, "and").
|
29
|
+
gsub(/[\s-]+/, "-").
|
30
|
+
gsub(/[^a-z0-9-]/, "").
|
31
|
+
gsub(/[-]+/, "-")
|
32
32
|
end
|
33
33
|
|
34
34
|
# Transforms a potentially hyphenated String into a symbol name.
|
@@ -36,7 +36,7 @@ module Mint
|
|
36
36
|
# @param [String, #to_s] obj an object to be turned into a symbol name
|
37
37
|
# @return [Symbol] a symbol representation of obj
|
38
38
|
def self.symbolize(obj)
|
39
|
-
slugize(obj).gsub(/-/,
|
39
|
+
slugize(obj).gsub(/-/, "_").to_sym
|
40
40
|
end
|
41
41
|
|
42
42
|
# Transforms a String or Pathname into a fully expanded Pathname.
|
@@ -73,9 +73,9 @@ module Mint
|
|
73
73
|
|
74
74
|
def self.listify(list)
|
75
75
|
if list.length > 2
|
76
|
-
list[0..-2].join(
|
76
|
+
list[0..-2].join(", ") + " & " + list.last
|
77
77
|
else
|
78
|
-
list.join(
|
78
|
+
list.join(" & ")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -103,6 +103,10 @@ module Mint
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
def self.hashify(list1, list2)
|
107
|
+
Hash[*list1.zip(list2).flatten]
|
108
|
+
end
|
109
|
+
|
106
110
|
# Returns the relative path to to_directory from from_directory.
|
107
111
|
# If to_directory and from_directory have no parents in common besides
|
108
112
|
# /, returns the absolute directory of to_directory. Assumes no symlinks.
|
@@ -126,11 +130,11 @@ module Mint
|
|
126
130
|
# @param [Hash, #[]] new_opts a set of options to add to the Yaml file
|
127
131
|
# @param [Pathname, #exist] file a file to read from and write to
|
128
132
|
# @return [void]
|
129
|
-
def self.update_yaml!(
|
130
|
-
curr_opts =
|
133
|
+
def self.update_yaml!(file, opts={})
|
134
|
+
curr_opts = File.exist?(file) ? YAML.load_file(file) : {}
|
131
135
|
|
132
|
-
File.open file,
|
133
|
-
YAML.dump(curr_opts.merge(
|
136
|
+
File.open file, "w" do |f|
|
137
|
+
YAML.dump(curr_opts.merge(opts), f)
|
134
138
|
end
|
135
139
|
end
|
136
140
|
|
data/lib/mint/layout.rb
CHANGED
data/lib/mint/mint.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "fileutils"
|
3
|
+
require "yaml"
|
4
|
+
require "tilt"
|
5
|
+
|
6
|
+
require "active_support/core_ext/hash/slice"
|
5
7
|
|
6
8
|
module Mint
|
9
|
+
ROOT = (Pathname.new(__FILE__).realpath.dirname + "../..").to_s
|
10
|
+
|
11
|
+
SCOPES = {
|
12
|
+
local: Pathname.new(".mint"),
|
13
|
+
user: Pathname.new("~/.mint").expand_path,
|
14
|
+
global: Pathname.new("#{ROOT}/config").expand_path
|
15
|
+
}
|
16
|
+
|
17
|
+
SCOPE_NAMES = SCOPES.keys
|
18
|
+
|
7
19
|
# Assume that someone using an Html template has formatted it
|
8
20
|
# in Erb and that a Css stylesheet will pass untouched through
|
9
21
|
# a Scss parser.
|
@@ -12,21 +24,17 @@ module Mint
|
|
12
24
|
|
13
25
|
# @return [String] the Mint root path name
|
14
26
|
def self.root
|
15
|
-
|
27
|
+
ROOT
|
16
28
|
end
|
17
29
|
|
18
|
-
# Returns an array with the Mint template path
|
19
|
-
#
|
20
|
-
# Either way, earlier/higher paths take precedence. And is considered to
|
21
|
-
# be the directory for "local" config options, templates, etc.
|
30
|
+
# Returns an array with the Mint template path for the named scope
|
31
|
+
# or scopes. This path is used to lookup templates and configuration options.
|
22
32
|
#
|
23
|
-
# @param [
|
24
|
-
# @return [
|
25
|
-
def self.path(
|
26
|
-
|
27
|
-
|
28
|
-
paths = mint_path.split(':')
|
29
|
-
as_path ? paths.map {|p| Pathname.new(p).expand_path } : paths
|
33
|
+
# @param [Hash] opts a list of options, including :scopes
|
34
|
+
# @return [Array] the Mint path as an Array of Pathnames
|
35
|
+
def self.path(opts={})
|
36
|
+
opts = { scopes: SCOPE_NAMES }.merge(opts)
|
37
|
+
SCOPES.slice(*opts[:scopes]).values
|
30
38
|
end
|
31
39
|
|
32
40
|
# Returns the part of Mint.path relevant to scope.
|
@@ -43,9 +51,9 @@ module Mint
|
|
43
51
|
case Mint.path
|
44
52
|
when Array
|
45
53
|
index = { local: 0, user: 1, global: 2 }[scope]
|
46
|
-
Mint.path
|
54
|
+
Mint.path[index]
|
47
55
|
when Hash
|
48
|
-
Mint.path
|
56
|
+
Mint.path[scope]
|
49
57
|
else
|
50
58
|
nil
|
51
59
|
end
|
@@ -54,16 +62,15 @@ module Mint
|
|
54
62
|
# @return [Hash] key Mint directories
|
55
63
|
def self.directories
|
56
64
|
{
|
57
|
-
templates:
|
58
|
-
config: 'config'
|
65
|
+
templates: "templates"
|
59
66
|
}
|
60
67
|
end
|
61
68
|
|
62
69
|
# @return [Hash] key Mint files
|
63
70
|
def self.files
|
64
71
|
{
|
65
|
-
syntax:
|
66
|
-
|
72
|
+
syntax: "syntax.yaml",
|
73
|
+
defaults: "defaults.yaml"
|
67
74
|
}
|
68
75
|
end
|
69
76
|
|
@@ -72,8 +79,8 @@ module Mint
|
|
72
79
|
{
|
73
80
|
# Do not set default `template`--will override style and
|
74
81
|
# layout when already specified -- causes tricky bugs
|
75
|
-
layout:
|
76
|
-
style:
|
82
|
+
layout: "default", # default layout
|
83
|
+
style: "default", # default style
|
77
84
|
destination: nil, # do not create a subdirectory
|
78
85
|
style_destination: nil # do not copy style to root
|
79
86
|
}
|
@@ -87,18 +94,51 @@ module Mint
|
|
87
94
|
# @return [Array] CSS formats, for source -> destination
|
88
95
|
# name guessing/conversion only.
|
89
96
|
def self.css_formats
|
90
|
-
[
|
97
|
+
["css", "sass", "scss", "less"]
|
91
98
|
end
|
92
99
|
|
93
|
-
#
|
94
|
-
|
95
|
-
|
100
|
+
# Returns a hash of all active options specified by file (for all scopes).
|
101
|
+
# That is, if you specify file as "defaults.yaml", this will return the aggregate
|
102
|
+
# of all defaults.yaml-specified options in the Mint path, where more local
|
103
|
+
# members of the path take precedence over more global ones.
|
104
|
+
#
|
105
|
+
# @param [String] file a filename pointing to a Mint configuration file
|
106
|
+
# @return [Hash] a structured set of configuration options
|
107
|
+
def self.configuration(opts={})
|
108
|
+
opts = { scopes: SCOPE_NAMES }.merge(opts)
|
109
|
+
|
110
|
+
# Merge config options from all config files on the Mint path,
|
111
|
+
# where more local options take precedence over more global
|
112
|
+
# options
|
113
|
+
configuration = Mint.path(:scopes => opts[:scopes]).
|
114
|
+
map {|p| p + Mint.files[:defaults] }.
|
115
|
+
select(&:exist?).
|
116
|
+
map {|p| YAML.load_file p }.
|
117
|
+
reverse.
|
118
|
+
reduce(Mint.default_options) {|r,p| r.merge p }
|
119
|
+
|
120
|
+
Helpers.symbolize_keys configuration
|
121
|
+
end
|
96
122
|
|
97
|
-
|
123
|
+
# Returns all configuration options (as specified by the aggregate
|
124
|
+
# of all config files), along with opts, where opts take precedence.
|
125
|
+
#
|
126
|
+
# @param [Hash] additional options to add to the current configuration
|
127
|
+
# @return [Hash] a structured set of configuration options with opts
|
128
|
+
# overriding any options from config files
|
129
|
+
def self.configuration_with(opts)
|
130
|
+
configuration.merge opts
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [Array] the full path for each known template in the Mint path
|
134
|
+
def self.templates(opts={})
|
135
|
+
opts = { scopes: SCOPE_NAMES }.merge(opts)
|
136
|
+
Mint.path(:scopes => opts[:scopes]).
|
98
137
|
map {|p| p + directories[:templates] }.
|
99
138
|
select(&:exist?).
|
100
139
|
map {|p| p.children.select(&:directory?).map(&:to_s) }.
|
101
|
-
flatten
|
140
|
+
flatten.
|
141
|
+
sort
|
102
142
|
end
|
103
143
|
|
104
144
|
# Decides whether the template specified by `name_or_file` is a real
|
@@ -139,14 +179,30 @@ module Mint
|
|
139
179
|
|
140
180
|
file_name = lambda {|x| x + templates_dir + name + type.to_s }
|
141
181
|
find_files = lambda {|x| Pathname.glob "#{x.to_s}.*" }
|
142
|
-
acceptable = lambda {|x| x.to_s =~ /#{Mint.formats.join
|
182
|
+
acceptable = lambda {|x| x.to_s =~ /#{Mint.formats.join "|"}/ }
|
143
183
|
|
144
|
-
Mint.path
|
184
|
+
Mint.path.map(&file_name).map(&find_files).flatten.
|
145
185
|
select(&acceptable).select(&:exist?).first.tap do |template|
|
146
186
|
raise TemplateNotFoundException unless template
|
147
187
|
end.to_s
|
148
188
|
end
|
149
189
|
|
190
|
+
def self.template_path(name, type, opts={})
|
191
|
+
defaults = {
|
192
|
+
scope: :local,
|
193
|
+
ext: { layout: "haml", style: "sass" }[type]
|
194
|
+
}
|
195
|
+
opts = defaults.merge(opts)
|
196
|
+
path = Mint.path_for_scope(opts[:scope])
|
197
|
+
|
198
|
+
case type
|
199
|
+
when :layout, :style
|
200
|
+
"#{path}/templates/#{name}/#{type}.#{opts[:ext]}"
|
201
|
+
when :all
|
202
|
+
"#{path}/templates/#{name}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
150
206
|
# Checks (non-rigorously) to see if the file is somewhere on the
|
151
207
|
# MINT_PATH
|
152
208
|
#
|
@@ -156,7 +212,7 @@ module Mint
|
|
156
212
|
paths = Mint.path.map {|f| File.expand_path f }
|
157
213
|
file_path = Pathname.new(file)
|
158
214
|
file_path.exist? and
|
159
|
-
file_path.dirname.expand_path.to_s =~ /#{paths.join(
|
215
|
+
file_path.dirname.expand_path.to_s =~ /#{paths.map(&:to_s).join("|")}/
|
160
216
|
end
|
161
217
|
|
162
218
|
# Guesses an appropriate name for the resource output file based on
|
@@ -166,10 +222,10 @@ module Mint
|
|
166
222
|
# @return [String] probably output file name
|
167
223
|
def self.guess_name_from(name)
|
168
224
|
name = Pathname(name).basename if name
|
169
|
-
css = Mint.css_formats.join
|
225
|
+
css = Mint.css_formats.join "|"
|
170
226
|
name.to_s.
|
171
|
-
gsub(/\.(#{css})$/,
|
172
|
-
gsub(/(\.[^css]+)$/,
|
227
|
+
gsub(/\.(#{css})$/, ".css").
|
228
|
+
gsub(/(\.[^css]+)$/, ".html")
|
173
229
|
end
|
174
230
|
|
175
231
|
# Transforms a path into a template that will render the file specified
|
data/lib/mint/plugin.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "mint/document"
|
2
|
+
require "set"
|
3
3
|
|
4
4
|
module Mint
|
5
5
|
def self.plugins
|
@@ -28,15 +28,15 @@ module Mint
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.template_directory(plugin)
|
31
|
-
Mint.root +
|
31
|
+
Mint.root + "/plugins/templates/" + plugin.underscore
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.config_directory(plugin)
|
35
|
-
Mint.root +
|
35
|
+
Mint.root + "/plugins/config/" + plugin.underscore
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.commandline_options_file(plugin)
|
39
|
-
plugin.config_directory +
|
39
|
+
plugin.config_directory + "/syntax.yml"
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.commandline_name(plugin)
|
data/lib/mint/plugins/epub.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "nokogiri"
|
2
|
+
require "hashie"
|
3
|
+
require "zip/zip"
|
4
|
+
require "zip/zipfilesystem"
|
5
|
+
require "active_support/core_ext/hash/deep_merge"
|
6
|
+
require "active_support/core_ext/hash/keys"
|
7
7
|
|
8
8
|
# Note: This code is not as clean as I want it to be. It is an example
|
9
9
|
# plugin with which I'm developing the Mint plugin system. Code cleanup
|
10
10
|
# to follow.
|
11
11
|
|
12
12
|
module Mint
|
13
|
-
META_DIR =
|
14
|
-
CONTENT_DIR =
|
13
|
+
META_DIR = "META-INF"
|
14
|
+
CONTENT_DIR = "OPS"
|
15
15
|
|
16
16
|
# Add chapters to document -- this is probably not a sustainable pattern
|
17
17
|
# for all plugins, but it's useful here.
|
18
18
|
class Document
|
19
19
|
def chapters
|
20
20
|
html_document = Nokogiri::HTML::Document.parse render
|
21
|
-
EPub.split_on(html_document,
|
21
|
+
EPub.split_on(html_document, "h2").map &:to_s
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,7 @@ module Mint
|
|
26
26
|
|
27
27
|
class EPub < Plugin
|
28
28
|
def self.after_publish(document)
|
29
|
-
# This check doesn't currently follow
|
29
|
+
# This check doesn't currently follow symlinks
|
30
30
|
if document.destination_directory == Dir.getwd
|
31
31
|
raise InvalidDocumentError
|
32
32
|
end
|
@@ -40,22 +40,22 @@ module Mint
|
|
40
40
|
create_chapters! chapters, :locals => metadata
|
41
41
|
|
42
42
|
create! do |container|
|
43
|
-
container.type =
|
43
|
+
container.type = "container"
|
44
44
|
container.locals = locals
|
45
45
|
end
|
46
46
|
|
47
47
|
create! do |content|
|
48
|
-
content.type =
|
48
|
+
content.type = "content"
|
49
49
|
content.locals = locals
|
50
50
|
end
|
51
51
|
|
52
52
|
create! do |toc|
|
53
|
-
toc.type =
|
53
|
+
toc.type = "toc"
|
54
54
|
toc.locals = locals
|
55
55
|
end
|
56
56
|
|
57
57
|
create! do |title|
|
58
|
-
title.type =
|
58
|
+
title.type = "title"
|
59
59
|
title.locals = locals
|
60
60
|
end
|
61
61
|
end
|
@@ -63,8 +63,8 @@ module Mint
|
|
63
63
|
FileUtils.rm document.destination_file
|
64
64
|
|
65
65
|
self.zip! document.destination_directory,
|
66
|
-
:mimetype =>
|
67
|
-
:extension =>
|
66
|
+
:mimetype => "application/epub+zip",
|
67
|
+
:extension => "epub"
|
68
68
|
|
69
69
|
FileUtils.rm_r document.destination_directory
|
70
70
|
end
|
@@ -72,7 +72,7 @@ module Mint
|
|
72
72
|
protected
|
73
73
|
|
74
74
|
def self.split_on(document, tag_name, opts={})
|
75
|
-
container_node = opts[:container] ||
|
75
|
+
container_node = opts[:container] || "#container"
|
76
76
|
|
77
77
|
new_document = document.dup.tap do |node|
|
78
78
|
container = node.at container_node
|
@@ -86,22 +86,22 @@ module Mint
|
|
86
86
|
div = nil
|
87
87
|
container.element_children.each do |elem|
|
88
88
|
if elem.name == tag_name
|
89
|
-
div = node.create_element
|
90
|
-
# div.add_class
|
89
|
+
div = node.create_element "div"
|
90
|
+
# div.add_class "chapter"
|
91
91
|
elem.replace div
|
92
92
|
end
|
93
93
|
div << elem if div
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
new_document.search(
|
97
|
+
new_document.search("div div")
|
98
98
|
end
|
99
99
|
|
100
100
|
# This is an opinionated version of ZIP, specifically
|
101
101
|
# tailored to ePub creation
|
102
102
|
def self.zip!(directory, opts={})
|
103
103
|
default_opts = {
|
104
|
-
extension:
|
104
|
+
extension: "zip",
|
105
105
|
mimetype: nil
|
106
106
|
}
|
107
107
|
|
@@ -112,7 +112,7 @@ module Mint
|
|
112
112
|
|
113
113
|
Zip::ZipOutputStream.open "#{directory}.#{extension}" do |zos|
|
114
114
|
if opts[:mimetype]
|
115
|
-
zos.put_next_entry(
|
115
|
+
zos.put_next_entry("mimetype", nil, nil, Zip::ZipEntry::STORED)
|
116
116
|
zos << opts[:mimetype]
|
117
117
|
end
|
118
118
|
|
@@ -136,7 +136,7 @@ module Mint
|
|
136
136
|
yield options if block_given?
|
137
137
|
options = options.to_hash.symbolize_keys
|
138
138
|
|
139
|
-
type = options[:type] ||
|
139
|
+
type = options[:type] || "container"
|
140
140
|
default_options =
|
141
141
|
case type.to_sym
|
142
142
|
when :container
|
@@ -156,7 +156,7 @@ module Mint
|
|
156
156
|
|
157
157
|
def self.create_chapters!(chapters, opts={})
|
158
158
|
opts = chapter_defaults.deep_merge(opts)
|
159
|
-
template_file = EPub.template_directory +
|
159
|
+
template_file = EPub.template_directory + "/layouts/layout.haml"
|
160
160
|
renderer = Tilt.new template_file, :ugly => true
|
161
161
|
chapters.map do |chapter|
|
162
162
|
renderer.render Object.new, opts[:locals].merge(:content => chapter)
|
@@ -172,7 +172,7 @@ module Mint
|
|
172
172
|
renderer = Tilt.new template_file, :ugly => true
|
173
173
|
content = renderer.render Object.new, opts[:locals]
|
174
174
|
|
175
|
-
File.open(opts[:to],
|
175
|
+
File.open(opts[:to], "w") do |f|
|
176
176
|
f << content
|
177
177
|
end
|
178
178
|
end
|
@@ -215,13 +215,13 @@ module Mint
|
|
215
215
|
# def self.chapters_from(document)
|
216
216
|
# html_text = File.read document.destination_file
|
217
217
|
# html_document = Nokogiri::HTML::Document.parse html_text
|
218
|
-
# chapter_contents = self.split_on(html_document,
|
218
|
+
# chapter_contents = self.split_on(html_document, "h2")
|
219
219
|
# chapter_ids = (1..chapters.length).map {|x| "chapter-#{x}" }
|
220
220
|
# chapters = Hash[chapter_ids.zip chapter_contents]
|
221
221
|
# end
|
222
222
|
|
223
223
|
def self.create_chapter!(id, text)
|
224
|
-
File.open chapter_filename(id),
|
224
|
+
File.open chapter_filename(id), "w" do |file|
|
225
225
|
file << text
|
226
226
|
end
|
227
227
|
end
|
@@ -229,64 +229,64 @@ module Mint
|
|
229
229
|
def self.chapter_defaults
|
230
230
|
{
|
231
231
|
locals: {
|
232
|
-
title:
|
232
|
+
title: "Untitled"
|
233
233
|
}
|
234
234
|
}
|
235
235
|
end
|
236
236
|
|
237
237
|
def self.container_defaults
|
238
238
|
defaults = {
|
239
|
-
from:
|
239
|
+
from: "container.haml",
|
240
240
|
to: "#{META_DIR}/container.xml",
|
241
241
|
locals: {
|
242
|
-
opf_file:
|
242
|
+
opf_file: "OPS/content.opf"
|
243
243
|
}
|
244
244
|
}
|
245
245
|
end
|
246
246
|
|
247
247
|
def self.content_defaults
|
248
248
|
defaults = {
|
249
|
-
from:
|
249
|
+
from: "content.haml",
|
250
250
|
to: "#{CONTENT_DIR}/content.opf",
|
251
251
|
locals: {
|
252
|
-
title:
|
253
|
-
language:
|
254
|
-
short_title:
|
255
|
-
uuid:
|
256
|
-
description:
|
252
|
+
title: "Untitled",
|
253
|
+
language: "English",
|
254
|
+
short_title: "",
|
255
|
+
uuid: "Unspecified",
|
256
|
+
description: "No description",
|
257
257
|
date: Date.today,
|
258
|
-
creators: [
|
258
|
+
creators: ["Anonymous"],
|
259
259
|
contributors: [],
|
260
|
-
publisher:
|
261
|
-
genre:
|
262
|
-
rights:
|
263
|
-
ncx_file:
|
264
|
-
stylesheet:
|
265
|
-
title_file:
|
260
|
+
publisher: "Self published",
|
261
|
+
genre: "Non-fiction",
|
262
|
+
rights: "All Rights Reserved",
|
263
|
+
ncx_file: "toc.ncx",
|
264
|
+
stylesheet: "style.css",
|
265
|
+
title_file: "title.html",
|
266
266
|
}
|
267
267
|
}
|
268
268
|
end
|
269
269
|
|
270
270
|
def self.toc_defaults
|
271
271
|
defaults = {
|
272
|
-
from:
|
272
|
+
from: "toc.haml",
|
273
273
|
to: "#{CONTENT_DIR}/toc.ncx",
|
274
274
|
locals: {
|
275
|
-
uuid:
|
276
|
-
title:
|
277
|
-
title_file:
|
275
|
+
uuid: "Unspecified",
|
276
|
+
title: "Untitled",
|
277
|
+
title_file: "title.html",
|
278
278
|
}
|
279
279
|
}
|
280
280
|
end
|
281
281
|
|
282
282
|
def self.title_defaults
|
283
283
|
defaults = {
|
284
|
-
from:
|
284
|
+
from: "title.haml",
|
285
285
|
to: "#{CONTENT_DIR}/title.html",
|
286
286
|
locals: {
|
287
|
-
title:
|
288
|
-
creators: [
|
289
|
-
stylesheet:
|
287
|
+
title: "Untitled",
|
288
|
+
creators: ["Anonymous"],
|
289
|
+
stylesheet: "style.css"
|
290
290
|
}
|
291
291
|
}
|
292
292
|
end
|