diary 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{diary}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robin Clart"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/diary/cli.rb",
30
30
  "lib/diary/draft.rb",
31
31
  "lib/diary/item.rb",
32
+ "lib/diary/message.rb",
32
33
  "lib/diary/page.rb",
33
34
  "lib/diary/post.rb",
34
35
  "lib/diary/site.rb",
@@ -13,35 +13,17 @@ require 'ostruct'
13
13
  require 'liquid'
14
14
  require 'bluecloth'
15
15
 
16
- module Diary
17
- module Message
18
- # Red
19
- Error = " \e[1;31merror\e[0m"
20
- Skip = " \e[1;31mskip\e[0m"
21
-
22
- # Green
23
- Published = " \e[1;32mpublished\e[0m"
24
- Created = " \e[1;32mcreated\e[0m"
25
- Updated = " \e[1;32mupdated\e[0m"
26
-
27
- # Yellow
28
- Identical = " \e[1;33midentical\e[0m"
29
- Exist = " \e[1;33mexist\e[0m"
30
-
31
- # Cyan
32
- Invoke = " \e[1;36minvoke\e[0m"
33
- end
34
-
35
- def self.version
36
- File.read(File.expand_path("../../VERSION", __FILE__))
37
- end
38
- end
39
-
40
-
41
16
  # internals
17
+ require 'diary/message'
42
18
  require 'diary/site'
43
19
  require 'diary/template'
44
20
  require 'diary/item'
45
21
  require 'diary/draft'
46
22
  require 'diary/page'
47
23
  require 'diary/post'
24
+
25
+ module Diary
26
+ def self.version
27
+ File.read(File.expand_path("../../VERSION", __FILE__))
28
+ end
29
+ end
@@ -37,7 +37,6 @@ module Diary
37
37
  output_file.puts render
38
38
  output_file.close
39
39
 
40
- puts "#{Invoke} #{template.path}"
41
40
  puts "#{Updated} #{output_file_path}"
42
41
  else
43
42
  puts "#{Identical} #{output_file_path}"
@@ -45,7 +44,7 @@ module Diary
45
44
  end
46
45
 
47
46
  def template
48
- @template ||= Template.lookup(self, options.template)
47
+ Template.lookup(self)
49
48
  end
50
49
 
51
50
  def file
@@ -56,12 +55,8 @@ module Diary
56
55
  file.read.split(/---\n/).slice(-1)
57
56
  end
58
57
 
59
- def options
60
- if ydoc.is_a?(Hash)
61
- @options ||= OpenStruct.new(ydoc)
62
- else
63
- OpenStruct.new
64
- end
58
+ def data
59
+ ydoc.is_a?(Hash) ? OpenStruct.new(ydoc) : OpenStruct.new
65
60
  end
66
61
 
67
62
  def ydoc
@@ -119,7 +114,7 @@ module Diary
119
114
  end
120
115
 
121
116
  def liquidize
122
- Liquid::Template.parse(template.file.read)
117
+ Liquid::Template.parse(template.read)
123
118
  end
124
119
 
125
120
  def markdownize
@@ -0,0 +1,19 @@
1
+ module Diary
2
+ module Message
3
+ # Red
4
+ Error = " \e[1;31merror\e[0m"
5
+ Skip = " \e[1;31mskip\e[0m"
6
+
7
+ # Green
8
+ Published = " \e[1;32mpublished\e[0m"
9
+ Created = " \e[1;32mcreated\e[0m"
10
+ Updated = " \e[1;32mupdated\e[0m"
11
+
12
+ # Yellow
13
+ Identical = " \e[1;33midentical\e[0m"
14
+ Exist = " \e[1;33mexist\e[0m"
15
+
16
+ # Cyan
17
+ Invoke = " \e[1;36minvoke\e[0m"
18
+ end
19
+ end
@@ -1,35 +1,28 @@
1
1
  module Diary
2
2
  class Template
3
- attr_reader :path
4
-
5
- def initialize(path)
6
- @path = path
7
- end
8
-
9
- def file
10
- File.new(@path)
11
- end
3
+ include Message
12
4
 
13
- def self.all
14
- Dir[File.join("templates", "*.html")].map { |t| Template.new(t) }
5
+ def self.lookup(item)
6
+ return file(item.data.template) if exists?(item.data.template)
7
+ return file(item.file_name) if exists?(item.file_name)
8
+ return file(item.class_name.downcase) if exists?(item.class_name.downcase)
9
+ return file("index")
15
10
  end
16
11
 
17
- def self.lookup(page_or_post, template_name = nil)
18
- Template.new resolve_path(page_or_post, template_name)
19
- end
20
-
21
12
  private
22
13
 
23
- def self.resolve_path(page_or_post, template_name)
24
- if template_name and File.exists?("templates/#{template_name}.html")
25
- "templates/#{template_name}.html"
26
- elsif File.exists?("templates/#{page_or_post.slug}.html")
27
- "templates/#{page_or_post.slug}.html"
28
- elsif File.exists?("templates/#{page_or_post.class_name.downcase}.html")
29
- "templates/#{page_or_post.class_name.downcase}.html"
30
- else
31
- 'templates/index.html'
14
+ def self.file(name)
15
+ File.new(resolve(name)).tap do |file|
16
+ puts "#{Invoke} #{file.path}"
32
17
  end
33
18
  end
19
+
20
+ def self.exists?(name)
21
+ File.exists?(resolve(name))
22
+ end
23
+
24
+ def self.resolve(name)
25
+ File.join("templates", "#{name}.html")
26
+ end
34
27
  end
35
28
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robin Clart
@@ -66,6 +66,7 @@ files:
66
66
  - lib/diary/cli.rb
67
67
  - lib/diary/draft.rb
68
68
  - lib/diary/item.rb
69
+ - lib/diary/message.rb
69
70
  - lib/diary/page.rb
70
71
  - lib/diary/post.rb
71
72
  - lib/diary/site.rb