PlainSite 1.2.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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +43 -0
  4. data/LICENSE +20 -0
  5. data/PlainSite.gemspec +40 -0
  6. data/README.md +276 -0
  7. data/Rakefile +34 -0
  8. data/_config.yml +6 -0
  9. data/bin/plainsite +76 -0
  10. data/lib/PlainSite.rb +5 -0
  11. data/lib/PlainSite/Commands.rb +76 -0
  12. data/lib/PlainSite/Data/Category.rb +235 -0
  13. data/lib/PlainSite/Data/FrontMatterFile.rb +64 -0
  14. data/lib/PlainSite/Data/Post.rb +237 -0
  15. data/lib/PlainSite/Data/PostList.rb +164 -0
  16. data/lib/PlainSite/Data/PostListPage.rb +80 -0
  17. data/lib/PlainSite/RenderTask.rb +235 -0
  18. data/lib/PlainSite/Site.rb +330 -0
  19. data/lib/PlainSite/SocketPatch.rb +15 -0
  20. data/lib/PlainSite/Tpl/ExtMethods.rb +55 -0
  21. data/lib/PlainSite/Tpl/LayErb.rb +73 -0
  22. data/lib/PlainSite/Utils.rb +79 -0
  23. data/lib/PlainSite/_scaffold/_src/assets/README.md +5 -0
  24. data/lib/PlainSite/_scaffold/_src/assets/css/style.css +506 -0
  25. data/lib/PlainSite/_scaffold/_src/assets/favicon.ico +0 -0
  26. data/lib/PlainSite/_scaffold/_src/config.yml +10 -0
  27. data/lib/PlainSite/_scaffold/_src/data/essays/game-of-life.md +15 -0
  28. data/lib/PlainSite/_scaffold/_src/data/essays/phoenix-rebirth.html +15 -0
  29. data/lib/PlainSite/_scaffold/_src/data/programming/hello-world.md +48 -0
  30. data/lib/PlainSite/_scaffold/_src/extensions/TplExt.rb +23 -0
  31. data/lib/PlainSite/_scaffold/_src/routes.rb +49 -0
  32. data/lib/PlainSite/_scaffold/_src/templates/404.html +16 -0
  33. data/lib/PlainSite/_scaffold/_src/templates/about.html +11 -0
  34. data/lib/PlainSite/_scaffold/_src/templates/base.html +32 -0
  35. data/lib/PlainSite/_scaffold/_src/templates/header.html +8 -0
  36. data/lib/PlainSite/_scaffold/_src/templates/index.html +25 -0
  37. data/lib/PlainSite/_scaffold/_src/templates/list.html +41 -0
  38. data/lib/PlainSite/_scaffold/_src/templates/post.html +81 -0
  39. data/lib/PlainSite/_scaffold/_src/templates/rss.erb +29 -0
  40. data/test/CategoryTest.rb +63 -0
  41. data/test/FrontMatterFileTest.rb +40 -0
  42. data/test/LayErbTest.rb +20 -0
  43. data/test/ObjectProxyTest.rb +30 -0
  44. data/test/PostListTest.rb +55 -0
  45. data/test/PostTest.rb +48 -0
  46. data/test/SiteTest.rb +105 -0
  47. data/test/fixtures/2012-06-12-test.md +7 -0
  48. data/test/fixtures/category-demo/2012-06-12-post1.md +7 -0
  49. data/test/fixtures/category-demo/2013-05-01-post2.md +7 -0
  50. data/test/fixtures/category-demo/_meta.yml +1 -0
  51. data/test/fixtures/category-demo/index.md +6 -0
  52. data/test/fixtures/category-demo/sub-category1/sub-post1.md +1 -0
  53. data/test/fixtures/category-demo/sub-category2/sub-post2.md +1 -0
  54. data/test/fixtures/include.erb +1 -0
  55. data/test/fixtures/invalid-front-matter.html +7 -0
  56. data/test/fixtures/layout.erb +1 -0
  57. data/test/fixtures/no-front-matter.html +2 -0
  58. data/test/fixtures/tpl.erb +7 -0
  59. data/test/fixtures/valid-front-matter.html +14 -0
  60. data/test/runtest +6 -0
  61. metadata +202 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 313dfb3ffc12bf634379115f8bd397667e478045
