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,50 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Tansu
|
3
|
+
class Drawer
|
4
|
+
def initialize(app, options, exclude_path = [])
|
5
|
+
@config = app.config
|
6
|
+
@options = options
|
7
|
+
@dirs = ["/"]
|
8
|
+
@exclude_path = exclude(exclude_path)
|
9
|
+
search_directory(@config.source)
|
10
|
+
end
|
11
|
+
|
12
|
+
def empty
|
13
|
+
empty = []
|
14
|
+
@dirs.each do |dir|
|
15
|
+
glob_path = File.join(@config.source, dir, "#{@config.tansu[:default_document].strip}*")
|
16
|
+
if Dir.glob(glob_path).length == 0
|
17
|
+
empty.push(dir)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
empty
|
21
|
+
end
|
22
|
+
|
23
|
+
def search_directory(dir)
|
24
|
+
regex = Regexp.new("^" + @config.source)
|
25
|
+
Dir.glob(File.join(dir, '*')).each do |path|
|
26
|
+
if File.ftype(path) == "directory" && !exclude?(path)
|
27
|
+
@dirs.push(path.gsub(regex, ""))
|
28
|
+
search_directory(path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def exclude(path)
|
34
|
+
default = [
|
35
|
+
@config.images_dir,
|
36
|
+
@config.js_dir,
|
37
|
+
@config.css_dir,
|
38
|
+
@config.layouts_dir,
|
39
|
+
@options.templates_dir
|
40
|
+
]
|
41
|
+
default | path
|
42
|
+
end
|
43
|
+
|
44
|
+
def exclude?(path)
|
45
|
+
regex = Regexp.new("^#{@config.source}/(#{@exclude_path.join("|")})")
|
46
|
+
regex =~ path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "middleman-tansu/drawer"
|
2
|
+
require "middleman-tansu/helpers"
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Tansu
|
6
|
+
class Extension < ::Middleman::Extension
|
7
|
+
option :exclude_path, %w(sitemap.xml), "Path list that you don't want to see"
|
8
|
+
option :templates_dir, "templates", "Path of template directory's path in source direcotry"
|
9
|
+
option :index_template_name, "index.html", "Name of index template"
|
10
|
+
option :default_document, "index.html", "Name of default document. When you use IIS, set 'default.html'"
|
11
|
+
|
12
|
+
# Helpers for use within templates and layouts.
|
13
|
+
self.defined_helpers = [ ::Middleman::Tansu::Helpers ]
|
14
|
+
|
15
|
+
def initialize(app, options_hash = {}, &block)
|
16
|
+
super
|
17
|
+
app.config.tansu = {
|
18
|
+
:exclude_path => options[:exclude_path],
|
19
|
+
:templates_dir => options[:templates_dir],
|
20
|
+
:default_document => options[:default_document]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_configuration
|
25
|
+
exclude_path = options.exclude_path || []
|
26
|
+
Drawer.new(app, options, exclude_path).empty.each do |path|
|
27
|
+
app.proxy(File.join(path, options[:default_document]),
|
28
|
+
File.join("/", options.templates_dir, options.index_template_name),
|
29
|
+
ignore: true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Tansu
|
3
|
+
module Helpers
|
4
|
+
def path_list(current_path)
|
5
|
+
paths = []
|
6
|
+
splited = current_path.split("/")
|
7
|
+
splited.each_with_index do |val, index|
|
8
|
+
path = File.join("/", splited[0..index])
|
9
|
+
path = path + "/" unless /\.html$/ =~ path
|
10
|
+
val = val.sub(".html", "") if /\.html$/ =~ val
|
11
|
+
paths.push({path: path, name: val}) unless /^index$/ =~ val
|
12
|
+
end
|
13
|
+
paths
|
14
|
+
end
|
15
|
+
|
16
|
+
def breadcrumbs(klass = 'breadcrumbs', root = "Top")
|
17
|
+
li = []
|
18
|
+
li.push("<li class=\"root\">#{link_to(root, "/")}</li>")
|
19
|
+
|
20
|
+
paths = path_list(current_resource.path)
|
21
|
+
paths.each do |path|
|
22
|
+
if path == paths.last
|
23
|
+
li.push("<li class=\"current\">#{path[:name]}</li>")
|
24
|
+
else
|
25
|
+
li.push("<li>#{link_to(path[:name], path[:path])}</li>")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"<ul class=\"#{klass}\">\n#{li.join("\n")}\n</ul>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def children_pages(key = :date, order_by = :asc)
|
32
|
+
dirs = []
|
33
|
+
pages = []
|
34
|
+
|
35
|
+
current_resource.children.each do |page|
|
36
|
+
if !exclude?(page.path)
|
37
|
+
if /index\.html$/ =~ page.path
|
38
|
+
dirs.push(page)
|
39
|
+
else
|
40
|
+
pages.push(page)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Sorting pages and dirs
|
46
|
+
if order_by == :desc
|
47
|
+
pages = pages.sort {|a, b|
|
48
|
+
b.data[key] <=> a.data[key]
|
49
|
+
}
|
50
|
+
dirs = dirs.sort {|a, b|
|
51
|
+
b.path <=> a.path
|
52
|
+
}
|
53
|
+
else
|
54
|
+
pages = pages.sort {|a, b|
|
55
|
+
a.data[key] <=> b.data[key]
|
56
|
+
}
|
57
|
+
dirs = dirs.sort {|a, b|
|
58
|
+
a.path <=> b.path
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
dirs | pages
|
63
|
+
end
|
64
|
+
|
65
|
+
def exclude?(path)
|
66
|
+
regex = Regexp.new("^(#{exclude(path).join("|")})")
|
67
|
+
regex =~ path
|
68
|
+
end
|
69
|
+
|
70
|
+
def exclude(path)
|
71
|
+
default = [
|
72
|
+
config.images_dir,
|
73
|
+
config.js_dir,
|
74
|
+
config.css_dir,
|
75
|
+
config.layouts_dir,
|
76
|
+
config.tansu[:templates_dir]
|
77
|
+
]
|
78
|
+
dirs = default | config.tansu[:exclude_path]
|
79
|
+
end
|
80
|
+
|
81
|
+
def page_name(page)
|
82
|
+
if page.data.title
|
83
|
+
paths = page.path.split("/")
|
84
|
+
paths.pop
|
85
|
+
File.join(paths, page.data.title).gsub(/^\//, "")
|
86
|
+
else
|
87
|
+
page.path.gsub(/(\/index)?\.html$/, "")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def page_url(page)
|
92
|
+
File.join("/", page.path.gsub(/index\.html$/, ""))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'middleman-core/templates'
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Tansu
|
5
|
+
|
6
|
+
class Template < Middleman::Templates::Base
|
7
|
+
class_option 'css_dir',
|
8
|
+
default: 'stylesheets',
|
9
|
+
desc: 'The path to the css files'
|
10
|
+
class_option 'js_dir',
|
11
|
+
default: 'javascripts',
|
12
|
+
desc: 'The path to the javascript files'
|
13
|
+
class_option 'images_dir',
|
14
|
+
default: 'images',
|
15
|
+
desc: 'The path to the image files'
|
16
|
+
|
17
|
+
def self.source_root
|
18
|
+
File.join(File.dirname(__FILE__), 'template')
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_scaffold!
|
22
|
+
template 'shared/Gemfile.tt', File.join(location, 'Gemfile')
|
23
|
+
template 'shared/config.tt', File.join(location, 'config.rb')
|
24
|
+
|
25
|
+
empty_directory File.join(location, 'source', options[:css_dir])
|
26
|
+
empty_directory File.join(location, 'source', options[:js_dir])
|
27
|
+
empty_directory File.join(location, 'source', options[:images_dir])
|
28
|
+
empty_directory File.join(location, 'source', 'templates')
|
29
|
+
empty_directory File.join(location, 'source', 'layouts')
|
30
|
+
|
31
|
+
copy_file 'source/sample.html.md', File.join(location, 'source/sample.html.md')
|
32
|
+
|
33
|
+
copy_file 'source/layouts/layout.slim', File.join(location, 'source/layouts/layout.slim')
|
34
|
+
|
35
|
+
copy_file 'source/stylesheets/all.css.sass', File.join(location, 'source', options[:css_dir], 'all.css.sass')
|
36
|
+
copy_file 'source/stylesheets/github-markdown.css', File.join(location, 'source', options[:css_dir], 'github-markdown.css')
|
37
|
+
|
38
|
+
copy_file 'source/templates/index.html.slim', File.join(location, 'source', 'templates', 'index.html.slim')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
2
|
+
# the following line to use "http://" instead
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gem "middleman", "~>3.3.7"
|
6
|
+
|
7
|
+
gem "middleman-pure", :github => "yterajima/middleman-pure"
|
8
|
+
gem "middleman-tansu", :github => "yterajima/middleman-tansu"
|
9
|
+
gem "middleman-syntax"
|
10
|
+
|
11
|
+
gem "redcarpet"
|
12
|
+
gem "slim"
|
13
|
+
gem "builder"
|
14
|
+
|
15
|
+
# Live-reloading plugin
|
16
|
+
gem "middleman-livereload", "~> 3.1.0"
|
17
|
+
|
18
|
+
# For faster file watcher updates on Windows:
|
19
|
+
gem "wdm", "~> 0.1.0", :platforms => [:mswin, :mingw]
|
20
|
+
|
21
|
+
# Windows does not come with time zone data
|
22
|
+
gem "tzinfo-data", platforms: [:mswin, :mingw]
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "slim"
|
2
|
+
require "builder"
|
3
|
+
|
4
|
+
# Tansu Settings
|
5
|
+
set :site_title, "Middleman-Tansu"
|
6
|
+
activate :tansu
|
7
|
+
|
8
|
+
# Markdown Settings
|
9
|
+
set :markdown_engine, :redcarpet
|
10
|
+
set :markdown, :fenced_code_blocks => true, :smartypants => true, :with_toc_data => true
|
11
|
+
activate :syntax, :inline_theme => 'github'
|
12
|
+
|
13
|
+
###
|
14
|
+
# Compass
|
15
|
+
###
|
16
|
+
|
17
|
+
# Change Compass configuration
|
18
|
+
# compass_config do |config|
|
19
|
+
# config.output_style = :compact
|
20
|
+
# end
|
21
|
+
|
22
|
+
###
|
23
|
+
# Page options, layouts, aliases and proxies
|
24
|
+
###
|
25
|
+
|
26
|
+
# Per-page layout changes:
|
27
|
+
#
|
28
|
+
# With no layout
|
29
|
+
# page "/path/to/file.html", :layout => false
|
30
|
+
#
|
31
|
+
# With alternative layout
|
32
|
+
# page "/path/to/file.html", :layout => :otherlayout
|
33
|
+
#
|
34
|
+
# A path which all have the same layout
|
35
|
+
# with_layout :admin do
|
36
|
+
# page "/admin/*"
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
|
40
|
+
# proxy "/this-page-has-no-template.html", "/template-file.html", :locals => {
|
41
|
+
# :which_fake_page => "Rendering a fake page with a local variable" }
|
42
|
+
|
43
|
+
###
|
44
|
+
# Helpers
|
45
|
+
###
|
46
|
+
|
47
|
+
# Automatic image dimensions on image_tag helper
|
48
|
+
# activate :automatic_image_sizes
|
49
|
+
|
50
|
+
# Reload the browser automatically whenever files change
|
51
|
+
# configure :development do
|
52
|
+
# activate :livereload
|
53
|
+
# end
|
54
|
+
|
55
|
+
# Methods defined in the helpers block are available in templates
|
56
|
+
# helpers do
|
57
|
+
# def some_helper
|
58
|
+
# "Helping"
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
|
62
|
+
set :css_dir, 'stylesheets'
|
63
|
+
|
64
|
+
set :js_dir, 'javascripts'
|
65
|
+
|
66
|
+
set :images_dir, 'images'
|
67
|
+
|
68
|
+
# Build-specific configuration
|
69
|
+
configure :build do
|
70
|
+
# For example, change the Compass output style for deployment
|
71
|
+
# activate :minify_css
|
72
|
+
|
73
|
+
# Minify Javascript on build
|
74
|
+
# activate :minify_javascript
|
75
|
+
|
76
|
+
# Enable cache buster
|
77
|
+
# activate :asset_hash
|
78
|
+
|
79
|
+
# Use relative URLs
|
80
|
+
# activate :relative_assets
|
81
|
+
|
82
|
+
# Or use a different image path
|
83
|
+
# set :http_prefix, "/Content/images/"
|
84
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
meta charset="utf-8"
|
5
|
+
|
6
|
+
/! Always force latest IE rendering engine or request Chrome Frame
|
7
|
+
meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"
|
8
|
+
|
9
|
+
meta name="viewport" content="width=device-width,user-scalable=no,maximum-scale=1"
|
10
|
+
|
11
|
+
title
|
12
|
+
- if /^index.html$/ =~ current_resource.path
|
13
|
+
= config.site_title
|
14
|
+
- elsif data.page.title
|
15
|
+
= "#{data.page.title} - #{config.site_title}"
|
16
|
+
- else
|
17
|
+
= "#{current_resource.path.gsub(/index\.html$/, "")} - #{config.site_title}"
|
18
|
+
|
19
|
+
== stylesheet_link_tag "all"
|
20
|
+
|
21
|
+
body class="#{page_classes}"
|
22
|
+
main
|
23
|
+
header
|
24
|
+
nav.breadcrumbs
|
25
|
+
== breadcrumbs
|
26
|
+
|
27
|
+
h1
|
28
|
+
- if /^index.html$/ =~ current_resource.path
|
29
|
+
= config.site_title
|
30
|
+
- elsif data.page.title
|
31
|
+
= data.page.title
|
32
|
+
- else
|
33
|
+
= current_resource.path.gsub(/index\.html$/, "")
|
34
|
+
|
35
|
+
article.markdown-body
|
36
|
+
- if data.page.author || data.page.date
|
37
|
+
div.metadata
|
38
|
+
- if data.page.author
|
39
|
+
dl
|
40
|
+
dt author
|
41
|
+
dd
|
42
|
+
- if data.page.author.instance_of?(Array)
|
43
|
+
== data.page.author.join(", ")
|
44
|
+
- else
|
45
|
+
== data.page.author
|
46
|
+
|
47
|
+
- if data.page.date
|
48
|
+
dl
|
49
|
+
dt date
|
50
|
+
dd
|
51
|
+
== data.page.date
|
52
|
+
|
53
|
+
== yield
|
54
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
---
|
2
|
+
title: middleman-tansu の簡単な紹介
|
3
|
+
author: yterajima
|
4
|
+
date: 2014-01-25 23:32:00 +0900
|
5
|
+
---
|
6
|
+
|
7
|
+
[middleman-tansu](https://github.com/yterajima/middleman-tansu) は Markdown ファイルをディレクトリを使って分類管理するために開発されているテンプレートです。例えるなら, 静的な wiki のようなものを目指しています。バラバラに管理される Markdown を tansu (箪笥) に入れてまとめて管理できるように工夫されています。
|
8
|
+
|
9
|
+
## middleman-tansu が提供する機能
|
10
|
+
|
11
|
+
1. `middleman tansu` コマンド
|
12
|
+
2. 各ディレクトリに `index.html` を用意する機能
|
13
|
+
3. 自動生成された `index.html` を活用するための Helper
|
14
|
+
4. プロジェクトテンプレート
|
15
|
+
|
16
|
+
### 1.`middleman tansu` コマンド
|
17
|
+
|
18
|
+
[middleman-blog](https://github.com/middleman/middleman-blog) のようにコマンドラインからページのひな形を作成することができます。
|
19
|
+
|
20
|
+
```sh
|
21
|
+
$ middleman tansu path/to/ページ
|
22
|
+
```
|
23
|
+
|
24
|
+
このコマンドによって `source/path/to/ページ.html.md` が作成されます。同時にこのテンプレートに必要な Frontmatter を書き込みます。
|
25
|
+
|
26
|
+
|
27
|
+
### 2.各ディレクトリに `index.html` を用意する機能
|
28
|
+
|
29
|
+
大量の Markdown ファイルを管理するには工夫が必要です。
|
30
|
+
|
31
|
+
`source` ディレクトリ以下に次のようにディレクトリとファイルが用意されているとしましょう。
|
32
|
+
|
33
|
+
```
|
34
|
+
- source
|
35
|
+
- ディレクトリ1
|
36
|
+
- ページ1.md.html
|
37
|
+
- ページ2.md.html
|
38
|
+
- ディレクトリ2
|
39
|
+
- index.html.slim
|
40
|
+
- templates
|
41
|
+
- index.html.slim
|
42
|
+
```
|
43
|
+
|
44
|
+
この状態で `$ middleman server` を実行した場合, `http://localhost:4567` にアクセスしても何も表示されます。また, `http://localhost:4567/ディレクトリ1/` にアクセスしても当然何も表示されません。このまま build & deploy した場合, それぞれのページにたどり着けません。
|
45
|
+
|
46
|
+
そこで, middleman-tansu では `index.html` にあたるファイルがない場合, 動的にそのページを生成しそのディレクトリ中のページやディレクトリへのリンクを提供します。
|
47
|
+
|
48
|
+
__NOTICE__: `index.html` として出力されるファイルが存在する場合は, middleman-tansu はそのディレクトリに元からあった `index.html` を採用します。
|
49
|
+
|
50
|
+
このディレクトリ構成の場合, `source/index.html` と `source/ディレクトリ1/index.html` を自動的に用意します。用意すると言ってもファイルを直接ディレクトリの中に作成する訳ではありません。[動的ページ](https://middlemanapp.com/jp/basics/dynamic-pages/) つまりは `proxy` を使って `$ middleman server`, `$ middleman build` の際にページを出力します。
|
51
|
+
|
52
|
+
### 3.自動生成された `index.html` を活用するための Helper
|
53
|
+
|
54
|
+
いくつかの Helper を提供しています。主に使われるのは次の 2 つになるでしょう。
|
55
|
+
|
56
|
+
- breadcrumbs
|
57
|
+
- 表示されているページまでのパンくずリストを表示する
|
58
|
+
- layout の中で使われることがほとんどです
|
59
|
+
- children_pages
|
60
|
+
- 現在のページがあるディレクトリ中のファイル/ディレクトリ一覧
|
61
|
+
- この Helper は `index.html` になるファイルの中で使われます
|
62
|
+
|
63
|
+
|
64
|
+
### 4.プロジェクトテンプレート
|
65
|
+
|
66
|
+
middleman-tansu は拡張機能と同時にプロジェクトテンプレートを提供しています。次のコマンドで初期化できます。
|
67
|
+
|
68
|
+
```sh
|
69
|
+
$ middleman tansu PROJECT_NAME --template tansu
|
70
|
+
```
|
71
|
+
|
72
|
+
このまま `$ middleman server` すると基本的な機能が用意されたテンプレートを使うことができます。このテンプレートは github-flavored-markdown を使用することができます。もちろんコードの構文ハイライトも対応します。
|
73
|
+
|
74
|
+
|
75
|
+
|