mint 0.7.4 → 0.8.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 +7 -0
- data/Gemfile +23 -14
- data/LICENSE +22 -0
- data/README.md +82 -56
- data/bin/mint +47 -10
- data/bin/mint-epub +1 -4
- data/config/templates/base/style.css +187 -0
- data/config/templates/default/css/style.css +126 -79
- 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/newspaper/layout.erb +16 -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/protocol/layout.erb +9 -0
- data/config/templates/protocol/style.css +25 -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_template.rb +37 -0
- data/lib/mint/document.rb +185 -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 +207 -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_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 +86 -88
- 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 -223
- data/config/syntax.yaml +0 -71
- data/config/templates/base/style.sass +0 -144
- 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
@@ -0,0 +1,368 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "CLI Publishing Workflow" do
|
4
|
+
describe "Mint::CommandLine.publish!" do
|
5
|
+
context "in isolated environment" do
|
6
|
+
around(:each) do |example|
|
7
|
+
in_temp_dir do |dir|
|
8
|
+
@test_dir = dir
|
9
|
+
setup_basic_config
|
10
|
+
create_template_directory("default")
|
11
|
+
example.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "basic publishing" do
|
16
|
+
it "publishes a single markdown file" do
|
17
|
+
markdown_file = create_markdown_file("test.md", "# Hello World\n\nThis is a test.")
|
18
|
+
|
19
|
+
expect {
|
20
|
+
Mint::CommandLine.publish!([markdown_file], {})
|
21
|
+
}.not_to raise_error
|
22
|
+
|
23
|
+
verify_file_content("test.html") do |content|
|
24
|
+
expect(content).to include("<h1>Hello World</h1>")
|
25
|
+
expect(content).to include("<p>This is a test.</p>")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "publishes multiple markdown files" do
|
30
|
+
file1 = create_markdown_file("doc1.md", "# Document 1")
|
31
|
+
file2 = create_markdown_file("doc2.md", "# Document 2")
|
32
|
+
|
33
|
+
expect {
|
34
|
+
Mint::CommandLine.publish!([file1, file2], {})
|
35
|
+
}.not_to raise_error
|
36
|
+
|
37
|
+
verify_file_content("doc1.html") do |content|
|
38
|
+
expect(content).to include("<h1>Document 1</h1>")
|
39
|
+
end
|
40
|
+
|
41
|
+
verify_file_content("doc2.html") do |content|
|
42
|
+
expect(content).to include("<h1>Document 2</h1>")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "uses default template when none specified" do
|
47
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
48
|
+
|
49
|
+
Mint::CommandLine.publish!([markdown_file], {})
|
50
|
+
|
51
|
+
verify_file_content("test.html") do |content|
|
52
|
+
expect(content).to include("<!DOCTYPE html>")
|
53
|
+
expect(content).to include("<html>")
|
54
|
+
expect(content).to include("</html>")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with custom options" do
|
60
|
+
it "publishes with custom destination" do
|
61
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
62
|
+
FileUtils.mkdir_p("output")
|
63
|
+
|
64
|
+
Mint::CommandLine.publish!([markdown_file], { destination: "output" })
|
65
|
+
|
66
|
+
expect(File.exist?("output/test.html")).to be true
|
67
|
+
expect(File.exist?("test.html")).to be false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "publishes with custom root directory" do
|
71
|
+
# Create a subdirectory structure
|
72
|
+
FileUtils.mkdir_p("docs")
|
73
|
+
Dir.chdir("docs") do
|
74
|
+
create_markdown_file("readme.md", "# Documentation")
|
75
|
+
end
|
76
|
+
|
77
|
+
# Publish from parent directory with current directory as root
|
78
|
+
Mint::CommandLine.publish!(["docs/readme.md"], { root: Dir.getwd })
|
79
|
+
|
80
|
+
expect(File.exist?("docs/readme.html")).to be true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "uses custom template" do
|
84
|
+
create_template_directory("custom", with_layout: true, with_style: true)
|
85
|
+
File.write(".mint/templates/custom/layout.erb",
|
86
|
+
"<html><body class='custom'><%= content %></body></html>")
|
87
|
+
|
88
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
89
|
+
|
90
|
+
Mint::CommandLine.publish!([markdown_file], { layout: "custom" })
|
91
|
+
|
92
|
+
verify_file_content("test.html") do |content|
|
93
|
+
expect(content).to include("class='custom'")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "applies custom style template" do
|
98
|
+
create_template_directory("styled", with_layout: true, with_style: true)
|
99
|
+
File.write(".mint/templates/styled/style.css",
|
100
|
+
"body { background: red; }")
|
101
|
+
|
102
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
103
|
+
|
104
|
+
Mint::CommandLine.publish!([markdown_file], { style: "styled" })
|
105
|
+
|
106
|
+
# Check if style file was created and linked
|
107
|
+
expect(File.exist?("test.html")).to be true
|
108
|
+
# Style files are typically processed to a temp directory
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "recursive publishing" do
|
113
|
+
it "discovers and publishes markdown files recursively" do
|
114
|
+
# Create nested directory structure with markdown files
|
115
|
+
FileUtils.mkdir_p("docs/section1")
|
116
|
+
FileUtils.mkdir_p("docs/section2")
|
117
|
+
|
118
|
+
create_markdown_file("docs/index.md", "# Main Documentation")
|
119
|
+
create_markdown_file("docs/section1/intro.md", "# Introduction")
|
120
|
+
create_markdown_file("docs/section2/advanced.md", "# Advanced Topics")
|
121
|
+
|
122
|
+
# Also create non-markdown files that should be ignored
|
123
|
+
File.write("docs/config.yaml", "key: value")
|
124
|
+
File.write("docs/section1/script.js", "console.log('test');")
|
125
|
+
|
126
|
+
Mint::CommandLine.publish!(["docs"], { recursive: true })
|
127
|
+
|
128
|
+
expect(File.exist?("docs/index.html")).to be true
|
129
|
+
expect(File.exist?("docs/section1/intro.html")).to be true
|
130
|
+
expect(File.exist?("docs/section2/advanced.html")).to be true
|
131
|
+
|
132
|
+
# Non-markdown files should not be converted
|
133
|
+
expect(File.exist?("docs/config.html")).to be false
|
134
|
+
expect(File.exist?("docs/section1/script.html")).to be false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "handles empty directories gracefully" do
|
138
|
+
FileUtils.mkdir_p("empty/nested/dirs")
|
139
|
+
|
140
|
+
expect {
|
141
|
+
Mint::CommandLine.publish!(["empty"], { recursive: true })
|
142
|
+
}.not_to raise_error
|
143
|
+
end
|
144
|
+
|
145
|
+
it "processes current directory when no files specified" do
|
146
|
+
create_markdown_file("current.md", "# Current Directory")
|
147
|
+
FileUtils.mkdir_p("sub")
|
148
|
+
create_markdown_file("sub/nested.md", "# Nested File")
|
149
|
+
|
150
|
+
Mint::CommandLine.publish!([], { recursive: true })
|
151
|
+
|
152
|
+
expect(File.exist?("current.html")).to be true
|
153
|
+
expect(File.exist?("sub/nested.html")).to be true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "file discovery" do
|
158
|
+
it "recognizes various markdown extensions" do
|
159
|
+
# Create files with different markdown extensions
|
160
|
+
extensions = %w[md markdown mkd]
|
161
|
+
extensions.each_with_index do |ext, i|
|
162
|
+
create_markdown_file("test#{i}.#{ext}", "# Test #{i}")
|
163
|
+
end
|
164
|
+
|
165
|
+
files = extensions.map.with_index {|ext, i| "test#{i}.#{ext}" }
|
166
|
+
Mint::CommandLine.publish!(files, {})
|
167
|
+
|
168
|
+
extensions.each_with_index do |ext, i|
|
169
|
+
expect(File.exist?("test#{i}.html")).to be true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "processes files with complex content" do
|
174
|
+
complex_content = <<~MARKDOWN
|
175
|
+
# Main Title
|
176
|
+
|
177
|
+
## Subtitle
|
178
|
+
|
179
|
+
This is a paragraph with **bold** and *italic* text.
|
180
|
+
|
181
|
+
- List item 1
|
182
|
+
- List item 2
|
183
|
+
- List item 3
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
def hello
|
187
|
+
puts "Hello, World!"
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
| Column 1 | Column 2 |
|
192
|
+
|----------|----------|
|
193
|
+
| Cell 1 | Cell 2 |
|
194
|
+
| Cell 3 | Cell 4 |
|
195
|
+
|
196
|
+
[Link to example](https://example.com)
|
197
|
+
MARKDOWN
|
198
|
+
|
199
|
+
create_markdown_file("complex.md", complex_content)
|
200
|
+
|
201
|
+
Mint::CommandLine.publish!(["complex.md"], {})
|
202
|
+
|
203
|
+
verify_file_content("complex.html") do |content|
|
204
|
+
expect(content).to include("<h1>Main Title</h1>")
|
205
|
+
expect(content).to include("<h2>Subtitle</h2>")
|
206
|
+
expect(content).to include("<strong>bold</strong>")
|
207
|
+
expect(content).to include("<em>italic</em>")
|
208
|
+
expect(content).to include("<ul>")
|
209
|
+
expect(content).to include("<code")
|
210
|
+
expect(content).to include("href=\"https://example.com\"")
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "error handling" do
|
216
|
+
it "handles missing source files gracefully" do
|
217
|
+
expect {
|
218
|
+
Mint::CommandLine.publish!(["nonexistent.md"], {})
|
219
|
+
}.to raise_error(Errno::ENOENT) # Should raise an error for missing file
|
220
|
+
end
|
221
|
+
|
222
|
+
it "handles permission errors" do
|
223
|
+
# Create a file, then make directory read-only
|
224
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
225
|
+
|
226
|
+
# Try to publish to a non-writable location
|
227
|
+
# This test might be platform-specific
|
228
|
+
expect {
|
229
|
+
Mint::CommandLine.publish!([markdown_file], { destination: "/root" })
|
230
|
+
}.to raise_error(Errno::EROFS) # Should fail due to permissions
|
231
|
+
end
|
232
|
+
|
233
|
+
it "handles invalid templates gracefully" do
|
234
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
235
|
+
|
236
|
+
expect {
|
237
|
+
Mint::CommandLine.publish!([markdown_file], { layout: "nonexistent" })
|
238
|
+
}.to raise_error(Mint::TemplateNotFoundException)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "output file naming" do
|
243
|
+
it "preserves directory structure in output" do
|
244
|
+
FileUtils.mkdir_p("input/subdir")
|
245
|
+
create_markdown_file("input/subdir/doc.md", "# Nested Document")
|
246
|
+
|
247
|
+
Mint::CommandLine.publish!(["input/subdir/doc.md"], {})
|
248
|
+
|
249
|
+
expect(File.exist?("input/subdir/doc.html")).to be true
|
250
|
+
end
|
251
|
+
|
252
|
+
it "handles files with no extension" do
|
253
|
+
File.write("README", "# Readme\n\nThis is a readme file.")
|
254
|
+
|
255
|
+
# This might fail if README is not recognized as markdown
|
256
|
+
# The behavior depends on how Mint determines file types
|
257
|
+
end
|
258
|
+
|
259
|
+
it "overwrites existing output files" do
|
260
|
+
markdown_file = create_markdown_file("test.md", "# Version 1")
|
261
|
+
File.write("test.html", "<html>Old content</html>")
|
262
|
+
|
263
|
+
Mint::CommandLine.publish!([markdown_file], {})
|
264
|
+
|
265
|
+
verify_file_content("test.html") do |content|
|
266
|
+
expect(content).to include("Version 1")
|
267
|
+
expect(content).not_to include("Old content")
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe "configuration integration" do
|
273
|
+
it "respects configuration file settings" do
|
274
|
+
# Create custom config
|
275
|
+
config_content = {
|
276
|
+
'layout' => 'custom',
|
277
|
+
'style' => 'minimal',
|
278
|
+
'destination' => 'build'
|
279
|
+
}
|
280
|
+
File.write(".mint/config.yaml", config_content.to_yaml)
|
281
|
+
|
282
|
+
# Create the referenced templates
|
283
|
+
create_template_directory("custom")
|
284
|
+
create_template_directory("minimal")
|
285
|
+
FileUtils.mkdir_p("build")
|
286
|
+
|
287
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
288
|
+
|
289
|
+
Mint::CommandLine.publish!([markdown_file], {})
|
290
|
+
|
291
|
+
expect(File.exist?("build/test.html")).to be true
|
292
|
+
end
|
293
|
+
|
294
|
+
it "allows command-line options to override config" do
|
295
|
+
# Set config with default destination
|
296
|
+
config_content = { 'destination' => 'config_output' }
|
297
|
+
File.write(".mint/config.yaml", config_content.to_yaml)
|
298
|
+
|
299
|
+
FileUtils.mkdir_p("cli_output")
|
300
|
+
markdown_file = create_markdown_file("test.md", "# Test")
|
301
|
+
|
302
|
+
# Override with CLI option
|
303
|
+
Mint::CommandLine.publish!([markdown_file], { destination: "cli_output" })
|
304
|
+
|
305
|
+
expect(File.exist?("cli_output/test.html")).to be true
|
306
|
+
expect(File.exist?("config_output/test.html")).to be false
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe "multi-file processing" do
|
311
|
+
it "processes multiple files efficiently" do
|
312
|
+
files = []
|
313
|
+
10.times do |i|
|
314
|
+
files << create_markdown_file("doc#{i}.md", "# Document #{i}")
|
315
|
+
end
|
316
|
+
|
317
|
+
start_time = Time.now
|
318
|
+
Mint::CommandLine.publish!(files, {})
|
319
|
+
end_time = Time.now
|
320
|
+
|
321
|
+
# All files should be processed
|
322
|
+
10.times do |i|
|
323
|
+
expect(File.exist?("doc#{i}.html")).to be true
|
324
|
+
end
|
325
|
+
|
326
|
+
# Should complete in reasonable time (this is somewhat arbitrary)
|
327
|
+
expect(end_time - start_time).to be < 5.0
|
328
|
+
end
|
329
|
+
|
330
|
+
it "passes file list to templates for navigation" do
|
331
|
+
# This tests the all_files feature for multi-file processing
|
332
|
+
files = []
|
333
|
+
3.times do |i|
|
334
|
+
files << create_markdown_file("page#{i}.md", "# Page #{i}")
|
335
|
+
end
|
336
|
+
|
337
|
+
# Create a template that uses the all_files variable
|
338
|
+
nav_template = <<~ERB
|
339
|
+
<html>
|
340
|
+
<body>
|
341
|
+
<nav>
|
342
|
+
<% if files && files.any? %>
|
343
|
+
<% files.each do |file| %>
|
344
|
+
<a href="<%= file[:html_path] %>"><%= file[:title] %></a>
|
345
|
+
<% end %>
|
346
|
+
<% end %>
|
347
|
+
</nav>
|
348
|
+
<%= content %>
|
349
|
+
</body>
|
350
|
+
</html>
|
351
|
+
ERB
|
352
|
+
|
353
|
+
FileUtils.mkdir_p(".mint/templates/nav")
|
354
|
+
File.write(".mint/templates/nav/layout.erb", nav_template)
|
355
|
+
|
356
|
+
Mint::CommandLine.publish!(files, { layout: "nav" })
|
357
|
+
|
358
|
+
# Check that navigation was included
|
359
|
+
verify_file_content("page0.html") do |content|
|
360
|
+
expect(content).to include("<nav>")
|
361
|
+
expect(content).to include("Page 1")
|
362
|
+
expect(content).to include("Page 2")
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "CLI Template Management" do
|
4
|
+
describe "template operations" do
|
5
|
+
context "in isolated environment" do
|
6
|
+
around(:each) do |example|
|
7
|
+
in_temp_dir do |dir|
|
8
|
+
@test_dir = dir
|
9
|
+
example.run
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Mint::CommandLine.templates" do
|
14
|
+
it "lists templates from specified scope" do
|
15
|
+
create_template_directory("custom")
|
16
|
+
create_template_directory("minimal")
|
17
|
+
|
18
|
+
stdout, stderr = capture_output do
|
19
|
+
Mint::CommandLine.templates("", :local)
|
20
|
+
end
|
21
|
+
|
22
|
+
expect(stdout).to include("custom")
|
23
|
+
expect(stdout).to include("minimal")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "filters templates by pattern" do
|
27
|
+
create_template_directory("custom-dark")
|
28
|
+
create_template_directory("custom-light")
|
29
|
+
create_template_directory("minimal")
|
30
|
+
|
31
|
+
stdout, stderr = capture_output do
|
32
|
+
Mint::CommandLine.templates("custom", :local)
|
33
|
+
end
|
34
|
+
|
35
|
+
expect(stdout).to include("custom-dark")
|
36
|
+
expect(stdout).to include("custom-light")
|
37
|
+
expect(stdout).not_to include("minimal")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "shows template paths in output" do
|
41
|
+
create_template_directory("test-template")
|
42
|
+
|
43
|
+
stdout, stderr = capture_output do
|
44
|
+
Mint::CommandLine.templates("", :local)
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(stdout).to include("test-template")
|
48
|
+
expect(stdout).to include(".mint/templates/test-template")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "handles empty template directory" do
|
52
|
+
stdout, stderr = capture_output do
|
53
|
+
Mint::CommandLine.templates("", :local)
|
54
|
+
end
|
55
|
+
|
56
|
+
expect(stdout.strip).to eq("")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "Mint::CommandLine.install" do
|
61
|
+
it "installs a layout template file" do
|
62
|
+
layout_content = "<html><body><%= yield %></body></html>"
|
63
|
+
create_template_file("custom.erb", :layout, layout_content)
|
64
|
+
|
65
|
+
expect {
|
66
|
+
Mint::CommandLine.install("custom.erb", "mytemplate", :local)
|
67
|
+
}.not_to raise_error
|
68
|
+
|
69
|
+
installed_file = ".mint/templates/mytemplate/layout.erb"
|
70
|
+
expect(File.exist?(installed_file)).to be true
|
71
|
+
expect(File.read(installed_file)).to eq(layout_content)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "installs a style template file" do
|
75
|
+
style_content = "body { background: #f0f0f0; }"
|
76
|
+
create_template_file("custom.css", :style, style_content)
|
77
|
+
|
78
|
+
expect {
|
79
|
+
Mint::CommandLine.install("custom.css", "mystyle", :local)
|
80
|
+
}.not_to raise_error
|
81
|
+
|
82
|
+
installed_file = ".mint/templates/mystyle/style.css"
|
83
|
+
expect(File.exist?(installed_file)).to be true
|
84
|
+
expect(File.read(installed_file)).to eq(style_content)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "creates template directory if it doesn't exist" do
|
88
|
+
create_template_file("layout.erb", :layout)
|
89
|
+
|
90
|
+
expect(File.exist?(".mint/templates/newtemplate")).to be false
|
91
|
+
|
92
|
+
Mint::CommandLine.install("layout.erb", "newtemplate", :local)
|
93
|
+
|
94
|
+
expect(File.exist?(".mint/templates/newtemplate")).to be true
|
95
|
+
expect(File.exist?(".mint/templates/newtemplate/layout.erb")).to be true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "determines template type by file extension" do
|
99
|
+
# Create different file types
|
100
|
+
File.write("layout.haml", "%html\n %body= yield")
|
101
|
+
File.write("style.scss", "$primary: #333;\nbody { color: $primary; }")
|
102
|
+
|
103
|
+
Mint::CommandLine.install("layout.haml", "haml-template", :local)
|
104
|
+
Mint::CommandLine.install("style.scss", "scss-template", :local)
|
105
|
+
|
106
|
+
expect(File.exist?(".mint/templates/haml-template/layout.haml")).to be true
|
107
|
+
expect(File.exist?(".mint/templates/scss-template/style.scss")).to be true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises error for non-existent source file" do
|
111
|
+
expect {
|
112
|
+
Mint::CommandLine.install("nonexistent.erb", "test", :local)
|
113
|
+
}.to raise_error(RuntimeError, /No such file/)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "Mint::CommandLine.uninstall" do
|
119
|
+
it "removes an entire template directory" do
|
120
|
+
create_template_directory("removeme", with_layout: true, with_style: true)
|
121
|
+
|
122
|
+
expect(File.exist?(".mint/templates/removeme")).to be true
|
123
|
+
|
124
|
+
Mint::CommandLine.uninstall("removeme", :local)
|
125
|
+
|
126
|
+
expect(File.exist?(".mint/templates/removeme")).to be false
|
127
|
+
end
|
128
|
+
|
129
|
+
it "handles non-existent templates gracefully" do
|
130
|
+
expect {
|
131
|
+
Mint::CommandLine.uninstall("nonexistent", :local)
|
132
|
+
}.to raise_error(Errno::ENOENT)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "Mint::CommandLine.edit" do
|
137
|
+
it "opens layout template in editor" do
|
138
|
+
create_template_directory("editable", with_layout: true)
|
139
|
+
template_file = ".mint/templates/editable/layout.erb"
|
140
|
+
|
141
|
+
silence_output do
|
142
|
+
mock_editor do
|
143
|
+
expect {
|
144
|
+
Mint::CommandLine.edit("editable", :layout, :local)
|
145
|
+
}.not_to raise_error
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it "opens style template in editor" do
|
151
|
+
create_template_directory("editable", with_style: true)
|
152
|
+
|
153
|
+
silence_output do
|
154
|
+
mock_editor do
|
155
|
+
expect {
|
156
|
+
Mint::CommandLine.edit("editable", :style, :local)
|
157
|
+
}.not_to raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it "prompts to create template if it doesn't exist" do
|
163
|
+
# Mock STDIN to simulate user input
|
164
|
+
allow(STDIN).to receive(:gets).and_return("y\n")
|
165
|
+
|
166
|
+
silence_output do
|
167
|
+
mock_editor do
|
168
|
+
expect {
|
169
|
+
Mint::CommandLine.edit("newtemplate", :layout, :local)
|
170
|
+
}.not_to raise_error
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
expect(File.exist?(".mint/templates/newtemplate/layout.erb")).to be true
|
175
|
+
end
|
176
|
+
|
177
|
+
it "cancels creation when user says no" do
|
178
|
+
allow(STDIN).to receive(:gets).and_return("n\n")
|
179
|
+
|
180
|
+
silence_output do
|
181
|
+
expect {
|
182
|
+
Mint::CommandLine.edit("newtemplate", :layout, :local)
|
183
|
+
}.to raise_error(SystemExit)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it "rejects invalid template types" do
|
188
|
+
silence_output do
|
189
|
+
expect {
|
190
|
+
Mint::CommandLine.edit("template", :invalid, :local)
|
191
|
+
}.to raise_error(SystemExit, /Invalid template type/)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it "requires template name" do
|
196
|
+
silence_output do
|
197
|
+
expect {
|
198
|
+
Mint::CommandLine.edit("", :layout, :local)
|
199
|
+
}.to raise_error(SystemExit, /No template specified/)
|
200
|
+
|
201
|
+
expect {
|
202
|
+
Mint::CommandLine.edit(nil, :layout, :local)
|
203
|
+
}.to raise_error(SystemExit, /No template specified/)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "template creation helpers" do
|
209
|
+
describe "Mint::CommandLine.create_template" do
|
210
|
+
it "creates a layout template with default content" do
|
211
|
+
template_file = Mint::CommandLine.create_template("newlayout", :layout, :local)
|
212
|
+
|
213
|
+
expect(File.exist?(template_file)).to be true
|
214
|
+
content = File.read(template_file)
|
215
|
+
expect(content).to include("<!DOCTYPE html>")
|
216
|
+
expect(content).to include("<%= content %>")
|
217
|
+
expect(template_file).to end_with("/layout.erb")
|
218
|
+
end
|
219
|
+
|
220
|
+
it "creates a style template with default content" do
|
221
|
+
template_file = Mint::CommandLine.create_template("newstyle", :style, :local)
|
222
|
+
|
223
|
+
expect(File.exist?(template_file)).to be true
|
224
|
+
content = File.read(template_file)
|
225
|
+
expect(content).to include("body {")
|
226
|
+
expect(content).to include("font-family:")
|
227
|
+
expect(template_file).to end_with("/style.css")
|
228
|
+
end
|
229
|
+
|
230
|
+
it "creates template directory structure" do
|
231
|
+
Mint::CommandLine.create_template("organized", :layout, :local)
|
232
|
+
|
233
|
+
expect(File.exist?(".mint/templates/organized")).to be true
|
234
|
+
expect(File.directory?(".mint/templates/organized")).to be true
|
235
|
+
end
|
236
|
+
|
237
|
+
it "rejects invalid template types" do
|
238
|
+
silence_output do
|
239
|
+
expect {
|
240
|
+
Mint::CommandLine.create_template("test", :invalid, :local)
|
241
|
+
}.to raise_error(SystemExit, /Invalid template type/)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "default template content" do
|
247
|
+
it "provides valid HTML5 layout template" do
|
248
|
+
content = Mint::CommandLine.default_layout_content
|
249
|
+
|
250
|
+
expect(content).to include("<!DOCTYPE html>")
|
251
|
+
expect(content).to include("<html>")
|
252
|
+
expect(content).to include("<title>Document</title>")
|
253
|
+
expect(content).to include("<%= content %>")
|
254
|
+
expect(content).to include("<%= style %>")
|
255
|
+
end
|
256
|
+
|
257
|
+
it "provides basic CSS style template" do
|
258
|
+
content = Mint::CommandLine.default_style_content
|
259
|
+
|
260
|
+
expect(content).to include("body {")
|
261
|
+
expect(content).to include("font-family:")
|
262
|
+
expect(content).to include("max-width:")
|
263
|
+
expect(content).to include("code {")
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe "template lookup integration" do
|
269
|
+
it "finds installed templates via lookup methods" do
|
270
|
+
create_template_directory("findme", with_layout: true, with_style: true)
|
271
|
+
|
272
|
+
layout_file = Mint.lookup_layout("findme")
|
273
|
+
style_file = Mint.lookup_style("findme")
|
274
|
+
template_dir = Mint.lookup_template("findme")
|
275
|
+
|
276
|
+
expect(layout_file).to include("findme/layout.erb")
|
277
|
+
expect(style_file).to include("findme/style.css")
|
278
|
+
expect(template_dir.to_s).to include("findme")
|
279
|
+
expect(File.exist?(layout_file)).to be true
|
280
|
+
expect(File.exist?(style_file)).to be true
|
281
|
+
expect(File.directory?(template_dir)).to be true
|
282
|
+
end
|
283
|
+
|
284
|
+
it "raises TemplateNotFoundException for missing templates" do
|
285
|
+
expect {
|
286
|
+
Mint.lookup_layout("missing")
|
287
|
+
}.to raise_error(Mint::TemplateNotFoundException)
|
288
|
+
|
289
|
+
expect {
|
290
|
+
Mint.lookup_style("missing")
|
291
|
+
}.to raise_error(Mint::TemplateNotFoundException)
|
292
|
+
|
293
|
+
expect {
|
294
|
+
Mint.lookup_template("missing")
|
295
|
+
}.to raise_error(Mint::TemplateNotFoundException)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
data/spec/css_spec.rb
CHANGED
@@ -39,7 +39,7 @@ module Mint
|
|
39
39
|
|
40
40
|
describe ".parse" do
|
41
41
|
it "transforms a map of human-readable styles into a CSS string" do
|
42
|
-
CSS.parse({ "Font" => "Helvetica" }).
|
42
|
+
expect(CSS.parse({ "Font" => "Helvetica" })).to eq("#container {\n font-family: Helvetica;\n}")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|