mint 0.7.4 → 0.8.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.
- checksums.yaml +7 -0
- data/Gemfile +23 -14
- data/LICENSE +22 -0
- data/README.md +68 -79
- data/bin/mint +47 -10
- data/bin/mint-epub +1 -4
- data/config/templates/base/style.css +187 -0
- data/config/templates/default/layout.erb +10 -0
- data/config/templates/default/style.css +237 -0
- data/config/templates/garden/layout.erb +38 -0
- data/config/templates/garden/style.css +303 -0
- data/config/templates/nord/layout.erb +11 -0
- data/config/templates/nord/style.css +339 -0
- data/config/templates/nord-dark/layout.erb +11 -0
- data/config/templates/nord-dark/style.css +339 -0
- data/config/templates/zen/layout.erb +11 -0
- data/config/templates/zen/style.css +114 -0
- data/lib/mint/command_line.rb +253 -111
- data/lib/mint/css.rb +11 -4
- data/lib/mint/css_parser.rb +76 -0
- data/lib/mint/css_template.rb +37 -0
- data/lib/mint/document.rb +203 -43
- data/lib/mint/helpers.rb +50 -10
- data/lib/mint/layout.rb +2 -3
- data/lib/mint/markdown_template.rb +47 -0
- data/lib/mint/mint.rb +181 -114
- data/lib/mint/plugin.rb +3 -3
- data/lib/mint/plugins/epub.rb +1 -2
- data/lib/mint/resource.rb +19 -9
- data/lib/mint/style.rb +10 -14
- data/lib/mint/version.rb +1 -1
- data/lib/mint.rb +1 -0
- data/man/mint.1 +135 -0
- data/spec/cli/README.md +99 -0
- data/spec/cli/argument_parsing_spec.rb +237 -0
- data/spec/cli/bin_integration_spec.rb +348 -0
- data/spec/cli/configuration_management_spec.rb +363 -0
- data/spec/cli/full_workflow_integration_spec.rb +527 -0
- data/spec/cli/publish_workflow_spec.rb +368 -0
- data/spec/cli/template_management_spec.rb +300 -0
- data/spec/css_parser_spec.rb +149 -0
- data/spec/css_spec.rb +1 -1
- data/spec/document_spec.rb +102 -69
- data/spec/helpers_spec.rb +42 -42
- data/spec/mint_spec.rb +104 -80
- data/spec/plugin_spec.rb +141 -143
- data/spec/run_cli_tests.rb +95 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/style_spec.rb +18 -16
- data/spec/support/cli_helpers.rb +169 -0
- data/spec/support/fixtures/content-2.md +16 -0
- data/spec/support/matchers.rb +1 -1
- metadata +116 -224
- data/config/syntax.yaml +0 -71
- data/config/templates/base/style.sass +0 -144
- data/config/templates/default/css/style.css +0 -158
- data/config/templates/default/layout.haml +0 -8
- data/config/templates/default/style.sass +0 -36
- data/config/templates/protocol/layout.haml +0 -7
- data/config/templates/protocol/style.sass +0 -20
- data/config/templates/zen/css/style.css +0 -145
- data/config/templates/zen/layout.haml +0 -7
- data/config/templates/zen/style.sass +0 -24
- data/features/config.feature +0 -21
- data/features/plugins/epub.feature +0 -23
- data/features/publish.feature +0 -73
- data/features/support/env.rb +0 -15
- data/features/templates.feature +0 -79
- data/spec/command_line_spec.rb +0 -87
- data/spec/plugins/epub_spec.rb +0 -242
data/lib/mint/mint.rb
CHANGED
@@ -1,94 +1,75 @@
|
|
1
|
+
|
1
2
|
require "pathname"
|
2
3
|
require "fileutils"
|
3
4
|
require "yaml"
|
4
5
|
require "tilt"
|
5
|
-
|
6
|
+
require "tilt/mapping"
|
6
7
|
require "active_support/core_ext/hash/slice"
|
8
|
+
require "active_support/core_ext/string/output_safety"
|
9
|
+
require "mint/css_template"
|
10
|
+
require "mint/markdown_template"
|
7
11
|
|
8
12
|
module Mint
|
9
|
-
ROOT
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
ROOT = (Pathname.new(__FILE__).realpath.dirname + "../..").to_s
|
14
|
+
MARKDOWN_EXTENSIONS = %w[md markdown mkd].freeze
|
15
|
+
LOCAL_SCOPE = Pathname.new(".mint")
|
16
|
+
USER_SCOPE = Pathname.new("~/.config/mint").expand_path
|
17
|
+
GLOBAL_SCOPE = Pathname.new("#{ROOT}/config").expand_path
|
18
|
+
SCOPES = { local: LOCAL_SCOPE, user: USER_SCOPE, global: GLOBAL_SCOPE }
|
19
|
+
SCOPE_NAMES = SCOPES.keys
|
20
|
+
CONFIG_FILE = "config.yaml"
|
21
|
+
TEMPLATES_DIRECTORY = "templates"
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def self.default_options
|
24
|
+
{
|
25
|
+
root: Dir.getwd,
|
26
|
+
destination: nil,
|
27
|
+
style_mode: :inline,
|
28
|
+
style_destination: nil,
|
29
|
+
output_file: '#{basename}.#{new_extension}',
|
30
|
+
layout_or_style_or_template: [:template, 'default'],
|
31
|
+
scope: :local,
|
32
|
+
recursive: false,
|
33
|
+
verbose: false
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.mapping
|
38
|
+
if @mapping
|
39
|
+
@mapping
|
40
|
+
else
|
41
|
+
@mapping = Tilt::Mapping.new.tap do |m|
|
42
|
+
m.register Mint::CSSTemplate, 'css' # Inline Css @imports, creating a single file
|
43
|
+
m.register Mint::MarkdownTemplate, 'txt' # Process Txt as Markdown
|
44
|
+
m.register Mint::MarkdownTemplate, *MARKDOWN_EXTENSIONS
|
45
|
+
m.register Tilt::ScssTemplate, 'scss'
|
46
|
+
m.register Tilt::SassTemplate, 'sass'
|
47
|
+
m.register Tilt::ERBTemplate, 'erb', 'html' # Allow for Erb inside HTML
|
48
|
+
m.register Tilt::HamlTemplate, 'haml'
|
49
|
+
end
|
50
|
+
end
|
28
51
|
end
|
29
52
|
|
30
53
|
# Returns an array with the Mint template path for the named scope
|
31
54
|
# or scopes. This path is used to lookup templates and configuration options.
|
32
55
|
#
|
33
|
-
# @param [
|
56
|
+
# @param [Array] scopes a list of scopes to include
|
34
57
|
# @return [Array] the Mint path as an Array of Pathnames
|
35
|
-
def self.path(
|
36
|
-
|
37
|
-
SCOPES.slice(*opts[:scopes]).values
|
58
|
+
def self.path(scopes = SCOPE_NAMES)
|
59
|
+
SCOPES.slice(*scopes).values
|
38
60
|
end
|
39
61
|
|
40
|
-
# Returns the
|
41
|
-
# I want to refactor this so that Mint.path is always a Hash...
|
42
|
-
# should take care of this in the Mint.path=() method.
|
43
|
-
# Right now, this is a hack. It assumes a sane MINT_PATH, where the
|
44
|
-
# first entry is most local, the second is user-level,
|
45
|
-
# and the last entry is most global.
|
62
|
+
# Returns the base directory for Mint configuration at the specified scope.
|
46
63
|
#
|
47
64
|
# @param [Symbol] scope the scope we want to find the path for
|
48
|
-
# @
|
49
|
-
|
50
|
-
|
51
|
-
case Mint.path
|
52
|
-
when Array
|
53
|
-
index = { local: 0, user: 1, global: 2 }[scope]
|
54
|
-
Mint.path[index]
|
55
|
-
when Hash
|
56
|
-
Mint.path[scope]
|
57
|
-
else
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# @return [Hash] key Mint directories
|
63
|
-
def self.directories
|
64
|
-
{
|
65
|
-
templates: "templates"
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
# @return [Hash] key Mint files
|
70
|
-
def self.files
|
71
|
-
{
|
72
|
-
syntax: "syntax.yaml",
|
73
|
-
defaults: "defaults.yaml"
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
# @return [Hash] last-resort options for creating Mint documents.
|
78
|
-
def self.default_options
|
79
|
-
{
|
80
|
-
# Do not set default `template`--will override style and
|
81
|
-
# layout when already specified -- causes tricky bugs
|
82
|
-
layout: "default", # default layout
|
83
|
-
style: "default", # default style
|
84
|
-
destination: nil, # do not create a subdirectory
|
85
|
-
style_destination: nil # do not copy style to root
|
86
|
-
}
|
65
|
+
# @return [Pathname] the Mint path for +scope+ as a Pathname
|
66
|
+
def self.path_for_scope(scope = :local)
|
67
|
+
SCOPES[scope]
|
87
68
|
end
|
88
69
|
|
89
70
|
# @return [Array] all file extensions that Tilt will render
|
90
71
|
def self.formats
|
91
|
-
|
72
|
+
mapping.template_map.keys
|
92
73
|
end
|
93
74
|
|
94
75
|
# @return [Array] CSS formats, for source -> destination
|
@@ -97,6 +78,7 @@ module Mint
|
|
97
78
|
["css", "sass", "scss", "less"]
|
98
79
|
end
|
99
80
|
|
81
|
+
|
100
82
|
# Returns a hash of all active options specified by file (for all scopes).
|
101
83
|
# That is, if you specify file as "defaults.yaml", this will return the aggregate
|
102
84
|
# of all defaults.yaml-specified options in the Mint path, where more local
|
@@ -110,10 +92,16 @@ module Mint
|
|
110
92
|
# Merge config options from all config files on the Mint path,
|
111
93
|
# where more local options take precedence over more global
|
112
94
|
# options
|
113
|
-
configuration = Mint.path(
|
114
|
-
map {|p| p + Mint
|
95
|
+
configuration = Mint.path(opts[:scopes]).
|
96
|
+
map {|p| p + Mint::CONFIG_FILE }.
|
115
97
|
select(&:exist?).
|
116
|
-
map
|
98
|
+
map do |p|
|
99
|
+
begin
|
100
|
+
YAML.load_file p
|
101
|
+
rescue Psych::SyntaxError, StandardError => e
|
102
|
+
{}
|
103
|
+
end
|
104
|
+
end.
|
117
105
|
reverse.
|
118
106
|
reduce(Mint.default_options) {|r,p| r.merge p }
|
119
107
|
|
@@ -127,42 +115,79 @@ module Mint
|
|
127
115
|
# @return [Hash] a structured set of configuration options with opts
|
128
116
|
# overriding any options from config files
|
129
117
|
def self.configuration_with(opts)
|
130
|
-
|
118
|
+
scopes = if opts[:local] || opts[:user] || opts[:global]
|
119
|
+
if opts[:local]
|
120
|
+
[:local]
|
121
|
+
elsif opts[:user]
|
122
|
+
[:user]
|
123
|
+
elsif opts[:global]
|
124
|
+
[:global]
|
125
|
+
end
|
126
|
+
else
|
127
|
+
SCOPE_NAMES
|
128
|
+
end
|
129
|
+
|
130
|
+
processed_opts = opts.dup
|
131
|
+
if processed_opts[:layout_or_style_or_template]
|
132
|
+
option_type, option_value = processed_opts.delete(:layout_or_style_or_template)
|
133
|
+
case option_type
|
134
|
+
when :template
|
135
|
+
processed_opts[:template] = option_value
|
136
|
+
when :layout
|
137
|
+
processed_opts[:layout] = option_value
|
138
|
+
when :style
|
139
|
+
processed_opts[:style] = option_value
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
configuration(scopes: scopes).merge processed_opts
|
131
144
|
end
|
132
145
|
|
133
146
|
# @return [Array] the full path for each known template in the Mint path
|
134
|
-
def self.templates(
|
135
|
-
|
136
|
-
|
137
|
-
map {|p| p + directories[:templates] }.
|
147
|
+
def self.templates(scope = :local)
|
148
|
+
Mint.path([scope]).
|
149
|
+
map {|p| p + TEMPLATES_DIRECTORY }.
|
138
150
|
select(&:exist?).
|
139
151
|
map {|p| p.children.select(&:directory?).map(&:to_s) }.
|
140
152
|
flatten.
|
141
153
|
sort
|
142
154
|
end
|
143
155
|
|
144
|
-
#
|
145
|
-
# file or the name of a template. If it is a real file, Mint will
|
146
|
-
# return a that file. Otherwise, Mint will look for a file with that
|
147
|
-
# name in the Mint path. The `type` argument indicates whether the
|
148
|
-
# template we are looking for is a layout or a style and will affect
|
149
|
-
# which type of template is returned for a given template name. For
|
150
|
-
# example, `lookup_template :normal` might return a layout template
|
151
|
-
# referring to the file ~/.mint/templates/normal/layout.erb.
|
152
|
-
# Adding :style as a second argument returns
|
153
|
-
# ~/.mint/templates/normal/style.css.
|
156
|
+
# Returns the template directory for the given template name
|
154
157
|
#
|
155
|
-
# @param [String, File, #to_s] name_or_file a name or template file
|
158
|
+
# @param [String, File, #to_s] name_or_file a name or template file
|
156
159
|
# to look up
|
157
160
|
# @param [Symbol] type the resource type to look up
|
158
161
|
# @return [File] the named, typed template file
|
159
162
|
def self.lookup_template(name_or_file, type=:layout)
|
160
163
|
name = name_or_file.to_s
|
161
|
-
|
164
|
+
|
165
|
+
# Only treat as a direct file if it's an actual file (not directory)
|
166
|
+
if File.file?(name) && formats.include?(File.extname(name)[1..-1])
|
167
|
+
Pathname.new(name).dirname
|
168
|
+
else
|
169
|
+
Pathname.new(find_template_directory(name))
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Returns the layout file for the given template name
|
174
|
+
#
|
175
|
+
# @param [String] name the template name to look up
|
176
|
+
# @return [String] path to the layout file
|
177
|
+
def self.lookup_layout(name)
|
178
|
+
find_template(name, :layout)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the style file for the given template name
|
182
|
+
#
|
183
|
+
# @param [String] name the template name to look up
|
184
|
+
# @return [String] path to the style file
|
185
|
+
def self.lookup_style(name)
|
186
|
+
find_template(name, :style)
|
162
187
|
end
|
163
188
|
|
164
189
|
# Finds a template named `name` in the Mint path. If `type` is :layout,
|
165
|
-
# will look for `MINT_PATH/templates/layout.*`. If it is :style, will
|
190
|
+
# will look for `MINT_PATH/templates/template_name/layout.*`. If it is :style, will
|
166
191
|
# look for `MINT_PATH/templates/template_name/style.*`. Mint assumes
|
167
192
|
# that a named template will hold only one layout and one style template.
|
168
193
|
# It does not know how to decide between style.css and style.less, for
|
@@ -175,32 +200,74 @@ module Mint
|
|
175
200
|
#
|
176
201
|
# @return [File] the named, typed template file
|
177
202
|
def self.find_template(name, type)
|
178
|
-
|
179
|
-
|
180
|
-
file_name = lambda {|x| x + templates_dir + name + type.to_s }
|
203
|
+
file_name = lambda {|x| x + Mint::TEMPLATES_DIRECTORY + name + type.to_s }
|
181
204
|
find_files = lambda {|x| Pathname.glob "#{x.to_s}.*" }
|
182
|
-
acceptable = lambda {|x|
|
205
|
+
acceptable = lambda {|x|
|
206
|
+
ext = File.extname(x.to_s)[1..-1]
|
207
|
+
return false unless ext
|
208
|
+
case type
|
209
|
+
when :layout
|
210
|
+
formats.include?(ext)
|
211
|
+
when :style
|
212
|
+
css_formats.include?(ext)
|
213
|
+
else
|
214
|
+
false
|
215
|
+
end
|
216
|
+
}
|
183
217
|
|
184
|
-
Mint.path.
|
185
|
-
|
186
|
-
|
187
|
-
|
218
|
+
template_file = Mint.path.
|
219
|
+
map(&file_name).
|
220
|
+
map(&find_files).
|
221
|
+
flatten.
|
222
|
+
select(&acceptable).
|
223
|
+
select(&:exist?).
|
224
|
+
first
|
225
|
+
|
226
|
+
unless template_file
|
227
|
+
template_dirs = Mint.path.map {|p| p + Mint::TEMPLATES_DIRECTORY + name }.select(&:exist?)
|
228
|
+
if template_dirs.any?
|
229
|
+
expected_exts = case type
|
230
|
+
when :layout then formats.join(', ')
|
231
|
+
when :style then css_formats.join(', ')
|
232
|
+
end
|
233
|
+
raise TemplateNotFoundException, "Template '#{name}' exists but has no valid #{type} file. Expected #{type}.{#{expected_exts}}"
|
234
|
+
else
|
235
|
+
raise TemplateNotFoundException, "Template '#{name}' does not exist."
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
template_file.to_s
|
188
240
|
end
|
189
241
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
"#{path}/templates/#{name}"
|
242
|
+
# Finds a template directory by name
|
243
|
+
#
|
244
|
+
# @param [String] name the template name to find
|
245
|
+
# @return [String] path to the template directory
|
246
|
+
def self.find_template_directory(name)
|
247
|
+
template_dir = Mint.path.
|
248
|
+
map {|p| p + Mint::TEMPLATES_DIRECTORY + name }.
|
249
|
+
select(&:exist?).
|
250
|
+
first
|
251
|
+
|
252
|
+
unless template_dir
|
253
|
+
raise TemplateNotFoundException, "Template '#{name}' does not exist."
|
203
254
|
end
|
255
|
+
|
256
|
+
template_dir.to_s
|
257
|
+
end
|
258
|
+
|
259
|
+
# Finds a specific template file by name and type
|
260
|
+
#
|
261
|
+
# @param [String] name the template name to find
|
262
|
+
# @param [Symbol] type :layout or :style
|
263
|
+
# @return [String] path to the template file
|
264
|
+
def self.find_template_file(name, type)
|
265
|
+
find_template(name, type)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Returns the template directory for the given scope, if found
|
269
|
+
def self.template_path(name, scope)
|
270
|
+
Mint.path_for_scope(scope) + "templates/#{name}"
|
204
271
|
end
|
205
272
|
|
206
273
|
# Checks (non-rigorously) to see if the file is somewhere on the
|
@@ -211,7 +278,7 @@ module Mint
|
|
211
278
|
def self.template?(file)
|
212
279
|
paths = Mint.path.map {|f| File.expand_path f }
|
213
280
|
file_path = Pathname.new(file)
|
214
|
-
file_path.exist? and
|
281
|
+
file_path.exist? and
|
215
282
|
file_path.dirname.expand_path.to_s =~ /#{paths.map(&:to_s).join("|")}/
|
216
283
|
end
|
217
284
|
|
@@ -225,7 +292,7 @@ module Mint
|
|
225
292
|
css = Mint.css_formats.join "|"
|
226
293
|
name.to_s.
|
227
294
|
gsub(/\.(#{css})$/, ".css").
|
228
|
-
gsub(/(\.
|
295
|
+
gsub(/(\.(?!css).*)$/, ".html")
|
229
296
|
end
|
230
297
|
|
231
298
|
# Transforms a path into a template that will render the file specified
|
@@ -233,7 +300,7 @@ module Mint
|
|
233
300
|
#
|
234
301
|
# @param [Path, File, String, #to_s] path the file to render
|
235
302
|
def self.renderer(path)
|
236
|
-
|
303
|
+
mapping.new path.to_s
|
237
304
|
end
|
238
305
|
|
239
306
|
# Publishes a Document object according to its internal specifications.
|
data/lib/mint/plugin.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "mint/document"
|
2
1
|
require "set"
|
2
|
+
require "mint/document"
|
3
3
|
|
4
4
|
module Mint
|
5
5
|
def self.plugins
|
@@ -28,11 +28,11 @@ module Mint
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.template_directory(plugin)
|
31
|
-
Mint
|
31
|
+
Mint::ROOT + "/plugins/templates/" + plugin.underscore
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.config_directory(plugin)
|
35
|
-
Mint
|
35
|
+
Mint::ROOT + "/plugins/config/" + plugin.underscore
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.commandline_options_file(plugin)
|
data/lib/mint/plugins/epub.rb
CHANGED
data/lib/mint/resource.rb
CHANGED
@@ -4,6 +4,8 @@ module Mint
|
|
4
4
|
class Resource
|
5
5
|
attr_accessor :type
|
6
6
|
|
7
|
+
attr_accessor :context
|
8
|
+
|
7
9
|
attr_reader :name
|
8
10
|
def name=(name)
|
9
11
|
@name = name
|
@@ -26,7 +28,7 @@ module Mint
|
|
26
28
|
|
27
29
|
def source_file_path
|
28
30
|
path = Pathname.new(source)
|
29
|
-
path.absolute? ?
|
31
|
+
path.absolute? ?
|
30
32
|
path.expand_path : root_directory_path + path
|
31
33
|
end
|
32
34
|
|
@@ -59,22 +61,23 @@ module Mint
|
|
59
61
|
def destination_directory
|
60
62
|
destination_directory_path.to_s
|
61
63
|
end
|
62
|
-
|
64
|
+
|
63
65
|
def renderer=(renderer)
|
64
66
|
@renderer = renderer
|
65
67
|
end
|
66
68
|
|
67
|
-
def initialize(source,
|
69
|
+
def initialize(source, root: nil, destination: nil, context: nil, name: nil, &block)
|
68
70
|
return nil unless source
|
69
71
|
|
70
72
|
self.type = :resource
|
71
73
|
self.source = source
|
72
|
-
self.root =
|
73
|
-
self.destination =
|
74
|
+
self.root = root || source_directory
|
75
|
+
self.destination = destination
|
76
|
+
self.context = context
|
74
77
|
|
75
|
-
yield self if
|
78
|
+
yield self if block
|
76
79
|
|
77
|
-
self.name = Mint.guess_name_from
|
80
|
+
self.name = name || Mint.guess_name_from(source)
|
78
81
|
self.renderer = Mint.renderer source
|
79
82
|
end
|
80
83
|
|
@@ -83,9 +86,16 @@ module Mint
|
|
83
86
|
end
|
84
87
|
alias_method :==, :equal?
|
85
88
|
|
86
|
-
def render(context=
|
89
|
+
def render(context=self, args={})
|
87
90
|
# see Tilt TEMPLATES.md for more info
|
88
|
-
@renderer.render context, args
|
91
|
+
@renderer.render context, args
|
92
|
+
end
|
93
|
+
|
94
|
+
def publish!(opts={})
|
95
|
+
FileUtils.mkdir_p self.destination_directory
|
96
|
+
File.open(self.destination_file, "w+") do |f|
|
97
|
+
f << self.render
|
98
|
+
end
|
89
99
|
end
|
90
100
|
end
|
91
101
|
end
|
data/lib/mint/style.rb
CHANGED
@@ -2,13 +2,12 @@ require "mint/resource"
|
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
class Style < Resource
|
5
|
-
# Creates a new
|
5
|
+
# Creates a new Style object using a mandatory source file
|
6
6
|
# and optional configuration options.
|
7
7
|
#
|
8
8
|
# @param [String] source the absolute or relative file path
|
9
|
-
|
10
|
-
|
11
|
-
super(source, opts)
|
9
|
+
def initialize(source, root: nil, destination: nil, context: nil, name: nil, &block)
|
10
|
+
super(source, root: root, destination: destination, context: context, name: name, &block)
|
12
11
|
self.type = :style
|
13
12
|
|
14
13
|
# We want to render final stylesheet to the /css subdirectory if
|
@@ -19,7 +18,9 @@ module Mint
|
|
19
18
|
# However, if a destination directory is already specified, we
|
20
19
|
# leave it alone.
|
21
20
|
if Mint.template?(self.source_directory) and rendered?
|
22
|
-
|
21
|
+
tmp_dir = Mint.path_for_scope(:user) + "tmp"
|
22
|
+
self.destination ||= tmp_dir.to_s
|
23
|
+
self.root = "/"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -27,19 +28,14 @@ module Mint
|
|
27
28
|
#
|
28
29
|
# @return [Boolean] whether or not style should be rendered
|
29
30
|
def rendered?
|
30
|
-
|
31
|
+
true # All styles need rendering now (CSS for imports, Sass for compilation)
|
31
32
|
end
|
32
33
|
|
33
|
-
# Renders a Style object
|
34
|
-
# of its source file.
|
34
|
+
# Renders a Style object through Tilt template system
|
35
35
|
#
|
36
|
-
# @return [String] a rendered stylesheet
|
36
|
+
# @return [String] a rendered stylesheet
|
37
37
|
def render
|
38
|
-
|
39
|
-
super
|
40
|
-
else
|
41
|
-
File.read source
|
42
|
-
end
|
38
|
+
super
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
data/lib/mint/version.rb
CHANGED
data/lib/mint.rb
CHANGED
data/man/mint.1
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
.TH MINT 1 "December 2024" "mint" "User Commands"
|
2
|
+
.SH NAME
|
3
|
+
mint \- transform plain text documents into beautiful styled HTML
|
4
|
+
.SH SYNOPSIS
|
5
|
+
.B mint
|
6
|
+
.I COMMAND
|
7
|
+
[\fIOPTIONS\fR] [\fIFILE\fR...]
|
8
|
+
.SH DESCRIPTION
|
9
|
+
Mint transforms your plain text documents into beautiful documents. It makes that process as simple (but customizable) as possible.
|
10
|
+
|
11
|
+
Mint processes Markdown, Textile, and other templating languages into styled HTML documents ready to print, email, and present.
|
12
|
+
.SH COMMANDS
|
13
|
+
.TP
|
14
|
+
.B publish
|
15
|
+
Transform one or more source files into HTML documents
|
16
|
+
.SH OPTIONS
|
17
|
+
.TP
|
18
|
+
.BR \-d ", " \-\-destination " " \fIDIRECTORY\fR
|
19
|
+
Specify a destination directory, relative to the root
|
20
|
+
.TP
|
21
|
+
.BR \-\-style\-mode " " \fIMODE\fR
|
22
|
+
Specify how styles are included (inline, external, original). Default is inline.
|
23
|
+
.TP
|
24
|
+
.BR \-\-style\-destination " " \fIDESTINATION\fR
|
25
|
+
Create stylesheet at specified directory or file path and link it. This sets style mode to external.
|
26
|
+
.TP
|
27
|
+
.BR \-\-template " " \fITEMPLATE\fR
|
28
|
+
Specify a template to use for both layout and styling
|
29
|
+
.TP
|
30
|
+
.BR \-l ", " \-\-layout " " \fILAYOUT\fR
|
31
|
+
Specify a specific layout template
|
32
|
+
.TP
|
33
|
+
.BR \-\-style " " \fISTYLE\fR
|
34
|
+
Specify a specific style template
|
35
|
+
.TP
|
36
|
+
.BR \-g ", " \-\-global
|
37
|
+
Specify config changes on a global level
|
38
|
+
.TP
|
39
|
+
.BR \-u ", " \-\-user
|
40
|
+
Specify config changes on a user-wide level
|
41
|
+
.TP
|
42
|
+
.BR \-\-local
|
43
|
+
Specify config changes on a local level (default)
|
44
|
+
.TP
|
45
|
+
.BR \-r ", " \-\-recursive
|
46
|
+
Recursively find all Markdown files in subdirectories
|
47
|
+
.TP
|
48
|
+
.BR \-v ", " \-\-verbose
|
49
|
+
Enable verbose output
|
50
|
+
.TP
|
51
|
+
.BR \-h ", " \-\-help
|
52
|
+
Display help information
|
53
|
+
.SH STYLE OPTIONS
|
54
|
+
Mint offers flexible control over how stylesheets are incorporated into your documents:
|
55
|
+
|
56
|
+
.SS Inline Styles (Default)
|
57
|
+
By default, Mint inlines CSS directly into your HTML documents, creating self-contained files:
|
58
|
+
.RS
|
59
|
+
.nf
|
60
|
+
mint publish document.md
|
61
|
+
.fi
|
62
|
+
.RE
|
63
|
+
|
64
|
+
.SS External Stylesheets
|
65
|
+
Create external stylesheets that are linked from your HTML documents:
|
66
|
+
.RS
|
67
|
+
.nf
|
68
|
+
mint publish document.md --style-destination css
|
69
|
+
mint publish document.md --style-destination styles/main.css
|
70
|
+
.fi
|
71
|
+
.RE
|
72
|
+
|
73
|
+
External stylesheets are useful when you want to share stylesheets across multiple documents, keep HTML files smaller, or allow separate caching of styles.
|
74
|
+
.SH EXAMPLES
|
75
|
+
.TP
|
76
|
+
Transform a single Markdown file:
|
77
|
+
.nf
|
78
|
+
mint publish document.md
|
79
|
+
.fi
|
80
|
+
.TP
|
81
|
+
Transform multiple files:
|
82
|
+
.nf
|
83
|
+
mint publish doc1.md doc2.md doc3.md
|
84
|
+
.fi
|
85
|
+
.TP
|
86
|
+
Use a specific template:
|
87
|
+
.nf
|
88
|
+
mint publish resume.md --template resume
|
89
|
+
.fi
|
90
|
+
.TP
|
91
|
+
Create external stylesheet:
|
92
|
+
.nf
|
93
|
+
mint publish document.md --style-destination css
|
94
|
+
.fi
|
95
|
+
.TP
|
96
|
+
Recursively process all Markdown files:
|
97
|
+
.nf
|
98
|
+
mint publish --recursive
|
99
|
+
.fi
|
100
|
+
.SH TEMPLATES
|
101
|
+
Mint comes with several built-in templates:
|
102
|
+
.IP \(bu 2
|
103
|
+
.B default
|
104
|
+
\- Clean, professional styling
|
105
|
+
.IP \(bu 2
|
106
|
+
.B zen
|
107
|
+
\- Minimalist design
|
108
|
+
.IP \(bu 2
|
109
|
+
.B protocol
|
110
|
+
\- Technical documentation style
|
111
|
+
.IP \(bu 2
|
112
|
+
.B newspaper
|
113
|
+
\- Multi-column layout
|
114
|
+
.IP \(bu 2
|
115
|
+
.B nord/nord-dark
|
116
|
+
\- Modern color schemes
|
117
|
+
.PP
|
118
|
+
Templates can be written in any format accepted by the Tilt template interface library (ERB, Haml, etc.).
|
119
|
+
.SH FILES
|
120
|
+
.TP
|
121
|
+
.I ~/.config/mint/
|
122
|
+
User-specific configuration and templates
|
123
|
+
.TP
|
124
|
+
.I .mint/
|
125
|
+
Project-specific configuration and templates
|
126
|
+
.TP
|
127
|
+
.I config.yaml
|
128
|
+
Configuration file (can exist at global, user, or local levels)
|
129
|
+
.SH SEE ALSO
|
130
|
+
.BR markdown (1),
|
131
|
+
.BR tilt (1)
|
132
|
+
.SH AUTHOR
|
133
|
+
David Jacobs <david@wit.io>
|
134
|
+
.SH HOMEPAGE
|
135
|
+
https://github.com/davejacobs/mint
|