docwu 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/docwu/config.rb CHANGED
@@ -53,6 +53,10 @@ module Docwu
53
53
  @deploy_path ||= ("#{self.workspace}/_deploy")
54
54
  end
55
55
 
56
+ def tmp_path
57
+ @tmp_path ||= ("#{self.workspace}/_tmp")
58
+ end
59
+
56
60
  end
57
61
  end
58
62
 
data/lib/docwu/folder.rb CHANGED
@@ -22,7 +22,7 @@ module Docwu
22
22
 
23
23
  @name = ::Docwu::Utils.filename(@src)
24
24
 
25
- @dest = "#{self.worker.deploy_path}/#{self.path}"
25
+ @dest = "#{self.worker.tmp_deploy_path}/#{self.path}"
26
26
  @index_dest = "#{self.dest}/index.html"
27
27
  # -------------------------------------
28
28
 
data/lib/docwu/post.rb CHANGED
@@ -53,7 +53,7 @@ module Docwu
53
53
 
54
54
  @path = "#{_filename_extless}.#{_extend_name}"
55
55
  @url = "/#{@path}"
56
- @dest = "#{self.worker.deploy_path}/#{self.path}"
56
+ @dest = "#{self.worker.tmp_deploy_path}/#{self.path}"
57
57
 
58
58
  @file_name = ::Docwu::Utils.filename(_filename_extless)
59
59
 
data/lib/docwu/render.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'redcarpet'
3
3
  require 'coderay'
4
4
  require "nokogiri"
5
+ # require "pdfkit"
5
6
 
6
7
  module Docwu
7
8
  class Render
@@ -11,6 +12,12 @@ module Docwu
11
12
  end
12
13
  end
13
14
 
15
+ # 生成pdf
16
+ # https://github.com/pdfkit/PDFKit
17
+ # def generate_pdf options={}
18
+ # kit = ::PDFKit.new(::File.new(options[:dest]))
19
+ # end
20
+
14
21
  #
15
22
  # usage:
16
23
  # ::Docwu::Render.generate(
data/lib/docwu/topic.rb CHANGED
@@ -17,7 +17,7 @@ module Docwu
17
17
  _filename_extless = ::Docwu::Utils.filename_extless(self.path)
18
18
 
19
19
  @url = "/#{@path}"
20
- @dest = "#{self.worker.deploy_path}/#{self.path}"
20
+ @dest = "#{self.worker.tmp_deploy_path}/#{self.path}"
21
21
 
22
22
  @file_name = ::Docwu::Utils.filename(_filename_extless)
23
23
 
data/lib/docwu/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Docwu
3
- VERSION = "0.0.14"
3
+ VERSION = "0.0.15"
4
4
  end
data/lib/docwu/worker.rb CHANGED
@@ -3,10 +3,11 @@ require 'date'
3
3
  module Docwu
4
4
  class Worker
5
5
 
6
- attr_reader :layouts, :data, :deploy_path, :folders, :topics
6
+ attr_reader :layouts, :data, :deploy_path, :folders, :topics, :tmp_path
7
7
 
8
8
  def initialize
9
9
  @deploy_path = ::Docwu.config.deploy_path # 部署路径
10
+ @tmp_path = ::Docwu.config.tmp_path
10
11
 
11
12
  @data = {
12
13
  'worker' => {
@@ -69,24 +70,37 @@ module Docwu
69
70
  # 输出:
70
71
  # TODO: 先生成临时目录, 然后 -> deploy
71
72
  def generate
72
- # 删除要输出的路径
73
- FileUtils.rm_rf(self.deploy_path)
74
- FileUtils.mkdir_p(self.deploy_path)
73
+ begin
74
+ # 删除要输出的路径
75
+ FileUtils.mkdir_p(self.tmp_deploy_path)
75
76
 
76
- ::Docwu::Utils.cp_r("#{plain_path('/assets')}", "#{self.deploy_path}/assets")
77
+ ::Docwu::Utils.cp_r("#{plain_path('/assets')}", "#{self.tmp_deploy_path}/assets")
77
78
 
78
- # 复制静态文件里去
79
- ::Docwu::Utils.cp_r("#{plain_path('/static')}", "#{self.deploy_path}/static")
79
+ # 复制静态文件里去
80
+ ::Docwu::Utils.cp_r("#{plain_path('/static')}", "#{self.tmp_deploy_path}/static")
80
81
 
81
- self.folders.each do |folder|
82
- folder.generate
83
- end
82
+ self.folders.each do |folder|
83
+ folder.generate
84
+ end
85
+
86
+ self.topics.each do |topic|
87
+ topic.generate
88
+ end
84
89
 
85
- self.topics.each do |topic|
86
- topic.generate
90
+ rescue Exception => exception
91
+ FileUtils.rm_rf(self.tmp_deploy_path)
92
+ raise "#{exception}"
93
+ else
94
+ FileUtils.rm_rf(self.deploy_path)
95
+ FileUtils.mv(self.tmp_deploy_path, self.deploy_path)
96
+ ensure
87
97
  end
88
98
  end
89
99
 
100
+ def tmp_deploy_path
101
+ @tmp_deploy_path ||= "#{self.tmp_path}/_deploy/#{Time.now.to_i}"
102
+ end
103
+
90
104
  def plain_path(path)
91
105
  "#{::Docwu.config.workspace}#{path}"
92
106
  end
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'docwu', '0.0.14'
3
+ gem 'docwu', '0.0.15'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docwu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-03 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  segments:
156
156
  - 0
157
- hash: 1246911035850330828
157
+ hash: -2459986803963416847
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  none: false
160
160
  requirements:
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  segments:
165
165
  - 0
166
- hash: 1246911035850330828
166
+ hash: -2459986803963416847
167
167
  requirements: []
168
168
  rubyforge_project:
169
169
  rubygems_version: 1.8.25