middleman-tansu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +13 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +31 -0
  7. data/Rakefile +2 -0
  8. data/features/auto_index.feature +155 -0
  9. data/features/helpers.feature +138 -0
  10. data/features/step_definitions/helpers_steps.rb +11 -0
  11. data/features/support/env.rb +4 -0
  12. data/features/tansu_cli.feature +80 -0
  13. data/features/template_cli.feature +27 -0
  14. data/fixtures/.gitkeep +0 -0
  15. data/fixtures/breadcrumbs-app/config.rb +1 -0
  16. data/fixtures/breadcrumbs-app/source/dir/page.md +0 -0
  17. data/fixtures/breadcrumbs-app/source/images/.gitkeep +0 -0
  18. data/fixtures/breadcrumbs-app/source/javascripts/.gitkeep +0 -0
  19. data/fixtures/breadcrumbs-app/source/layouts/layout.erb +13 -0
  20. data/fixtures/breadcrumbs-app/source/stylesheets/all.css +0 -0
  21. data/fixtures/breadcrumbs-app/source/templates/index.html.erb +1 -0
  22. data/fixtures/breadcrumbs-params-app/config.rb +1 -0
  23. data/fixtures/breadcrumbs-params-app/source/dir/page.md +0 -0
  24. data/fixtures/breadcrumbs-params-app/source/images/.gitkeep +0 -0
  25. data/fixtures/breadcrumbs-params-app/source/javascripts/.gitkeep +0 -0
  26. data/fixtures/breadcrumbs-params-app/source/layouts/layout.erb +13 -0
  27. data/fixtures/breadcrumbs-params-app/source/stylesheets/all.css +0 -0
  28. data/fixtures/breadcrumbs-params-app/source/templates/index.html.erb +1 -0
  29. data/fixtures/children-pages-app/config.rb +2 -0
  30. data/fixtures/children-pages-app/source/dir1/no-title-page.md +4 -0
  31. data/fixtures/children-pages-app/source/dir1/page1.md +5 -0
  32. data/fixtures/children-pages-app/source/dir1/page2.md +5 -0
  33. data/fixtures/children-pages-app/source/dir1/page3.md +5 -0
  34. data/fixtures/children-pages-app/source/dir1/sub_dir1/page1.md +5 -0
  35. data/fixtures/children-pages-app/source/dir1/sub_dir2/.gitkeep +0 -0
  36. data/fixtures/children-pages-app/source/dir2/.gitkeep +0 -0
  37. data/fixtures/children-pages-app/source/images/.gitkeep +0 -0
  38. data/fixtures/children-pages-app/source/javascripts/.gitkeep +0 -0
  39. data/fixtures/children-pages-app/source/layouts/layout.erb +13 -0
  40. data/fixtures/children-pages-app/source/page1.md +5 -0
  41. data/fixtures/children-pages-app/source/stylesheets/all.css +0 -0
  42. data/fixtures/children-pages-app/source/templates/index.html.erb +1 -0
  43. data/fixtures/children-pages-with-category-app/config.rb +2 -0
  44. data/fixtures/children-pages-with-category-app/source/dir1/no-title-page.md +5 -0
  45. data/fixtures/children-pages-with-category-app/source/dir1/page1.md +6 -0
  46. data/fixtures/children-pages-with-category-app/source/dir1/page2.md +6 -0
  47. data/fixtures/children-pages-with-category-app/source/dir1/page3.md +6 -0
  48. data/fixtures/children-pages-with-category-app/source/dir1/sub_dir1/page1.md +5 -0
  49. data/fixtures/children-pages-with-category-app/source/dir1/sub_dir2/.gitkeep +0 -0
  50. data/fixtures/children-pages-with-category-app/source/dir2/.gitkeep +0 -0
  51. data/fixtures/children-pages-with-category-app/source/images/.gitkeep +0 -0
  52. data/fixtures/children-pages-with-category-app/source/javascripts/.gitkeep +0 -0
  53. data/fixtures/children-pages-with-category-app/source/layouts/layout.erb +13 -0
  54. data/fixtures/children-pages-with-category-app/source/page1.md +5 -0
  55. data/fixtures/children-pages-with-category-app/source/stylesheets/all.css +0 -0
  56. data/fixtures/children-pages-with-category-app/source/templates/index.html.erb +1 -0
  57. data/fixtures/drawer-app-with-markdown/config.rb +1 -0
  58. data/fixtures/drawer-app-with-markdown/source/empty_dir/sub_empty_dir/.gitkeep +0 -0
  59. data/fixtures/drawer-app-with-markdown/source/empty_dir/sub_empty_dir/sample.html.md +1 -0
  60. data/fixtures/drawer-app-with-markdown/source/images/.gitkeep +0 -0
  61. data/fixtures/drawer-app-with-markdown/source/javascripts/.gitkeep +0 -0
  62. data/fixtures/drawer-app-with-markdown/source/layouts/layout.erb +9 -0
  63. data/fixtures/drawer-app-with-markdown/source/not_empty_dir/index.html.md +1 -0
  64. data/fixtures/drawer-app-with-markdown/source/stylesheets/all.css +0 -0
  65. data/fixtures/drawer-app-with-markdown/source/templates/index.html.md +1 -0
  66. data/fixtures/drawer-app/config.rb +1 -0
  67. data/fixtures/drawer-app/source/empty_dir/sub_empty_dir/.gitkeep +0 -0
  68. data/fixtures/drawer-app/source/empty_dir/sub_empty_dir/sample.html.md +1 -0
  69. data/fixtures/drawer-app/source/images/.gitkeep +0 -0
  70. data/fixtures/drawer-app/source/javascripts/.gitkeep +0 -0
  71. data/fixtures/drawer-app/source/layouts/layout.erb +9 -0
  72. data/fixtures/drawer-app/source/not_empty_dir/index.html.erb +2 -0
  73. data/fixtures/drawer-app/source/stylesheets/all.css +0 -0
  74. data/fixtures/drawer-app/source/templates/index.html.erb +1 -0
  75. data/fixtures/empty-app/source/.gitkeep +0 -0
  76. data/fixtures/path-list-app/config.rb +1 -0
  77. data/fixtures/path-list-app/source/images/.gitkeep +0 -0
  78. data/fixtures/path-list-app/source/javascripts/.gitkeep +0 -0
  79. data/fixtures/path-list-app/source/layouts/layout.erb +9 -0
  80. data/fixtures/path-list-app/source/page/list/.gitkeep +0 -0
  81. data/fixtures/path-list-app/source/stylesheets/all.css +0 -0
  82. data/fixtures/path-list-app/source/templates/index.html.erb +15 -0
  83. data/lib/middleman-tansu.rb +12 -0
  84. data/lib/middleman-tansu/command.rb +126 -0
  85. data/lib/middleman-tansu/drawer.rb +50 -0
  86. data/lib/middleman-tansu/extension.rb +34 -0
  87. data/lib/middleman-tansu/helpers.rb +96 -0
  88. data/lib/middleman-tansu/template.rb +42 -0
  89. data/lib/middleman-tansu/template/shared/Gemfile.tt +22 -0
  90. data/lib/middleman-tansu/template/shared/config.tt +84 -0
  91. data/lib/middleman-tansu/template/source/layouts/layout.slim +54 -0
  92. data/lib/middleman-tansu/template/source/sample.html.md +75 -0
  93. data/lib/middleman-tansu/template/source/stylesheets/all.css.sass +82 -0
  94. data/lib/middleman-tansu/template/source/stylesheets/github-markdown.css +696 -0
  95. data/lib/middleman-tansu/template/source/templates/index.html.slim +6 -0
  96. data/lib/middleman-tansu/version.rb +5 -0
  97. data/lib/middleman_extension.rb +1 -0
  98. data/middleman-tansu.gemspec +32 -0
  99. 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
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <h1>Helpers</h1>
8
+
9
+ <h2>breadcrumbs helper</h2>
10
+ <%= breadcrumbs %>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <p>Proxy Page</p>
@@ -0,0 +1 @@
1
+ activate :tansu
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <h1>Helpers</h1>
8
+
9
+ <h2>breadcrumbs helper</h2>
10
+ <%= breadcrumbs("bread-links", "Home") %>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <p>Proxy Page</p>
@@ -0,0 +1,2 @@
1
+ activate :tansu
2
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ author: John Doe
3
+ date: 2015-01-24 22:00:00 +0900
4
+ ---
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Page1 Title
3
+ author: John Doe
4
+ date: 2015-01-10 22:00:00 +0900
5
+ ---
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Page2 Title
3
+ author: John Doe
4
+ date: 2015-01-11 08:00:00 +0900
5
+ ---
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Page3 Title
3
+ author: John Doe
4
+ date: 2015-01-15 12:00:00 +0900
5
+ ---
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Sub Page1 Title
3
+ author: John Doe
4
+ date: 2015-01-01 22:00:00 +0900
5
+ ---
File without changes
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <h1>Helpers</h1>
8
+
9
+ <h2>breadcrumbs helper</h2>
10
+ <%= breadcrumbs %>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Page1 Title
3
+ author: John Doe
4
+ date: 2014-12-22 11:25:00 +0900
5
+ ---
@@ -0,0 +1 @@
1
+ <p>Proxy Page</p>
@@ -0,0 +1,2 @@
1
+ activate :tansu
2
+
@@ -0,0 +1,5 @@
1
+ ---
2
+ author: John Doe
3
+ date: 2015-01-24 22:00:00 +0900
4
+ category: 4th category
5
+ ---
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Page1 Title
3
+ author: John Doe
4
+ date: 2015-01-10 22:00:00 +0900
5
+ category: 1st category
6
+ ---
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Page2 Title
3
+ author: John Doe
4
+ date: 2015-01-11 08:00:00 +0900
5
+ category: 2nd category
6
+ ---
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Page3 Title
3
+ author: John Doe
4
+ date: 2015-01-15 12:00:00 +0900
5
+ category: 3rd category
6
+ ---
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Sub Page1 Title
3
+ author: John Doe
4
+ date: 2015-01-01 22:00:00 +0900
5
+ ---
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <h1>Helpers</h1>
8
+
9
+ <h2>breadcrumbs helper</h2>
10
+ <%= breadcrumbs %>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Page1 Title
3
+ author: John Doe
4
+ date: 2014-12-22 11:25:00 +0900
5
+ ---
@@ -0,0 +1 @@
1
+ activate :tansu
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1 @@
1
+ activate :tansu
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Not Empty</h1>
2
+
File without changes
@@ -0,0 +1 @@
1
+ <h1>Proxy Template</h1>
File without changes
@@ -0,0 +1 @@
1
+ activate :tansu
File without changes
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <meta charsrt="utf-8">
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
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