mint 0.8.0 → 0.10.0
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 +4 -4
- data/Gemfile +1 -26
- data/README.md +138 -95
- data/bin/mint +2 -81
- data/config/templates/base/navigation.css +136 -0
- data/config/templates/base/print.css +152 -0
- data/config/templates/{reset.css → base/reset.css} +1 -1
- data/config/templates/base/style.css +117 -137
- data/config/templates/base/utilities.css +136 -0
- data/config/templates/base/variables.css +124 -0
- data/config/templates/basic/style.css +151 -0
- data/config/templates/default/layout.erb +33 -3
- data/config/templates/default/style.css +95 -164
- data/config/templates/magazine/style.css +383 -0
- data/config/templates/nord/style.css +105 -220
- data/config/templates/nord-dark/style.css +82 -263
- data/lib/mint/commandline/parse.rb +144 -0
- data/lib/mint/commandline/publish.rb +46 -0
- data/lib/mint/commandline/run.rb +30 -0
- data/lib/mint/config.rb +162 -0
- data/lib/mint/{css.rb → css_dsl.rb} +9 -9
- data/lib/mint/css_parser.rb +96 -0
- data/lib/mint/document.rb +251 -348
- data/lib/mint/document_tree.rb +163 -0
- data/lib/mint/exceptions.rb +2 -3
- data/lib/mint/helpers.rb +23 -180
- data/lib/mint/layout.rb +26 -9
- data/lib/mint/renderers/css_renderer.rb +32 -0
- data/lib/mint/renderers/erb_renderer.rb +11 -0
- data/lib/mint/renderers/markdown_renderer.rb +45 -0
- data/lib/mint/style.rb +21 -31
- data/lib/mint/template.rb +30 -0
- data/lib/mint/version.rb +1 -1
- data/lib/mint/workspace.rb +171 -0
- data/lib/mint.rb +44 -12
- data/man/mint.1 +88 -47
- data/spec/cli/README.md +13 -13
- data/spec/cli/argument_parsing_spec.rb +103 -131
- data/spec/cli/bin_integration_spec.rb +23 -243
- data/spec/cli/full_workflow_integration_spec.rb +99 -442
- data/spec/cli/original_style_integration_spec.rb +58 -0
- data/spec/cli/publish_workflow_spec.rb +72 -70
- data/spec/commandline_path_integration_spec.rb +230 -0
- data/spec/config_file_integration_spec.rb +362 -0
- data/spec/{css_spec.rb → css_dsl_spec.rb} +7 -3
- data/spec/css_parser_spec.rb +207 -0
- data/spec/document_spec.rb +37 -242
- data/spec/flattened_path_spec.rb +150 -0
- data/spec/layout_spec.rb +42 -3
- data/spec/mint_spec.rb +22 -217
- data/spec/path_handling_spec.rb +237 -0
- data/spec/run_cli_tests.rb +1 -1
- data/spec/spec_helper.rb +3 -10
- data/spec/style_spec.rb +31 -56
- data/spec/support/cli_helpers.rb +7 -10
- data/spec/support/matchers.rb +1 -1
- data/spec/template_spec.rb +31 -0
- data/spec/workspace_spec.rb +177 -0
- metadata +78 -93
- data/bin/mint-epub +0 -20
- data/config/templates/default/css/style.css +0 -205
- data/config/templates/garden/layout.erb +0 -38
- data/config/templates/garden/style.css +0 -303
- data/config/templates/newspaper/layout.erb +0 -16
- data/config/templates/nord/layout.erb +0 -11
- data/config/templates/nord-dark/layout.erb +0 -11
- data/config/templates/protocol/layout.erb +0 -9
- data/config/templates/protocol/style.css +0 -25
- data/config/templates/zen/layout.erb +0 -11
- data/config/templates/zen/style.css +0 -114
- data/lib/mint/command_line.rb +0 -360
- data/lib/mint/css_template.rb +0 -37
- data/lib/mint/markdown_template.rb +0 -47
- data/lib/mint/mint.rb +0 -313
- data/lib/mint/plugin.rb +0 -136
- data/lib/mint/plugins/epub.rb +0 -293
- data/lib/mint/resource.rb +0 -101
- data/plugins/templates/epub/layouts/container.haml +0 -5
- data/plugins/templates/epub/layouts/content.haml +0 -35
- data/plugins/templates/epub/layouts/layout.haml +0 -6
- data/plugins/templates/epub/layouts/title.haml +0 -11
- data/plugins/templates/epub/layouts/toc.haml +0 -26
- data/spec/cli/configuration_management_spec.rb +0 -363
- data/spec/cli/template_management_spec.rb +0 -300
- data/spec/helpers_spec.rb +0 -249
- data/spec/plugin_spec.rb +0 -449
- data/spec/resource_spec.rb +0 -135
data/spec/mint_spec.rb
CHANGED
@@ -1,242 +1,47 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Mint do
|
4
|
-
|
5
|
-
|
6
|
-
describe "::ROOT" do
|
4
|
+
describe "::PROJECT_ROOT" do
|
7
5
|
it "contains the root of the Mint gem as a string" do
|
8
|
-
expect(Mint::
|
6
|
+
expect(Mint::PROJECT_ROOT).to eq(File.expand_path("../..", __FILE__))
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
12
|
-
describe "
|
13
|
-
def as_pathname(files)
|
14
|
-
files.map {|file| Pathname.new(file) }
|
15
|
-
end
|
16
|
-
|
10
|
+
describe "::PATH" do
|
17
11
|
it "returns the paths corresponding to all scopes as an array" do
|
18
|
-
expect(Mint
|
12
|
+
expect(Mint::PATH).to eq([Pathname.new(".mint"),
|
19
13
|
Pathname.new("~/.config/mint").expand_path,
|
20
|
-
Pathname.new(Mint::
|
21
|
-
end
|
22
|
-
|
23
|
-
it "can filter paths by one scope" do
|
24
|
-
expect(Mint.path([:user])).to eq([Pathname.new("~/.config/mint").expand_path])
|
25
|
-
end
|
26
|
-
|
27
|
-
it "can filter paths by many scopes" do
|
28
|
-
expect(Mint.path([:local, :user])).to eq([Pathname.new(".mint"),
|
29
|
-
Pathname.new("~/.config/mint").expand_path])
|
14
|
+
Pathname.new(Mint::PROJECT_ROOT + "/config").expand_path])
|
30
15
|
end
|
31
16
|
end
|
32
17
|
|
33
|
-
|
34
18
|
describe ".configuration" do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
scope: :local,
|
44
|
-
recursive: false,
|
45
|
-
verbose: false
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when there is no config.yaml file on the Mint path" do
|
50
|
-
it "returns a default set of options" do
|
51
|
-
expect(Mint.configuration).to eq(defaults)
|
19
|
+
context "when there is no config.toml file on the Mint path" do
|
20
|
+
it "returns a default Config object" do
|
21
|
+
config = Mint.configuration
|
22
|
+
expect(config).to be_a(Mint::Config)
|
23
|
+
expect(config.layout_name).to eq('default')
|
24
|
+
expect(config.style_name).to eq('default')
|
25
|
+
expect(config.style_mode).to eq(:inline)
|
26
|
+
expect(config.output_file_format).to eq('%{name}.%{ext}')
|
52
27
|
end
|
53
28
|
end
|
54
29
|
|
55
|
-
context "when there is a config.
|
30
|
+
context "when there is a config.toml file on the Mint path" do
|
56
31
|
before do
|
57
|
-
FileUtils.mkdir_p
|
58
|
-
File.
|
59
|
-
file << "layout: zen"
|
60
|
-
end
|
32
|
+
FileUtils.mkdir_p(".mint")
|
33
|
+
File.write(".mint/config.toml", "style = \"custom\"")
|
61
34
|
end
|
62
35
|
|
63
36
|
after do
|
64
|
-
FileUtils.rm_rf
|
65
|
-
end
|
66
|
-
|
67
|
-
it "merges all specified options with precedence according to scope" do
|
68
|
-
expect(Mint.configuration[:layout]).to eq("zen")
|
69
|
-
end
|
70
|
-
|
71
|
-
it "can filter by scope (but always includes defaults)" do
|
72
|
-
expect(Mint.configuration(scopes: [:user])).to eq(defaults)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe ".configuration_with" do
|
78
|
-
it "displays the sum of all configuration files with other options added" do
|
79
|
-
expect(Mint.configuration_with(local: true)).to eq({
|
80
|
-
root: Dir.getwd,
|
81
|
-
destination: nil,
|
82
|
-
style_mode: :inline,
|
83
|
-
style_destination: nil,
|
84
|
-
output_file: '#{basename}.#{new_extension}',
|
85
|
-
layout_or_style_or_template: [:template, 'default'],
|
86
|
-
scope: :local,
|
87
|
-
recursive: false,
|
88
|
-
verbose: false,
|
89
|
-
local: true
|
90
|
-
})
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe ".templates" do
|
95
|
-
it "returns local templates by default" do
|
96
|
-
# Note: Now defaults to local scope, will include global templates only if explicitly requested
|
97
|
-
expect(Mint.templates).to be_an(Array)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "returns global templates when global scope is specified" do
|
101
|
-
expect(Mint.templates(:global)).to include(Mint::ROOT + "/config/templates/default")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe ".formats" do
|
106
|
-
it "includes Markdown" do
|
107
|
-
expect(Mint.formats).to include("md")
|
108
|
-
end
|
109
|
-
|
110
|
-
it "includes Haml" do
|
111
|
-
expect(Mint.formats).to include("haml")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe ".css_formats" do
|
116
|
-
it "includes Sass" do
|
117
|
-
expect(Mint.css_formats).to include("sass")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe ".renderer" do
|
122
|
-
it "creates a valid renderer" do
|
123
|
-
expect(Mint.renderer(@content_file)).to respond_to(:render)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe ".path_for_scope" do
|
128
|
-
it "chooses the appropriate path for scope" do
|
129
|
-
expectations = {
|
130
|
-
local: Pathname.new(".mint"),
|
131
|
-
user: Pathname.new("~/.config/mint").expand_path,
|
132
|
-
global: Pathname.new(Mint::ROOT + "/config").expand_path
|
133
|
-
}
|
134
|
-
|
135
|
-
expectations.each do |scope, path|
|
136
|
-
expect(Mint.path_for_scope(scope)).to eq(path)
|
37
|
+
FileUtils.rm_rf(".mint")
|
137
38
|
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Refactored lookup methods for explicit parameter interface
|
142
|
-
describe ".lookup_template" do
|
143
|
-
it "returns template directory path by name" do
|
144
|
-
result = Mint.lookup_template("default")
|
145
|
-
expect(result.to_s).to include("templates/default")
|
146
|
-
expect(File.directory?(result)).to be true
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe ".lookup_layout" do
|
151
|
-
it "returns layout file path by template name" do
|
152
|
-
result = Mint.lookup_layout("default")
|
153
|
-
expect(result).to include("templates/default")
|
154
|
-
expect(result).to end_with("layout.erb")
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe ".lookup_style" do
|
159
|
-
it "returns style file path by template name" do
|
160
|
-
result = Mint.lookup_style("default")
|
161
|
-
expect(result).to include("templates/default")
|
162
|
-
expect(result).to end_with("style.css")
|
163
|
-
end
|
164
|
-
end
|
165
39
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
expect(layout_file).to include("templates/default")
|
172
|
-
expect(layout_file).to end_with("layout.erb")
|
173
|
-
expect(style_file).to include("templates/default")
|
174
|
-
expect(style_file).to end_with("style.css")
|
175
|
-
end
|
176
|
-
|
177
|
-
it "determines if a file is a template file" do
|
178
|
-
actual_template = Mint.lookup_layout("default")
|
179
|
-
fake_template = "#{Mint::ROOT}/config/templates/default.css"
|
180
|
-
obvious_nontemplate = @dynamic_style_file
|
181
|
-
|
182
|
-
expect(Mint.template?(actual_template)).to be_truthy
|
183
|
-
expect(Mint.template?(fake_template)).to be_falsy
|
184
|
-
expect(Mint.template?(obvious_nontemplate)).to be_falsy
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe ".guess_name_from" do
|
189
|
-
it "properly guesses destination file names based on source file names" do
|
190
|
-
expect(Mint.guess_name_from("content.md")).to eq("content.html")
|
191
|
-
expect(Mint.guess_name_from("content.textile")).to eq("content.html")
|
192
|
-
expect(Mint.guess_name_from("layout.haml")).to eq("layout.html")
|
193
|
-
expect(Mint.guess_name_from("dynamic.sass")).to eq("dynamic.css")
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe ".destination_file_path and .style_destination_file_path" do
|
198
|
-
context "before it publishes a document" do
|
199
|
-
let(:document) { Mint::Document.new @content_file }
|
200
|
-
subject { document }
|
201
|
-
|
202
|
-
its(:destination_file_path) { should_not exist }
|
203
|
-
it "style destination file should not exist initially" do
|
204
|
-
# Clean up any existing style file first
|
205
|
-
FileUtils.rm_f(document.style_destination_file_path) if document.style_destination_file_path && File.exist?(document.style_destination_file_path)
|
206
|
-
expect(document.style_destination_file_path).not_to exist
|
40
|
+
it "merges config files with defaults" do
|
41
|
+
config = Mint.configuration
|
42
|
+
expect(config.style_name).to eq("custom")
|
43
|
+
expect(config.layout_name).to eq("default") # still has defaults
|
207
44
|
end
|
208
45
|
end
|
209
|
-
|
210
|
-
# These are copied from document_spec.rb. I eventually want to move
|
211
|
-
# to this non-OO style of publishing, and this is the transition
|
212
|
-
context "when it publishes a document" do
|
213
|
-
let(:document) { Mint::Document.new @content_file }
|
214
|
-
before { Mint.publish! document }
|
215
|
-
subject { document }
|
216
|
-
|
217
|
-
its(:destination_file_path) { should exist }
|
218
|
-
|
219
|
-
it "creates style file only for external style mode" do
|
220
|
-
if document.style_mode == :external
|
221
|
-
expect(document.style_destination_file_path).to exist
|
222
|
-
else
|
223
|
-
expect(document.style_destination_file_path).not_to exist
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe ".template_path" do
|
230
|
-
it "returns template directory for given name and scope" do
|
231
|
-
expect(Mint.template_path("pro", :local)).to eq(Pathname.new(".mint/templates/pro"))
|
232
|
-
end
|
233
|
-
|
234
|
-
it "works with user scope" do
|
235
|
-
expect(Mint.template_path("pro", :user)).to eq(Pathname.new("~/.config/mint/templates/pro").expand_path)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "works with global scope" do
|
239
|
-
expect(Mint.template_path("pro", :global)).to eq(Pathname.new("#{Mint::ROOT}/config/templates/pro"))
|
240
|
-
end
|
241
46
|
end
|
242
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Path Handling in Workspace.publish!" do
|
4
|
+
context "in isolated environment" do
|
5
|
+
around(:each) do |example|
|
6
|
+
in_temp_dir do |dir|
|
7
|
+
@test_dir = dir
|
8
|
+
create_template_directory("default")
|
9
|
+
example.run
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "relative path preservation (with preserve_structure: true)" do
|
14
|
+
it "preserves single-level directory structure" do
|
15
|
+
FileUtils.mkdir_p(["docs", "output"])
|
16
|
+
create_markdown_path("docs/readme.md", "# Documentation")
|
17
|
+
|
18
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("output"), preserve_structure: true)
|
19
|
+
workspace = Mint::Workspace.new([Pathname.new("docs/readme.md")], config)
|
20
|
+
workspace.publish!
|
21
|
+
|
22
|
+
expect(File.exist?("output/docs/readme.html")).to be true
|
23
|
+
expect(File.exist?("output/readme.html")).to be false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "preserves multi-level directory structure" do
|
27
|
+
FileUtils.mkdir_p(["src/guides/advanced", "build"])
|
28
|
+
create_markdown_path("src/guides/advanced/config.md", "# Advanced Configuration")
|
29
|
+
|
30
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("build"), preserve_structure: true)
|
31
|
+
workspace = Mint::Workspace.new([Pathname.new("src/guides/advanced/config.md")], config)
|
32
|
+
workspace.publish!
|
33
|
+
|
34
|
+
expect(File.exist?("build/src/guides/advanced/config.html")).to be true
|
35
|
+
expect(File.exist?("build/config.html")).to be false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "handles files in root directory" do
|
39
|
+
create_markdown_path("index.md", "# Home Page")
|
40
|
+
|
41
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("site"), preserve_structure: true)
|
42
|
+
workspace = Mint::Workspace.new([Pathname.new("index.md")], config)
|
43
|
+
workspace.publish!
|
44
|
+
|
45
|
+
expect(File.exist?("site/index.html")).to be true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "handles nested destination directories" do
|
49
|
+
FileUtils.mkdir_p("content")
|
50
|
+
create_markdown_path("content/about.md", "# About Us")
|
51
|
+
|
52
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("public/website"), preserve_structure: true)
|
53
|
+
workspace = Mint::Workspace.new([Pathname.new("content/about.md")], config)
|
54
|
+
workspace.publish!
|
55
|
+
|
56
|
+
expect(File.exist?("public/website/content/about.html")).to be true
|
57
|
+
expect(Dir.exist?("public/website/content")).to be true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "complex directory structures" do
|
62
|
+
it "handles deeply nested source with shallow destination" do
|
63
|
+
FileUtils.mkdir_p(["project/src/docs/api/v1", "api-docs"])
|
64
|
+
create_markdown_path("project/src/docs/api/v1/users.md", "# Users API")
|
65
|
+
|
66
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("api-docs"), preserve_structure: true)
|
67
|
+
workspace = Mint::Workspace.new([Pathname.new("project/src/docs/api/v1/users.md")], config)
|
68
|
+
workspace.publish!
|
69
|
+
|
70
|
+
expect(File.exist?("api-docs/project/src/docs/api/v1/users.html")).to be true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "handles multiple files with different nesting levels" do
|
74
|
+
FileUtils.mkdir_p(["src", "src/components", "src/pages/admin", "build"])
|
75
|
+
|
76
|
+
create_markdown_path("src/readme.md", "# Project README")
|
77
|
+
create_markdown_path("src/components/button.md", "# Button Component")
|
78
|
+
create_markdown_path("src/pages/admin/dashboard.md", "# Admin Dashboard")
|
79
|
+
|
80
|
+
files = [
|
81
|
+
"src/readme.md",
|
82
|
+
"src/components/button.md",
|
83
|
+
"src/pages/admin/dashboard.md"
|
84
|
+
]
|
85
|
+
|
86
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("build"), preserve_structure: true)
|
87
|
+
|
88
|
+
workspace = Mint::Workspace.new(files.map {|f| Pathname.new(f) }, config)
|
89
|
+
workspace.publish!
|
90
|
+
|
91
|
+
expect(File.exist?("build/readme.html")).to be true
|
92
|
+
expect(File.exist?("build/components/button.html")).to be true
|
93
|
+
expect(File.exist?("build/pages/admin/dashboard.html")).to be true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "edge cases" do
|
98
|
+
it "handles files with dots in directory names" do
|
99
|
+
FileUtils.mkdir_p(["v1.0/docs", "output"])
|
100
|
+
create_markdown_path("v1.0/docs/changelog.md", "# Changelog")
|
101
|
+
|
102
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("output"), preserve_structure: true)
|
103
|
+
workspace = Mint::Workspace.new([Pathname.new("v1.0/docs/changelog.md")], config)
|
104
|
+
workspace.publish!
|
105
|
+
|
106
|
+
expect(File.exist?("output/v1.0/docs/changelog.html")).to be true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "handles files with spaces in directory names" do
|
110
|
+
FileUtils.mkdir_p(["My Documents/Notes", "website"])
|
111
|
+
create_markdown_path("My Documents/Notes/ideas.md", "# Ideas")
|
112
|
+
|
113
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("website"), preserve_structure: true)
|
114
|
+
workspace = Mint::Workspace.new([Pathname.new("My Documents/Notes/ideas.md")], config)
|
115
|
+
workspace.publish!
|
116
|
+
|
117
|
+
expect(File.exist?("website/My Documents/Notes/ideas.html")).to be true
|
118
|
+
end
|
119
|
+
|
120
|
+
it "handles symlinked directories" do
|
121
|
+
FileUtils.mkdir_p(["real-content", "output"])
|
122
|
+
create_markdown_path("real-content/page.md", "# Page")
|
123
|
+
|
124
|
+
# Create symlink (skip if not supported)
|
125
|
+
begin
|
126
|
+
File.symlink("real-content", "linked-content")
|
127
|
+
|
128
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("output"), preserve_structure: true)
|
129
|
+
workspace = Mint::Workspace.new([Pathname.new("linked-content/page.md")], config)
|
130
|
+
workspace.publish!
|
131
|
+
|
132
|
+
expect(File.exist?("output/linked-content/page.html")).to be true
|
133
|
+
rescue NotImplementedError
|
134
|
+
skip "Symlinks not supported on this system"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "handles current directory references" do
|
139
|
+
FileUtils.mkdir_p(["docs", "site"])
|
140
|
+
create_markdown_path("docs/manual.md", "# Manual")
|
141
|
+
|
142
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("./site"), preserve_structure: true)
|
143
|
+
workspace = Mint::Workspace.new([Pathname.new("./docs/manual.md")], config)
|
144
|
+
workspace.publish!
|
145
|
+
|
146
|
+
expect(File.exist?("site/docs/manual.html")).to be true
|
147
|
+
end
|
148
|
+
|
149
|
+
it "handles parent directory references" do
|
150
|
+
FileUtils.mkdir_p(["project/content", "project/build", "output"])
|
151
|
+
create_markdown_path("project/content/info.md", "# Information")
|
152
|
+
|
153
|
+
Dir.chdir("project") do
|
154
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("../output"), preserve_structure: true)
|
155
|
+
workspace = Mint::Workspace.new([Pathname.new("content/info.md")], config)
|
156
|
+
workspace.publish!
|
157
|
+
end
|
158
|
+
|
159
|
+
expect(File.exist?("output/content/info.html")).to be true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "destination directory creation" do
|
164
|
+
it "creates missing destination directories automatically" do
|
165
|
+
create_markdown_path("test.md", "# Test")
|
166
|
+
|
167
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("deeply/nested/output/dir"))
|
168
|
+
workspace = Mint::Workspace.new([Pathname.new("test.md")], config)
|
169
|
+
workspace.publish!
|
170
|
+
|
171
|
+
expect(File.exist?("deeply/nested/output/dir/test.html")).to be true
|
172
|
+
expect(Dir.exist?("deeply/nested/output/dir")).to be true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "creates missing intermediate directories for nested sources" do
|
176
|
+
FileUtils.mkdir_p("src/a/b/c")
|
177
|
+
create_markdown_path("src/a/b/c/deep.md", "# Deep File")
|
178
|
+
|
179
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("output"), preserve_structure: true)
|
180
|
+
workspace = Mint::Workspace.new([Pathname.new("src/a/b/c/deep.md")], config)
|
181
|
+
workspace.publish!
|
182
|
+
|
183
|
+
expect(File.exist?("output/src/a/b/c/deep.html")).to be true
|
184
|
+
expect(Dir.exist?("output/src/a/b/c")).to be true
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "path sanitization" do
|
189
|
+
it "preserves valid special characters in paths" do
|
190
|
+
FileUtils.mkdir_p(["docs-2023", "output"])
|
191
|
+
create_markdown_path("docs-2023/v1.0_final.md", "# Version 1.0")
|
192
|
+
|
193
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("output"), preserve_structure: true)
|
194
|
+
workspace = Mint::Workspace.new([Pathname.new("docs-2023/v1.0_final.md")], config)
|
195
|
+
workspace.publish!
|
196
|
+
|
197
|
+
expect(File.exist?("output/docs-2023/v1.0_final.html")).to be true
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "multiple file processing with paths" do
|
202
|
+
it "processes multiple files maintaining their relative structure" do
|
203
|
+
# Create a realistic project structure
|
204
|
+
FileUtils.mkdir_p([
|
205
|
+
"content/blog/2023",
|
206
|
+
"content/docs/guides",
|
207
|
+
"content/pages",
|
208
|
+
"public"
|
209
|
+
])
|
210
|
+
|
211
|
+
files = [
|
212
|
+
"content/blog/2023/hello-world.md",
|
213
|
+
"content/docs/guides/getting-started.md",
|
214
|
+
"content/docs/guides/advanced.md",
|
215
|
+
"content/pages/about.md",
|
216
|
+
"content/pages/contact.md"
|
217
|
+
]
|
218
|
+
|
219
|
+
files.each_with_index do |file, i|
|
220
|
+
create_markdown_path(file, "# Document #{i + 1}")
|
221
|
+
end
|
222
|
+
|
223
|
+
config = Mint::Config.with_defaults(destination_directory: Pathname.new("public"), preserve_structure: true)
|
224
|
+
|
225
|
+
workspace = Mint::Workspace.new(files.map {|f| Pathname.new(f) }, config)
|
226
|
+
workspace.publish!
|
227
|
+
|
228
|
+
# Verify all files maintain their structure (with common "content" prefix dropped by autodrop)
|
229
|
+
expect(File.exist?("public/blog/2023/hello-world.html")).to be true
|
230
|
+
expect(File.exist?("public/docs/guides/getting-started.html")).to be true
|
231
|
+
expect(File.exist?("public/docs/guides/advanced.html")).to be true
|
232
|
+
expect(File.exist?("public/pages/about.html")).to be true
|
233
|
+
expect(File.exist?("public/pages/contact.html")).to be true
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
data/spec/run_cli_tests.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,8 +7,8 @@ require_relative "support/cli_helpers"
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
config.before(:all) do
|
9
9
|
@old_dir = Dir.getwd
|
10
|
-
FileUtils.mkdir_p "
|
11
|
-
@tmp_dir = File.realpath "
|
10
|
+
FileUtils.mkdir_p "./tmp/mint-test"
|
11
|
+
@tmp_dir = File.realpath "./tmp/mint-test"
|
12
12
|
|
13
13
|
@content_file = "content.md"
|
14
14
|
@content_file_2 = "content-2.md"
|
@@ -33,15 +33,8 @@ RSpec.configure do |config|
|
|
33
33
|
end
|
34
34
|
|
35
35
|
config.after(:each) do
|
36
|
-
["content.html", ".mint/
|
36
|
+
["content.html", ".mint/config.toml"].map {|file| Pathname.new file }.
|
37
37
|
select(&:exist?).
|
38
38
|
each {|file| FileUtils.rm_rf file }
|
39
|
-
|
40
|
-
Mint.templates.
|
41
|
-
map {|template| Pathname.new(template) + "css" }.
|
42
|
-
select(&:exist?).
|
43
|
-
map(&:children).
|
44
|
-
flatten.
|
45
|
-
each {|cache| File.delete(cache) }
|
46
39
|
end
|
47
40
|
end
|
data/spec/style_spec.rb
CHANGED
@@ -1,69 +1,44 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
its(:destination) { is_expected.to be_nil }
|
10
|
-
its(:destination_file) { is_expected.to eq("#{@tmp_dir}/static.css") }
|
11
|
-
|
12
|
-
it { is_expected.to be_rendered }
|
13
|
-
it "'renders' itself verbatim" do
|
14
|
-
expect(style.render).to eq(File.read(@static_style_file))
|
15
|
-
end
|
3
|
+
describe Mint::Style do
|
4
|
+
describe ".valid?" do
|
5
|
+
it "determines if a file is a valid stylesheet" do
|
6
|
+
expect(Mint::Style.valid?(Pathname.new("style.css"))).to be true
|
7
|
+
expect(Mint::Style.valid?(Pathname.new("other.css"))).to be false
|
16
8
|
end
|
9
|
+
end
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it "renders itself from a templating language to CSS" do
|
27
|
-
expect(style.render.gsub("\n", " ").strip).to eq(
|
28
|
-
File.read(@static_style_file).gsub("\n", " ").strip)
|
11
|
+
describe ".find_by_name" do
|
12
|
+
it "returns style file path by template name" do
|
13
|
+
result = Mint::Style.find_by_name("default")
|
14
|
+
if result
|
15
|
+
expect(result).to be_a(Pathname)
|
16
|
+
expect(Mint::Style.valid?(result)).to be true
|
17
|
+
else
|
18
|
+
expect(result).to be_nil
|
29
19
|
end
|
30
20
|
end
|
21
|
+
end
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
describe ".find_in_directory" do
|
24
|
+
it "finds style file in a specific directory" do
|
25
|
+
Dir.mktmpdir do |tmpdir|
|
26
|
+
template_dir = Pathname.new(tmpdir)
|
27
|
+
style_file = template_dir + "style.css"
|
28
|
+
style_file.write("body { color: black; }")
|
29
|
+
|
30
|
+
result = Mint::Style.find_in_directory(template_dir)
|
31
|
+
expect(result).to eq(style_file)
|
32
|
+
expect(Mint::Style.valid?(result)).to be true
|
40
33
|
end
|
41
34
|
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# style.destination.should be_nil
|
49
|
-
# end
|
50
|
-
|
51
|
-
# it "#destination_file" do
|
52
|
-
# style.destination_file.should ==
|
53
|
-
# Mint.path_for_scope(:local) + "/templates/static_test/style.css"
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
|
57
|
-
context "when it's created from a dynamic template file" do
|
58
|
-
let(:style) { Style.new(Mint.lookup_style("default")) }
|
59
|
-
subject { style }
|
60
|
-
|
61
|
-
it "has destination in user tmp directory" do
|
62
|
-
expect(style.destination).to match(/\.config\/mint\/tmp$/)
|
63
|
-
end
|
64
|
-
it "has destination file in user tmp directory" do
|
65
|
-
expect(style.destination_file).to match(/\.config\/mint\/tmp\/style\.css$/)
|
36
|
+
it "returns nil when no style file exists" do
|
37
|
+
Dir.mktmpdir do |tmpdir|
|
38
|
+
template_dir = Pathname.new(tmpdir)
|
39
|
+
result = Mint::Style.find_in_directory(template_dir)
|
40
|
+
expect(result).to be_nil
|
66
41
|
end
|
67
42
|
end
|
68
43
|
end
|
69
|
-
end
|
44
|
+
end
|
data/spec/support/cli_helpers.rb
CHANGED
@@ -52,7 +52,7 @@ module CLIHelpers
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Create a sample markdown file with content
|
55
|
-
def
|
55
|
+
def create_markdown_path(name = "test.md", content = "# Test\n\nHello world!")
|
56
56
|
File.write(name, content)
|
57
57
|
name
|
58
58
|
end
|
@@ -114,19 +114,16 @@ module CLIHelpers
|
|
114
114
|
config_dir = case scope
|
115
115
|
when :local then ".mint"
|
116
116
|
when :user then File.expand_path("~/.config/mint")
|
117
|
-
when :global then "#{Mint::
|
117
|
+
when :global then "#{Mint::PROJECT_ROOT}/config"
|
118
118
|
end
|
119
119
|
|
120
120
|
FileUtils.mkdir_p(config_dir)
|
121
|
-
config_file = "#{config_dir}/config.
|
121
|
+
config_file = "#{config_dir}/config.toml"
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
File.write(config_file, basic_config.to_yaml)
|
123
|
+
File.write(config_file, <<~TOML)
|
124
|
+
layout = "default"
|
125
|
+
style = "default"
|
126
|
+
TOML
|
130
127
|
config_file
|
131
128
|
end
|
132
129
|
|