4
+ data.tar.gz: 8819599394528bfe0c69fca6227ede91c9ab82f9
5
+ SHA512:
6
+ metadata.gz: eb7f464d362f286bf3e4d4fd5937b3a1fc0f6211b7c41cbf85b925e2624dca44976a662def2cc53d3481bf0a1e8c9eb39df750e01769b04f1d0f516683c364d2
7
+ data.tar.gz: 5a85fae2d574b4ef272dfc6f050c95279f45a956a3ea09c1d4f4002a524192db0919bfa5694e9ed91d46be99d2b2937382eea875969f7ebdf02ec3bd79a47d9a
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ PlainSite (1.2.0)
5
+ commander (~> 4.4)
6
+ git (~> 1.5)
7
+ kramdown (~> 1.17)
8
+ listen (~> 3.1)
9
+ pygments.rb (~> 1.2)
10
+ rake (~> 12.3)
11
+ safe_yaml (~> 1.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ commander (4.4.7)
17
+ highline (~> 2.0.0)
18
+ ffi (1.11.1-x64-mingw32)
19
+ git (1.5.0)
20
+ highline (2.0.2)
21
+ kramdown (1.17.0)
22
+ listen (3.1.5)
23
+ rb-fsevent (~> 0.9, >= 0.9.4)
24
+ rb-inotify (~> 0.9, >= 0.9.7)
25
+ ruby_dep (~> 1.2)
26
+ multi_json (1.13.1)
27
+ pygments.rb (1.2.1)
28
+ multi_json (>= 1.0.0)
29
+ rake (12.3.2)
30
+ rb-fsevent (0.10.3)
31
+ rb-inotify (0.10.0)
32
+ ffi (~> 1.0)
33
+ ruby_dep (1.5.0)
34
+ safe_yaml (1.0.5)
35
+
36
+ PLATFORMS
37
+ x64-mingw32
38
+
39
+ DEPENDENCIES
40
+ PlainSite!
41
+
42
+ BUNDLED WITH
43
+ 1.17.1
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 CJ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
+ require "PlainSite"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'PlainSite'
8
+ s.version = PlainSite::VERSION
9
+ s.license = 'MIT'
10
+ s.date = '2013-08-25'
11
+ s.author = 'Jex'
12
+ s.email = 'i@jex.im'
13
+ s.homepage = 'https://github.com/CJex/PlainSite'
14
+ s.summary = 'A Truely Hackable Static Site Generator.'
15
+ s.description = 'PlainSite is a simple but powerful static site generator inspired by Jekyll and Octopress.'
16
+
17
+ s.files = Dir['**/*'].reject { |f|
18
+ (File.directory? f) || (f.end_with? ".gem")
19
+ }
20
+
21
+ s.test_files = s.files.select { |path| path =~ /^test\/.*_test\.rb/ }
22
+ s.require_path = 'lib'
23
+ s.bindir = 'bin'
24
+ s.executables = ['plainsite']
25
+
26
+ s.required_ruby_version = '>= 1.9.3'
27
+
28
+ [
29
+ 'pygments.rb', '~> 1.2',
30
+ 'kramdown', '~> 1.17',
31
+ 'safe_yaml', '~> 1.0',
32
+ 'git', '~> 1.5',
33
+ 'rake', '~> 12.3',
34
+ 'commander', '~> 4.4',
35
+ 'listen', '~> 3.1'
36
+ ].each_slice(2) do |a|
37
+ s.add_runtime_dependency *a
38
+ end
39
+
40
+ end
@@ -0,0 +1,276 @@
1
+ PlainSite
2
+ =========
3
+
4
+ PlainSite:A Truely Hackable Static Site Generator.
5
+
6
+ <strong style="font-size:larger; color:red;"> This project is no longer maintained! </strong>
7
+
8
+ ## Getting Started
9
+
10
+ 1. Install [Ruby](https://www.ruby-lang.org/) and then:
11
+ ```bash
12
+ gem install PlainSite
13
+ ```
14
+
15
+ 2. Init site:
16
+ ```bash
17
+ cd mysite
18
+ plainsite init
19
+ ```
20
+
21
+ 3. Create new post:
22
+ ```bash
23
+ plainsite newpost post-slug 'Hello,wolrd!This is the title!'
24
+ ```
25
+
26
+ 4. Preview site,open <http://localhost:1990/> in your web browser.
27
+ ```bash
28
+ plainsite serve
29
+ ```
30
+
31
+ 5. Configure '_src/config.yml'
32
+ ```yaml
33
+ url: http://example.com # You site's domain or url prefix.
34
+ disqus_id: # Config to enable disqus comments.
35
+ name: YouBlogName
36
+ author: YouName
37
+ ```
38
+
39
+ 6. Build site static pages:
40
+ ```bash
41
+ plainsite build
42
+ ```
43
+
44
+ ## Features
45
+ 1. Give you back full control of generating pages.
46
+ 2. Along with Git,PlainSite can generate only updated posts' corresponding pages.
47
+ 3. Builtin live reload preview web server.
48
+ 4. Generate relative url thus enable to view site through `file://` protocal without any web server.
49
+ 5. Auto clean deleted posts' corresponding pages.
50
+ 6. Pagination becomes incredibly easy.
51
+
52
+
53
+ ## Site Directory Structrue
54
+
55
+ Run `plainsite init` will get things done.
56
+
57
+ ```
58
+ .
59
+ ├── .git
60
+ ├── .nojekyll
61
+ └── _src
62
+ ├── assets
63
+ ├── data
64
+ │ ├── category
65
+ │ ├── demo-post.html
66
+ │ └── 2012-12-25-hello-world.md
67
+ ├── templates
68
+ │ └── post.html
69
+ ├── routes.rb
70
+ └── config.yml
71
+ ```
72
+
73
+ All files under `_src` directory are the source files.Here is each sub directory's usage:
74
+
75
+ 1. `assets`: Put all your static files in it for easier maintenance. PlainSite will copy them to site's root on building.For example, if you want to [add a CNAME file to enable custom domain](https://help.github.com/articles/adding-a-cname-file-to-your-repository/),you need to put it at `/_src/assets/CNAME`,so PlainSite will copy it to `/CNAME`.
76
+ 2. `data`: Put your post files here,each file corresponds to a `Post`,each directory corresponds to a `Category`.
77
+ 3. `templates`: ERB template files.
78
+ 4. `routes.rb`: All custom tricks: url pattern,pagination, etc...
79
+ 5. `config.yml`: Site configuration.
80
+
81
+
82
+ ## Command Usages
83
+ 1. Run `plainsite build --local` will use relative url in output pages.
84
+ 2. Run `plainsite build --all` will force generate all pages.
85
+ 1. Run `plainsite help` for more command line options.
86
+
87
+ ## Code Highlight
88
+ Example post file content:
89
+ ```html
90
+ ---
91
+ title: Hello,world!
92
+ ---
93
+
94
+ **Here is post's content!**
95
+
96
+ Ruby:
97
+ <highlight ruby>
98
+ puts "Hello,world!"
99
+ </highlight>
100
+
101
+ Python,with line numbers:
102
+ <highlight python linenos>
103
+ def hello():
104
+ print("Hello")
105
+ </highlight>
106
+
107
+ Specify the start line number:
108
+ <highlight php linenos=20>
109
+ echo "PlainSite";
110
+ ob_flush();
111
+ </highlight>
112
+
113
+ If there is no line feed char in code, it will output an inline code element:<highlight>puts "Inline"</highlight>
114
+ ```
115
+
116
+ ## Customation
117
+
118
+
119
+ ### Concepts:
120
+
121
+ 1. Post:`PlainSite::Data::Post`
122
+
123
+ Plain text file under `_src/data/`,represents one post.
124
+
125
+ 2. Category:`PlainSite::Data::Category`
126
+
127
+ Directory under `_src/data/`.
128
+
129
+ 3. Template
130
+
131
+ ERB template files Under `_src/templates/` directory.
132
+
133
+ 4. Routes
134
+
135
+ Ruby script at ```_src/routes.rb```.
136
+
137
+
138
+ **PlainSite will ignore Post、Template files or Category directories which prefix with underscore.**
139
+
140
+
141
+ ### Post and Category
142
+
143
+ Files under site's `_src/data/` directory represent Post:
144
+ ```
145
+ _src/data/2011-02-28-hello-world.md
146
+ ```
147
+ The `2011-02-28` is post's created date(optional);`hello-world` is post's slug(required).It's not allowed that two post files under the same category directory have the same slug;The `.md` ,viz. extname,represents Post's content type(PlainSite only support Markdown and HTML two content types,corresponding extnames are `md` and `html`.
148
+
149
+ Post file content must starts with [YAML-Front format header](http://jekyllrb.com/docs/frontmatter/),and at least contains a `title` property.
150
+
151
+ The Post file's path relative to `_src/data` represents its Category.You can use directory as category to organize posts.For example,here are two categories:`programming` and `essays`:
152
+ ```
153
+ _src/data/programming/2011-02-28-hello-world.md
154
+ _src/data/essays/2013-04-22-life-is-a-game.md
155
+ ```
156
+
157
+ Category.data_id is the path relative to `_src/data`.
158
+
159
+ Post.data_id equals `Post.category.data_id + "/" + Post.slug` .
160
+
161
+ You can put an `_meta.yml` file under Category's directory to custom its attributes,such as `display_name`:
162
+ Here is an example file at `_src/data/programming/_meta.yml`:
163
+ ```yaml
164
+ display_name: ProgrammingLife
165
+ ```
166
+
167
+ All properties specified in post's YAML header can be accessed via Post object directly.
168
+
169
+
170
+ ## Routes and Templates
171
+ File `_src/routes.rb` is used to custom url pattern and all what you want.
172
+ The `_src/routes.rb` file is just a Ruby script that loaded and executed by PlainSite.
173
+ You can use global variable `$site` to access current `PlainSite::Site` instance object.
174
+ Through `$site.data` to get site root category(`_src/data`),`PlainSite::Data::Category` instance object.
175
+ For examples:
176
+
177
+ ```ruby
178
+ # coding:utf-8
179
+
180
+ $site.route(
181
+ # url_pattern specify the output page's urlpath(relative to site root)
182
+ url_pattern: 'index.html',
183
+
184
+ # template file path relative to `_src/templates/`
185
+ template: 'index.html',
186
+
187
+ # The 'data' will be sent to template to render.
188
+ # If data is Array/PostList object, It will render each item with template into seperated pages.
189
+ # ERB template's context is which 'data' property specified,
190
+ # ERB code can access its key or method directly,
191
+ # e.g. here 'index.html' template's erb code can directly use site and demo variables
192
+ data: {site: $site, demo:123},
193
+ build_anyway: true # Force build this route every time.
194
+ )
195
+
196
+ $site.route( # Generate single post page
197
+ url_pattern: 'about.html',
198
+ data: $site.data / :about , # Retrieve the Post which data_id is 'about'
199
+ template: 'post.html'
200
+ )
201
+
202
+ $site.route( # Generate posts under essays category
203
+ # ur_pattern: '{date.year}/{date.month}/{date.day}/{slug}.html',
204
+ url_pattern: '{data_id}.html', # url_pattern support variable replacement
205
+ # which is Post's property
206
+ data: 'essays/*', # Get all posts under 'essays',return PlainSite::Data::PostList instance
207
+ template: 'post.html'
208
+ )
209
+
210
+ $site.route(
211
+ url_pattern: 'programming/{slug}.html',
212
+ data: $site.data / :programming / :*, # synonym of 'programming/*'
213
+ template: 'post.html'
214
+ )
215
+
216
+ # $site.data.subs are categories under '_src/data',return Category[]
217
+ $site.data.subs.each do |category|
218
+ $site.route(
219
+ url_pattern: "#{category.name}/{slug}.html",
220
+ # category.posts/5 means category.paginate(page_size:5),return PostListPage[]
221
+ data: category.posts/5 , # category.posts is same as 'category / :* '
222
+ template: 'list.html'
223
+ )
224
+ end
225
+
226
+ ```
227
+
228
+
229
+ Template system supports layout,specified in its YAML Header:
230
+ ```erb
231
+ ---
232
+ layout: base.html # file path relative to self
233
+ ---
234
+ <% content_for :page_title do %>
235
+ <%=title%> - <%=site.name %>
236
+ <% end %>
237
+ <% content_for :page_content do %>
238
+ <h1><%=title%></h1>
239
+ <p>Date:<%=date%></p>
240
+ <%=content%>
241
+ <hr />
242
+
243
+ Use site.url_for to get url which affected by 'plainsite build --local' and resulted in relative url.
244
+ <%=site.url_for 'essays/hello' %>
245
+
246
+ Also support includes.
247
+ <%=include 'footer.html' %>
248
+ <% end %>
249
+ ```
250
+
251
+ The `base.html` contents:
252
+
253
+ ```erb
254
+ <html>
255
+ <head>
256
+ <title><%=yield :page_title%></title>
257
+ </head>
258
+ <body>
259
+ <%=yield :page_content%>
260
+ </body>
261
+ </html>
262
+ ```
263
+
264
+ ## More
265
+
266
+ 1. Run `gem server` to read PlainSite rdoc.
267
+ 2. Read the source code.
268
+
269
+ ## Sites using PlainSite
270
+
271
+ <span style="font-size:larger">Jex's Blog: <a href="https://jex.im/">https://jex.im/</a></span>
272
+
273
+
274
+
275
+
276
+
@@ -0,0 +1,34 @@
1
+ # coding:utf-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rdoc'
5
+ require 'PlainSite'
6
+
7
+ task :default => [:list]
8
+
9
+ desc 'List available tasks'
10
+ task :list do
11
+ sh 'rake -T'
12
+ end
13
+
14
+ desc 'Run irb'
15
+ task :irb do
16
+ sh 'irb -rubygems -I"lib:test"'
17
+ end
18
+
19
+
20
+
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'test'
23
+ test.pattern = 'test/*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ require 'rdoc/task'
28
+ Rake::RDocTask.new do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = "PlainSite v#{PlainSite::VERSION}"
31
+ rdoc.rdoc_files.include('README*')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
34
+
@@ -0,0 +1,6 @@
1
+ theme: jekyll-theme-cayman
2
+
3
+ exclude:
4
+ - lib/PlainSite/_scaffold/
5
+ - test/fixtures/
6
+
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # coding:utf-8
3
+ file=File.realpath __FILE__
4
+ BIN_FILE=File.basename(file)
5
+ $:.unshift File.join(File.dirname(file), *%w{ .. lib })
6
+
7
+ require 'commander/import'
8
+ require 'PlainSite'
9
+ require 'PlainSite/Commands'
10
+
11
+ program :name, 'PlainSite'
12
+ program :version, PlainSite::VERSION
13
+ program :description, 'PlainSite - simple static site generator.'
14
+ default_command :help
15
+
16
+ global_option '-r','--root [DIR]', 'Site root directory (defaults to ./)'
17
+
18
+ command :init do |c|
19
+ c.syntax = BIN_FILE+' init [options]'
20
+ c.summary = 'Init site scaffold.'
21
+ c.description = 'Init site scaffold,create a _site directory structure and place some examples.'
22
+ c.example 'Init new site /tmp/site1', 'init -r /tmp/site1'
23
+ c.option '--override', 'Override existing files (defaults to false)'
24
+ c.action do |args, options|
25
+ PlainSite::Commands.run :init,args,options
26
+ end
27
+ end
28
+
29
+
30
+ command :build do |c|
31
+ c.syntax = BIN_FILE+' build [options] [includes]'
32
+ c.summary = 'Generate static pages.'
33
+ c.description = 'Generate html pages.
34
+ Default it will read git status and only generate updated posts and templates\' corresponding pages.
35
+ If you want to generate specified files.Pass posts or templates file path as includes arguments.'
36
+ c.option '-d', '--dest [DIR]', 'Destination directory (defaults same as root)'
37
+ c.option '-a', '--all', 'Force regenerate all pages (default is false,only generate updated pages)'
38
+ c.option '-l','--local', 'Generate relative url.So you can view you site without web server.'
39
+ c.action do |args, options|
40
+ PlainSite::Commands.run :build,args,options
41
+ end
42
+ end
43
+
44
+ command :serve do |c|
45
+ c.syntax = BIN_FILE+' serve [options]'
46
+ c.summary = 'Run a preview web server.'
47
+ c.description = 'Run a preview web server on specified host and port'
48
+ c.option '--host [HOST]', 'Server host,defaults to 127.0.0.1'
49
+ c.option '-p', '--port [PORT]', 'Server port,default is 1990'
50
+ c.action do |args, options|
51
+ PlainSite::Commands.run :serve,args,options
52
+ end
53
+ end
54
+
55
+ command :newpost do |c|
56
+ c.syntax = BIN_FILE+' newpost [data_id] [title]'
57
+ c.summary = 'Create new post.'
58
+ c.description = <<DESC
59
+ The data_id is post's category/slug,created post file's date is today's date,if extension name not specified,default is '.md'.
60
+ DESC
61
+
62
+ c.example "Create new post file '_site/essay/life-is-a-game.md'", 'newpost essay/life-is-a-game'
63
+
64
+ c.action do |args, options|
65
+ PlainSite::Commands.run :newpost,args,options
66
+ end
67
+ end
68
+
69
+ command :clean do |c|
70
+ c.syntax = BIN_FILE+' clean'
71
+ c.summary = 'Clean isolated files.'
72
+ c.description = 'This command is danger.It will delete isolated files that neither copied from `_src/assets/` nor generated by `_src/routes.rb`.You must put all static site files under `_src/assets/`.'
73
+ c.action do |args, options|
74
+ PlainSite::Commands.run :clean,args,options
75
+ end
76
+ end