middleman-tansu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +13 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/features/auto_index.feature +155 -0
- data/features/helpers.feature +138 -0
- data/features/step_definitions/helpers_steps.rb +11 -0
- data/features/support/env.rb +4 -0
- data/features/tansu_cli.feature +80 -0
- data/features/template_cli.feature +27 -0
- data/fixtures/.gitkeep +0 -0
- data/fixtures/breadcrumbs-app/config.rb +1 -0
- data/fixtures/breadcrumbs-app/source/dir/page.md +0 -0
- data/fixtures/breadcrumbs-app/source/images/.gitkeep +0 -0
- data/fixtures/breadcrumbs-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/breadcrumbs-app/source/layouts/layout.erb +13 -0
- data/fixtures/breadcrumbs-app/source/stylesheets/all.css +0 -0
- data/fixtures/breadcrumbs-app/source/templates/index.html.erb +1 -0
- data/fixtures/breadcrumbs-params-app/config.rb +1 -0
- data/fixtures/breadcrumbs-params-app/source/dir/page.md +0 -0
- data/fixtures/breadcrumbs-params-app/source/images/.gitkeep +0 -0
- data/fixtures/breadcrumbs-params-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/breadcrumbs-params-app/source/layouts/layout.erb +13 -0
- data/fixtures/breadcrumbs-params-app/source/stylesheets/all.css +0 -0
- data/fixtures/breadcrumbs-params-app/source/templates/index.html.erb +1 -0
- data/fixtures/children-pages-app/config.rb +2 -0
- data/fixtures/children-pages-app/source/dir1/no-title-page.md +4 -0
- data/fixtures/children-pages-app/source/dir1/page1.md +5 -0
- data/fixtures/children-pages-app/source/dir1/page2.md +5 -0
- data/fixtures/children-pages-app/source/dir1/page3.md +5 -0
- data/fixtures/children-pages-app/source/dir1/sub_dir1/page1.md +5 -0
- data/fixtures/children-pages-app/source/dir1/sub_dir2/.gitkeep +0 -0
- data/fixtures/children-pages-app/source/dir2/.gitkeep +0 -0
- data/fixtures/children-pages-app/source/images/.gitkeep +0 -0
- data/fixtures/children-pages-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/children-pages-app/source/layouts/layout.erb +13 -0
- data/fixtures/children-pages-app/source/page1.md +5 -0
- data/fixtures/children-pages-app/source/stylesheets/all.css +0 -0
- data/fixtures/children-pages-app/source/templates/index.html.erb +1 -0
- data/fixtures/children-pages-with-category-app/config.rb +2 -0
- data/fixtures/children-pages-with-category-app/source/dir1/no-title-page.md +5 -0
- data/fixtures/children-pages-with-category-app/source/dir1/page1.md +6 -0
- data/fixtures/children-pages-with-category-app/source/dir1/page2.md +6 -0
- data/fixtures/children-pages-with-category-app/source/dir1/page3.md +6 -0
- data/fixtures/children-pages-with-category-app/source/dir1/sub_dir1/page1.md +5 -0
- data/fixtures/children-pages-with-category-app/source/dir1/sub_dir2/.gitkeep +0 -0
- data/fixtures/children-pages-with-category-app/source/dir2/.gitkeep +0 -0
- data/fixtures/children-pages-with-category-app/source/images/.gitkeep +0 -0
- data/fixtures/children-pages-with-category-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/children-pages-with-category-app/source/layouts/layout.erb +13 -0
- data/fixtures/children-pages-with-category-app/source/page1.md +5 -0
- data/fixtures/children-pages-with-category-app/source/stylesheets/all.css +0 -0
- data/fixtures/children-pages-with-category-app/source/templates/index.html.erb +1 -0
- data/fixtures/drawer-app-with-markdown/config.rb +1 -0
- data/fixtures/drawer-app-with-markdown/source/empty_dir/sub_empty_dir/.gitkeep +0 -0
- data/fixtures/drawer-app-with-markdown/source/empty_dir/sub_empty_dir/sample.html.md +1 -0
- data/fixtures/drawer-app-with-markdown/source/images/.gitkeep +0 -0
- data/fixtures/drawer-app-with-markdown/source/javascripts/.gitkeep +0 -0
- data/fixtures/drawer-app-with-markdown/source/layouts/layout.erb +9 -0
- data/fixtures/drawer-app-with-markdown/source/not_empty_dir/index.html.md +1 -0
- data/fixtures/drawer-app-with-markdown/source/stylesheets/all.css +0 -0
- data/fixtures/drawer-app-with-markdown/source/templates/index.html.md +1 -0
- data/fixtures/drawer-app/config.rb +1 -0
- data/fixtures/drawer-app/source/empty_dir/sub_empty_dir/.gitkeep +0 -0
- data/fixtures/drawer-app/source/empty_dir/sub_empty_dir/sample.html.md +1 -0
- data/fixtures/drawer-app/source/images/.gitkeep +0 -0
- data/fixtures/drawer-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/drawer-app/source/layouts/layout.erb +9 -0
- data/fixtures/drawer-app/source/not_empty_dir/index.html.erb +2 -0
- data/fixtures/drawer-app/source/stylesheets/all.css +0 -0
- data/fixtures/drawer-app/source/templates/index.html.erb +1 -0
- data/fixtures/empty-app/source/.gitkeep +0 -0
- data/fixtures/path-list-app/config.rb +1 -0
- data/fixtures/path-list-app/source/images/.gitkeep +0 -0
- data/fixtures/path-list-app/source/javascripts/.gitkeep +0 -0
- data/fixtures/path-list-app/source/layouts/layout.erb +9 -0
- data/fixtures/path-list-app/source/page/list/.gitkeep +0 -0
- data/fixtures/path-list-app/source/stylesheets/all.css +0 -0
- data/fixtures/path-list-app/source/templates/index.html.erb +15 -0
- data/lib/middleman-tansu.rb +12 -0
- data/lib/middleman-tansu/command.rb +126 -0
- data/lib/middleman-tansu/drawer.rb +50 -0
- data/lib/middleman-tansu/extension.rb +34 -0
- data/lib/middleman-tansu/helpers.rb +96 -0
- data/lib/middleman-tansu/template.rb +42 -0
- data/lib/middleman-tansu/template/shared/Gemfile.tt +22 -0
- data/lib/middleman-tansu/template/shared/config.tt +84 -0
- data/lib/middleman-tansu/template/source/layouts/layout.slim +54 -0
- data/lib/middleman-tansu/template/source/sample.html.md +75 -0
- data/lib/middleman-tansu/template/source/stylesheets/all.css.sass +82 -0
- data/lib/middleman-tansu/template/source/stylesheets/github-markdown.css +696 -0
- data/lib/middleman-tansu/template/source/templates/index.html.slim +6 -0
- data/lib/middleman-tansu/version.rb +5 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-tansu.gemspec +32 -0
- metadata +259 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Template CLI
|
2
|
+
|
3
|
+
Scenario: Create a new project
|
4
|
+
Given I run `middleman init MY_PROJECT --template tansu`
|
5
|
+
And the exit status should be 0
|
6
|
+
When I cd to "MY_PROJECT"
|
7
|
+
Then the following files should exist:
|
8
|
+
| Gemfile |
|
9
|
+
| .gitignore |
|
10
|
+
| config.rb |
|
11
|
+
| source/sample.html.md |
|
12
|
+
| source/layouts/layout.slim |
|
13
|
+
| source/stylesheets/all.css.sass |
|
14
|
+
| source/stylesheets/github-markdown.css |
|
15
|
+
| source/templates/index.html.slim |
|
16
|
+
|
17
|
+
Scenario: Build a new project
|
18
|
+
Given I run `middleman init MY_PROJECT --template tansu`
|
19
|
+
And I cd to "MY_PROJECT"
|
20
|
+
When I run `middleman build`
|
21
|
+
Then the exit status should be 0
|
22
|
+
And the following files should exist:
|
23
|
+
| build/index.html |
|
24
|
+
| build/sample.html |
|
25
|
+
| build/stylesheets/all.css |
|
26
|
+
And the file "build/index.html" should contain "middleman-tansu の簡単な紹介"
|
27
|
+
|
data/fixtures/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :tansu
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Proxy Page</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :tansu
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Proxy Page</p>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Proxy Page</p>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Proxy Page</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :tansu
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Sample
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Not Empty
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Proxy Template
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :tansu
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Sample
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Proxy Template</h1>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :tansu
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h1>Helpers</h1>
|
2
|
+
|
3
|
+
|
4
|
+
<h2>path_list helper</h2>
|
5
|
+
|
6
|
+
<% paths = path_list(current_resource.path) %>
|
7
|
+
<% if paths.length > 0 %>
|
8
|
+
<ul>
|
9
|
+
<% paths.each do |path| %>
|
10
|
+
<li><%= "#{path[:name]}:#{path[:path]}" %></li>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
<% else %>
|
14
|
+
<p>No Path List</p>
|
15
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
require "middleman-tansu/version"
|
3
|
+
require "middleman-tansu/template"
|
4
|
+
require "middleman-tansu/command"
|
5
|
+
|
6
|
+
Middleman::Templates.register :tansu, Middleman::Tansu::Template
|
7
|
+
|
8
|
+
::Middleman::Extensions.register(:tansu) do
|
9
|
+
require "middleman-tansu/extension"
|
10
|
+
::Middleman::Tansu::Extension
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "middleman-core/cli"
|
2
|
+
require "active_support/core_ext/time/zones"
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Cli
|
6
|
+
# This class provides a "tansu" command for the middleman CLI.
|
7
|
+
# "tansu" command has some options:
|
8
|
+
# - '-f': set file extension, default "md"
|
9
|
+
# - '-d': set date(yyyy-mm-dd). Default is now. This is used in Frontmatter.
|
10
|
+
# - '-a': set author name. Default "ENV['USER']".
|
11
|
+
class Tansu < Thor
|
12
|
+
include Thor::Actions
|
13
|
+
|
14
|
+
check_unknown_options!
|
15
|
+
|
16
|
+
namespace :tansu
|
17
|
+
|
18
|
+
def initialize(*args)
|
19
|
+
super
|
20
|
+
Time.zone = Time.zone || "UTC"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.source_root
|
24
|
+
ENV['MM_ROOT']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Tell Thor to exit with a nonzero exit code on failure
|
28
|
+
def self.exit_on_failure?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "tansu path/to/TITLE", "Create a new Tansu page"
|
33
|
+
method_option "file",
|
34
|
+
aliases: "-f",
|
35
|
+
desc: "The file extension to create the Tansu page (default: md)",
|
36
|
+
default: "md"
|
37
|
+
method_option "date",
|
38
|
+
aliases: "-d",
|
39
|
+
desc: "The date to create the Tansu page with (default: Time.zone.now)"
|
40
|
+
method_option "author",
|
41
|
+
aliases: "-a",
|
42
|
+
desc: "The author name to create the Tansu page (default: ENV['USER'])"
|
43
|
+
method_option "frontmatter",
|
44
|
+
desc: "Additions of Frontmatter. ex: \"category: sample, tags: frontmatter\"",
|
45
|
+
default: ""
|
46
|
+
def tansu(path)
|
47
|
+
paths = path.split("/")
|
48
|
+
title = paths.pop
|
49
|
+
ext = options[:file]
|
50
|
+
date = options[:date] ? Time.zone.parse(options[:date]) : Time.zone.now
|
51
|
+
author = options[:author] || ENV["USER"]
|
52
|
+
add_frontmatter = options[:frontmatter]
|
53
|
+
|
54
|
+
if Regexp.new(".html.#{ext}$") !~ title
|
55
|
+
filename = "#{title}.html.#{ext}"
|
56
|
+
end
|
57
|
+
|
58
|
+
dir = destination_dir(paths)
|
59
|
+
file = File.join(dir, filename)
|
60
|
+
|
61
|
+
if !Dir.exists?(dir)
|
62
|
+
FileUtils.mkdir_p dir
|
63
|
+
end
|
64
|
+
|
65
|
+
if File.exists?(file)
|
66
|
+
puts "#{file} is exist"
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
|
70
|
+
File.open(file, 'w') do |f|
|
71
|
+
f.puts frontmatter(title, author, date, add_frontmatter)
|
72
|
+
end
|
73
|
+
puts "create new tansu page: #{file}"
|
74
|
+
end
|
75
|
+
|
76
|
+
no_tasks do
|
77
|
+
def frontmatter(title, author, date, frontmatter)
|
78
|
+
data = {
|
79
|
+
:title => title,
|
80
|
+
:author => author,
|
81
|
+
:date => date
|
82
|
+
}
|
83
|
+
|
84
|
+
if !frontmatter.empty?
|
85
|
+
data = data.merge(add_frontmatter(frontmatter))
|
86
|
+
end
|
87
|
+
|
88
|
+
rows = ["---"]
|
89
|
+
data.each do |label, data|
|
90
|
+
rows << "#{label}: #{data.to_s.strip}"
|
91
|
+
end
|
92
|
+
rows << ["---"]
|
93
|
+
rows << "\n\n"
|
94
|
+
|
95
|
+
rows.join("\n")
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_frontmatter(str)
|
99
|
+
{} if str.empty?
|
100
|
+
|
101
|
+
frontmatter = {}
|
102
|
+
str.split(",").each do |row|
|
103
|
+
if /.+:.+/ =~ row
|
104
|
+
ary, label, data = row.split(/(.+?):(.+)$/)
|
105
|
+
frontmatter[label] = data
|
106
|
+
else
|
107
|
+
frontmatter[row] = ""
|
108
|
+
end
|
109
|
+
end
|
110
|
+
frontmatter
|
111
|
+
end
|
112
|
+
|
113
|
+
def destination_dir(dir)
|
114
|
+
app = Middleman::Application
|
115
|
+
source = File.join(app.root, app.config.source)
|
116
|
+
|
117
|
+
if dir == nil || dir == '.'
|
118
|
+
source
|
119
|
+
else
|
120
|
+
File.join(source, dir)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|