fngtps-weblog 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/weblog CHANGED
@@ -13,9 +13,10 @@ def usage
13
13
  puts ""
14
14
  puts "Commands:"
15
15
  puts " init: Initialize a directory for use with the weblog tool"
16
- puts " generate: Convert all Markdown source to an HTML file"
16
+ puts " generate: Convert all snippets to pages and generate indices"
17
17
  puts " publish: Move a draft directory into the public directory"
18
18
  puts " info: Print information about the current working directory"
19
+ puts " preview: Convert all snippets in the drafts directory"
19
20
  puts "Options:"
20
21
  puts " -v, --verbose: Print informative messages"
21
22
  end
@@ -40,6 +41,8 @@ when 'publish'
40
41
  Weblog.publish(options, *args[1..-1])
41
42
  when 'info'
42
43
  Weblog.print_info(options)
44
+ when 'preview'
45
+ Weblog.preview(options)
43
46
  when 'help'
44
47
  usage
45
48
  else
@@ -48,6 +48,7 @@ class Weblog
48
48
  unless @path = self.class.find_working_directory(cwd)
49
49
  puts "[!] Please use this tool from somewhere within the working directory"
50
50
  end
51
+ _load_metadata
51
52
  end
52
53
 
53
54
  def git
@@ -58,12 +59,22 @@ class Weblog
58
59
  @options[:verbose]
59
60
  end
60
61
 
62
+ def metadata_filename
63
+ File.join(path, 'config.json')
64
+ end
65
+
66
+ def _load_metadata
67
+ JSON.parse(File.read(metadata_filename)).each do |key, value|
68
+ self.send("#{key}=", value)
69
+ end if File.exist?(metadata_filename)
70
+ end
71
+
61
72
  # --- Attributes
62
73
 
63
- attr_accessor :path
74
+ attr_accessor :title, :path
64
75
 
65
76
  def title
66
- @path.split('/').last.gsub(/[_-]/, ' ').capitalize
77
+ @title || @path.split('/').last.gsub(/[_-]/, ' ').capitalize
67
78
  end
68
79
 
69
80
  def months
@@ -84,6 +95,20 @@ class Weblog
84
95
  end; @posts
85
96
  end
86
97
 
98
+ def drafts
99
+ if @drafts.nil?
100
+ paths = Set.new
101
+ base_path = File.join(@path, 'draft')
102
+ path_length = base_path.split('/').length
103
+ Dir.glob(File.join(base_path, '**/post.*')).each do |file|
104
+ paths << file.split('/')[path_length..-2].join('/')
105
+ end
106
+ @drafts = paths.map do |path|
107
+ Weblog::Post.new(self, path, :draft => true)
108
+ end
109
+ end; @drafts
110
+ end
111
+
87
112
  def size
88
113
  posts.size
89
114
  end
@@ -127,6 +152,10 @@ class Weblog
127
152
  ].join("\n")
128
153
  end
129
154
 
155
+ def preview
156
+ drafts.each { |draft| draft.generate }
157
+ end
158
+
130
159
  def self.init(options)
131
160
  DIRECTORIES.each { |path| FileUtils.mkdir_p(path) }
132
161
  unless File.exist?('templates')
@@ -152,4 +181,10 @@ class Weblog
152
181
  weblog.print_info
153
182
  weblog
154
183
  end
184
+
185
+ def self.preview(options)
186
+ weblog = new(Dir.pwd, options)
187
+ weblog.preview
188
+ weblog
189
+ end
155
190
  end
@@ -2,17 +2,26 @@ class Weblog
2
2
  class Post
3
3
  attr_accessor :path
4
4
 
5
- def initialize(weblog, path)
6
- @weblog = weblog
7
- @path = path
8
- @post = self
5
+ def initialize(weblog, path, options={})
6
+ @weblog = weblog
7
+ @path = path
8
+ @post = self
9
+ @options = options
9
10
  _load_metadata
10
11
  end
11
12
 
12
13
  # --- Metadata
13
14
 
15
+ def draft?
16
+ @options[:draft] == true
17
+ end
18
+
19
+ def public_directory
20
+ draft? ? 'draft' : 'public'
21
+ end
22
+
14
23
  def metadata_filename
15
- File.join(@weblog.path, 'public', @path, 'post.json')
24
+ File.join(@weblog.path, public_directory, @path, 'post.json')
16
25
  end
17
26
 
18
27
  attr_writer :author
@@ -102,19 +111,19 @@ class Weblog
102
111
  end
103
112
 
104
113
  def stylesheets
105
- Dir.glob(File.join(@weblog.path, 'public', path, '*.css')).map do |path|
106
- File.basename(path)
114
+ Dir.glob(File.join(@weblog.path, public_directory, path, '*.css')).map do |stylesheet_path|
115
+ File.join(path, File.basename(stylesheet_path))
107
116
  end
108
117
  end
109
118
 
110
119
  def javascripts
111
- Dir.glob(File.join(@weblog.path, 'public', path, '*.js')).map do |path|
112
- File.basename(path)
120
+ Dir.glob(File.join(@weblog.path, public_directory, path, '*.js')).map do |javascript_path|
121
+ File.join(path, File.basename(javascript_path))
113
122
  end
114
123
  end
115
124
 
116
125
  def snippet
117
- @snippet ||= Snippet.new(@weblog, self, File.join('public', path))
126
+ @snippet ||= Snippet.new(@weblog, self, File.join(public_directory, path))
118
127
  end
119
128
 
120
129
  def title
@@ -140,7 +149,7 @@ class Weblog
140
149
  end
141
150
 
142
151
  def index_filename
143
- File.join(@weblog.path, 'public', @path, 'index.html')
152
+ File.join(@weblog.path, public_directory, @path, 'index.html')
144
153
  end
145
154
 
146
155
  def generate
@@ -25,7 +25,7 @@ class Weblog
25
25
  end
26
26
 
27
27
  def read
28
- @read ||= File.read(filename).split("\n")
28
+ @read ||= File.read(@filename).split("\n")
29
29
  end
30
30
 
31
31
  def title
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fngtps-weblog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Manfred Stienstra
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-18 00:00:00 +01:00
18
+ date: 2010-11-22 00:00:00 +01:00
19
19
  default_executable: weblog
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency