write_down 0.0.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -21
- data/.travis.yml +4 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +17 -18
- data/README.md +20 -8
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/write_down +3 -0
- data/lib/write_down/converter/base.rb +18 -0
- data/lib/write_down/converter/markdown.rb +18 -0
- data/lib/write_down/converter/org.rb +18 -0
- data/lib/write_down/erb/container.erb +19 -0
- data/lib/write_down/erb/essay.erb +5 -0
- data/lib/write_down/erb/layout.erb +64 -0
- data/lib/write_down/erb/page.erb +4 -0
- data/lib/write_down/erb/post.erb +5 -0
- data/lib/write_down/erb/slide.erb +79 -0
- data/lib/write_down/model/asset.rb +36 -0
- data/lib/write_down/model/base.rb +63 -0
- data/lib/write_down/model/container.rb +35 -0
- data/lib/write_down/model/essay.rb +35 -0
- data/lib/write_down/model/layout.rb +75 -0
- data/lib/write_down/model/page.rb +47 -0
- data/lib/write_down/model/post.rb +47 -0
- data/lib/write_down/model/slide.rb +27 -0
- data/lib/write_down/utils/qiniu_sync.rb +23 -0
- data/lib/write_down/version.rb +1 -1
- data/lib/write_down.rb +13 -33
- data/write_down.gemspec +23 -12
- metadata +54 -91
- data/bin/write_down +0 -43
- data/lib/write_down/article.rb +0 -64
- data/lib/write_down/configuration.rb +0 -6
- data/lib/write_down/converter.rb +0 -8
- data/lib/write_down/page.rb +0 -6
- data/lib/write_down/series.rb +0 -10
- data/lib/write_down/site.rb +0 -10
- data/lib/write_down/template.rb +0 -20
- data/template/emacs/404.html +0 -157
- data/template/emacs/CHANGELOG.md +0 -133
- data/template/emacs/CONTRIBUTING.md +0 -154
- data/template/emacs/LICENSE.md +0 -19
- data/template/emacs/README.md +0 -1
- data/template/emacs/apple-touch-icon-precomposed.png +0 -0
- data/template/emacs/crossdomain.xml +0 -15
- data/template/emacs/css/custom.css +0 -18
- data/template/emacs/css/main.css +0 -304
- data/template/emacs/css/normalize.css +0 -527
- data/template/emacs/favicon.ico +0 -0
- data/template/emacs/humans.txt +0 -15
- data/template/emacs/img/.gitignore +0 -0
- data/template/emacs/index.html +0 -62
- data/template/emacs/js/main.js +0 -1
- data/template/emacs/js/plugins.js +0 -24
- data/template/emacs/js/vendor/jquery-1.10.2.min.js +0 -6
- data/template/emacs/js/vendor/modernizr-2.6.2.min.js +0 -4
- data/template/emacs/post.html +0 -80
- data/template/emacs/robots.txt +0 -3
- data/template/simple/404.html +0 -157
- data/template/simple/CNAME +0 -1
- data/template/simple/README.md +0 -1
- data/template/simple/_disqus.mustache +0 -19
- data/template/simple/_footer.mustache +0 -28
- data/template/simple/_header.mustache +0 -38
- data/template/simple/apple-touch-icon-precomposed.png +0 -0
- data/template/simple/crossdomain.xml +0 -15
- data/template/simple/css/layout.css +0 -72
- data/template/simple/css/main.css +0 -304
- data/template/simple/css/normalize.css +0 -527
- data/template/simple/favicon.ico +0 -0
- data/template/simple/humans.txt +0 -15
- data/template/simple/img/.gitignore +0 -0
- data/template/simple/index.html +0 -12
- data/template/simple/js/main.js +0 -1
- data/template/simple/js/plugins.js +0 -24
- data/template/simple/js/vendor/jquery-1.10.2.min.js +0 -6
- data/template/simple/js/vendor/modernizr-2.6.2.min.js +0 -4
- data/template/simple/post.html +0 -9
- data/template/simple/robots.txt +0 -3
- data/theme/ghost/assets/css/screen.css +0 -911
- data/theme/ghost/index.html +0 -75
- data/theme/ghost/post.html +0 -112
- data/theme/html5-boilerplate/.gitattributes +0 -1
- data/theme/html5-boilerplate/.gitignore +0 -2
- data/theme/html5-boilerplate/.htaccess +0 -551
- data/theme/html5-boilerplate/404.html +0 -157
- data/theme/html5-boilerplate/CHANGELOG.md +0 -133
- data/theme/html5-boilerplate/CONTRIBUTING.md +0 -154
- data/theme/html5-boilerplate/LICENSE.md +0 -19
- data/theme/html5-boilerplate/README.md +0 -61
- data/theme/html5-boilerplate/apple-touch-icon-precomposed.png +0 -0
- data/theme/html5-boilerplate/crossdomain.xml +0 -15
- data/theme/html5-boilerplate/css/main.css +0 -297
- data/theme/html5-boilerplate/css/normalize.css +0 -527
- data/theme/html5-boilerplate/favicon.ico +0 -0
- data/theme/html5-boilerplate/humans.txt +0 -15
- data/theme/html5-boilerplate/img/.gitignore +0 -0
- data/theme/html5-boilerplate/index.html +0 -91
- data/theme/html5-boilerplate/js/main.js +0 -1
- data/theme/html5-boilerplate/js/plugins.js +0 -24
- data/theme/html5-boilerplate/js/vendor/jquery-1.10.2.min.js +0 -6
- data/theme/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js +0 -4
- data/theme/html5-boilerplate/post.html +0 -70
- data/theme/html5-boilerplate/robots.txt +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 371ba9509dee381bd125dddb8b5e067363eaef64
|
4
|
+
data.tar.gz: db43ebedc42a7f46a4320069bd5a72c508e97a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49cf6a36dff404c7528d21fc75dae9bb6c93309b713f33d089e6c699085ffc5340e6807d49c097e4af17aed52f8c61cd3f52e04439b84a3c2fddaeb6b6022739
|
7
|
+
data.tar.gz: e58978c63dab9bef2fcbab9a45fba7cde34c439daa516ae5132fe8323fad7841ca84f55ceed1906c112b65bc015213704ca53cd10ad979b5c14b42771af9225d
|
data/.gitignore
CHANGED
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
.rvmrc
|
19
|
-
.ruby-version
|
20
|
-
.ruby-gemset
|
21
|
-
*.sh
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 马陆骋
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# WriteDown
|
2
2
|
|
3
|
-
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/write_down`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'write_down'
|
13
|
+
```
|
10
14
|
|
11
15
|
And then execute:
|
12
16
|
|
@@ -18,12 +22,20 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec write_down` to use the gem in this directory, ignoring other installed copies of this gem.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
32
|
|
23
33
|
## Contributing
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/write_down.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "write_down"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/write_down
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'pandoc-ruby'
|
2
|
+
|
3
|
+
module WriteDown
|
4
|
+
module Converter
|
5
|
+
# 基类, 定义了一些接口
|
6
|
+
class Markdown < Base
|
7
|
+
|
8
|
+
def initialize(model)
|
9
|
+
@content = model.content
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
PandocRuby.convert(@content, { f: :markdown, to: :html5}, 'no-highlight').to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'pandoc-ruby'
|
2
|
+
|
3
|
+
module WriteDown
|
4
|
+
module Converter
|
5
|
+
# 基类, 定义了一些接口
|
6
|
+
class Org < Base
|
7
|
+
|
8
|
+
def initialize(model)
|
9
|
+
@content = model.content
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
PandocRuby.convert(@content, { f: :org, to: :html5}, 'no-highlight')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!-- 首页的模板 -->
|
2
|
+
|
3
|
+
<h1>
|
4
|
+
<a href="/">编程青年</a>
|
5
|
+
</h1>
|
6
|
+
<section itemscope="" itemtype="http://schema.org/Blog">
|
7
|
+
<% items.each do |item| %>
|
8
|
+
<% unless item.draft %>
|
9
|
+
<article class="blog-article" itemscope="" itemtype="http://schema.org/BlogPosting">
|
10
|
+
<h2 class="blog-listing-title" itemprop="name">
|
11
|
+
<a href="/<%= item.link_to %>" itemprop="url">
|
12
|
+
<%= item.title %>
|
13
|
+
</a>
|
14
|
+
</h2>
|
15
|
+
<time class="blog-article-publishdate blog-listing-publishdate" content="<%= item.created_at %>" datetime="<%= item.created_at %>" itemprop="datePublished" pubdate=""><%= item.created_at %></time>
|
16
|
+
</article>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
</section>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="zh-cmn-Hans">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title><%= title %></title>
|
6
|
+
<meta name="description" content="编程青年的博客,记录着软件开发中的点点滴滴">
|
7
|
+
<meta name="copyright" content="Ma Lucheng 2014-2015">
|
8
|
+
<meta name="generator" content="pandoc">
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
10
|
+
|
11
|
+
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
12
|
+
<link rel="icon" href="/favicon.ico" type="image/x-icon">
|
13
|
+
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
|
14
|
+
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
|
15
|
+
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
|
16
|
+
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
|
17
|
+
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
|
18
|
+
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
|
19
|
+
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
|
20
|
+
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
|
21
|
+
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
|
22
|
+
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
|
23
|
+
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
24
|
+
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
|
25
|
+
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
26
|
+
<link rel="manifest" href="/manifest.json">
|
27
|
+
<meta name="msapplication-TileColor" content="#ffffff">
|
28
|
+
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
|
29
|
+
<meta name="theme-color" content="#ffffff">
|
30
|
+
|
31
|
+
<link href="/css/app.css<%= assets_version %>" rel="stylesheet">
|
32
|
+
</head>
|
33
|
+
|
34
|
+
<body>
|
35
|
+
<main id="content" role="main" class="row-wrapper">
|
36
|
+
<%= yield %>
|
37
|
+
</main> <!-- 网页主体 -->
|
38
|
+
|
39
|
+
<footer role="contentinfo" class="page-footer">
|
40
|
+
<p>© Ma Lucheng 2014-2015 — All content is licensed under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons BY-SA 3.0</a>.</p>
|
41
|
+
<nav>
|
42
|
+
<ul class="navigation-footer">
|
43
|
+
<% menus.each do |menu| %>
|
44
|
+
<li class="<%= menu[0] %>">
|
45
|
+
<a href="<%= menu[1] %>"><%= menu[0] %></a>
|
46
|
+
</li>
|
47
|
+
<% end %>
|
48
|
+
</ul>
|
49
|
+
<!-- <ul class="navigation-footer">
|
50
|
+
<% friend_links.each do |link| %>
|
51
|
+
<li>
|
52
|
+
<a href="<%= link[1] %>"><%= link[0] %></a>
|
53
|
+
</li>
|
54
|
+
<% end %>
|
55
|
+
</ul> -->
|
56
|
+
</nav>
|
57
|
+
<img src="/assets/images/home/zhifuma.png" />
|
58
|
+
</footer><!-- 页脚 -->
|
59
|
+
|
60
|
+
<script src="/js/vendor.js<%= assets_version %>"></script>
|
61
|
+
<script src="/js/app.js<%= assets_version %>"></script>
|
62
|
+
<script>require('main').init();</script>
|
63
|
+
</body>
|
64
|
+
</html>
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>reveal.js - The HTML Presentation Framework</title>
|
6
|
+
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
|
7
|
+
<meta name="author" content="Hakim El Hattab">
|
8
|
+
<meta name="apple-mobile-web-app-capable" content="yes" />
|
9
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
|
11
|
+
|
12
|
+
<link rel="stylesheet" href="<%=prefix%>css/reveal.css">
|
13
|
+
<link rel="stylesheet" href="<%=prefix%>css/theme/black.css" id="theme">
|
14
|
+
<!-- Code syntax highlighting -->
|
15
|
+
<link rel="stylesheet" href="<%=prefix%>lib/css/zenburn.css">
|
16
|
+
|
17
|
+
<!-- Printing and PDF exports -->
|
18
|
+
<script>
|
19
|
+
var link = document.createElement( 'link' );
|
20
|
+
link.rel = 'stylesheet';
|
21
|
+
link.type = 'text/css';
|
22
|
+
link.href = window.location.search.match( /print-pdf/gi ) ? '<%=prefix%>css/print/pdf.css' : '<%=prefix%>css/print/paper.css';
|
23
|
+
document.getElementsByTagName( 'head' )[0].appendChild( link );
|
24
|
+
</script>
|
25
|
+
|
26
|
+
<!--[if lt IE 9]>
|
27
|
+
<script src="<%=prefix%>lib/js/html5shiv.js"></script>
|
28
|
+
<![endif]-->
|
29
|
+
</head>
|
30
|
+
|
31
|
+
<body>
|
32
|
+
|
33
|
+
<div class="reveal">
|
34
|
+
|
35
|
+
<!-- Any section element inside of this container is displayed as a slide -->
|
36
|
+
<div class="slides" id="main-container">
|
37
|
+
<%= body %>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<!-- hook html struct -->
|
43
|
+
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
|
44
|
+
<script src="<%=prefix%>org-adapter.js"></script>
|
45
|
+
<script>
|
46
|
+
// for #main-container
|
47
|
+
revealjs_adapter();
|
48
|
+
</script>
|
49
|
+
|
50
|
+
<script src="<%=prefix%>lib/js/head.min.js"></script>
|
51
|
+
<script src="<%=prefix%>js/reveal.js"></script>
|
52
|
+
|
53
|
+
<script>
|
54
|
+
|
55
|
+
// Full list of configuration options available at:
|
56
|
+
// https://github.com/hakimel/reveal.js#configuration
|
57
|
+
Reveal.initialize({
|
58
|
+
controls: true,
|
59
|
+
progress: true,
|
60
|
+
history: true,
|
61
|
+
center: true,
|
62
|
+
|
63
|
+
transition: 'slide', // none/fade/slide/convex/concave/zoom
|
64
|
+
|
65
|
+
// Optional reveal.js plugins
|
66
|
+
dependencies: [
|
67
|
+
{ src: '<%=prefix%>lib/js/classList.js', condition: function() { return !document.body.classList; } },
|
68
|
+
{ src: '<%=prefix%>plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
69
|
+
{ src: '<%=prefix%>plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
70
|
+
{ src: '<%=prefix%>plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
|
71
|
+
{ src: '<%=prefix%>plugin/zoom-js/zoom.js', async: true },
|
72
|
+
{ src: '<%=prefix%>plugin/notes/notes.js', async: true }
|
73
|
+
]
|
74
|
+
});
|
75
|
+
|
76
|
+
</script>
|
77
|
+
|
78
|
+
</body>
|
79
|
+
</html>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module WriteDown
|
5
|
+
module Model
|
6
|
+
# 代表 js, css, 图片等资产
|
7
|
+
class Asset
|
8
|
+
|
9
|
+
def initialize(source_file, target_file = nil, option = {})
|
10
|
+
@source_file = source_file
|
11
|
+
@base_name = source_file.split("/").last.split(".").first
|
12
|
+
@ext_name = source_file.split("/").last.split(".").last
|
13
|
+
if target_file
|
14
|
+
@target_file = target_file
|
15
|
+
else
|
16
|
+
@target_file = "dist/#{target_file}"
|
17
|
+
end
|
18
|
+
@option = option
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
hash_file_name = "#{@base_name}-#{Time.now.to_s}.#{@ext_name}"
|
23
|
+
output = Pathname.new("#{@target_file}")
|
24
|
+
output.dirname.mkpath
|
25
|
+
@final_path = @source_file.gsub("#{@base_name}.#{@ext_name}", hash_file_name)
|
26
|
+
`cp #{source_file} #{@final_path}`
|
27
|
+
end
|
28
|
+
|
29
|
+
def sync
|
30
|
+
# TODO 使用配置文件传入七牛的 key 和 secret
|
31
|
+
QiniuSync.new("", "").sync @final_path #TODO @final_path 放在 initialize 里
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'front_matter_parser'
|
2
|
+
|
3
|
+
module WriteDown
|
4
|
+
module Model
|
5
|
+
# 基类, 定义了一些接口
|
6
|
+
class Base
|
7
|
+
|
8
|
+
attr_accessor :draft
|
9
|
+
attr_accessor :created_at
|
10
|
+
attr_accessor :link_to
|
11
|
+
attr_accessor :content
|
12
|
+
|
13
|
+
def initialize(source_file, target_file = nil)
|
14
|
+
@source_file = source_file
|
15
|
+
@base_name = source_file.split("/").last.split(".").first
|
16
|
+
@ext_name = source_file.split("/").last.split(".").last
|
17
|
+
meta_file = File.join("source", "meta", "#{@base_name}.json")
|
18
|
+
@meta = File.exist?(meta_file) ? JSON.parse(File.open(meta_file).read) : read_from_head
|
19
|
+
@draft = @meta['draft'].to_s == "true" ? true : false
|
20
|
+
@created_at = @meta['date'] || File.open(@source_file).ctime #.iso8610
|
21
|
+
@content = File.open(@source_file).read
|
22
|
+
if target_file
|
23
|
+
@target_file = target_file
|
24
|
+
elsif @base_name.end_with?"index"
|
25
|
+
@target_file = "dist/#{@base_name}.html"
|
26
|
+
else
|
27
|
+
@target_file = "dist/#{@base_name}/index.html"
|
28
|
+
end
|
29
|
+
@link_to = @target_file.gsub("index.html", "")
|
30
|
+
end
|
31
|
+
|
32
|
+
def converter
|
33
|
+
if @ext_name == "md" || @ext_name == "markdown"
|
34
|
+
return WriteDown::Converter::Markdown
|
35
|
+
end
|
36
|
+
if @ext_name == "org"
|
37
|
+
return WriteDown::Converter::Org
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def body
|
42
|
+
# binding.pry
|
43
|
+
converter.new(self).render
|
44
|
+
end
|
45
|
+
|
46
|
+
# 接口 render
|
47
|
+
# 用于找到自己的 erb 然后生成 html 字符串
|
48
|
+
def render
|
49
|
+
raise "Not impl..."
|
50
|
+
end
|
51
|
+
|
52
|
+
# 接口 build
|
53
|
+
# 用于把自己序列化到磁盘上
|
54
|
+
def build
|
55
|
+
raise "Not impl..."
|
56
|
+
end
|
57
|
+
|
58
|
+
def read_from_head
|
59
|
+
FrontMatterParser.parse_file(@source_file).front_matter
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'front_matter_parser'
|
2
|
+
|
3
|
+
|
4
|
+
module WriteDown
|
5
|
+
module Model
|
6
|
+
|
7
|
+
# 基类, 定义了一些接口
|
8
|
+
class Container
|
9
|
+
|
10
|
+
attr_accessor :items
|
11
|
+
|
12
|
+
def initialize(target_file, options = {})
|
13
|
+
@target_file = target_file
|
14
|
+
@items = []
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
template_file = File.expand_path('../../erb/container.erb', __FILE__)
|
20
|
+
template = File.read(template_file)
|
21
|
+
html_string = ERB.new(template).result(binding)
|
22
|
+
end
|
23
|
+
|
24
|
+
def build
|
25
|
+
Layout.new(self, @target_file, @options).render
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def append(item)
|
30
|
+
@items << item
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'pathname'
|
3
|
+
require 'date'
|
4
|
+
require 'json'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
module WriteDown
|
8
|
+
module Model
|
9
|
+
# 代表散文
|
10
|
+
class Essay < Base
|
11
|
+
|
12
|
+
def render
|
13
|
+
template_file = File.expand_path('../../erb/essay.erb', __FILE__)
|
14
|
+
template = File.read(template_file)
|
15
|
+
html_string = ERB.new(template).result(binding)
|
16
|
+
html_string
|
17
|
+
end
|
18
|
+
|
19
|
+
def build
|
20
|
+
Layout.new(self, @target_file).render
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# 概览
|
25
|
+
def summary
|
26
|
+
@meta['summary']
|
27
|
+
end
|
28
|
+
|
29
|
+
# 标题
|
30
|
+
def title
|
31
|
+
@meta['title']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|