diary 0.2.1 → 0.2.2

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.
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'date'
3
+ require 'time'
3
4
  require 'yaml'
4
5
  require 'ostruct'
5
6
  require 'singleton'
@@ -0,0 +1,15 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def edit(args, options)
5
+ `#{editor} #{const_get(args.shift.capitalize).find(args.first).path}`
6
+ end
7
+
8
+ private
9
+
10
+ def editor
11
+ YAML.load_file("config.yml")["editor"] || "nano"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  module Diary
3
2
  module Item
4
3
  module Creator
@@ -20,24 +19,11 @@ module Diary
20
19
  end
21
20
  end
22
21
 
23
- ACCENTS = {
24
- ['á','à','â','ä','ã'] => 'a',
25
- ['Ã','Ä','Â','À','�?'] => 'A',
26
- ['é','è','ê','ë'] => 'e',
27
- ['Ë','É','È','Ê'] => 'E',
28
- ['í','ì','î','ï'] => 'i',
29
- ['�?','Î','Ì','�?'] => 'I',
30
- ['ó','ò','ô','ö','õ'] => 'o',
31
- ['Õ','Ö','Ô','Ò','Ó'] => 'O',
32
- ['ú','ù','û','ü'] => 'u',
33
- ['Ú','Û','Ù','Ü'] => 'U',
34
- ['ç'] => 'c', ['Ç'] => 'C',
35
- ['ñ'] => 'n', ['Ñ'] => 'N'
36
- }
37
-
38
- def create(title)
39
- slug = slugify(title)
40
- path = resolve_path(slug)
22
+ def create(title_or_path)
23
+ path_fragments = title_or_path.split("/")
24
+ title = path_fragments.pop
25
+ path_fragments << title.parameterize
26
+ path = resolve_path(path_fragments.join("/"))
41
27
 
42
28
  ensure_directories_exists!(path)
43
29
 
@@ -58,18 +44,8 @@ module Diary
58
44
 
59
45
  private
60
46
 
61
- def slugify(str)
62
- ACCENTS.each do |ac,rep|
63
- ac.each do |s|
64
- str = str.gsub(s, rep)
65
- end
66
- end
67
-
68
- str.gsub(/[ ]+/, " ").gsub(/ /, "-").downcase
69
- end
70
-
71
- def resolve_path(slug)
72
- File.join(base_directory, "#{slug}.md")
47
+ def resolve_path(path)
48
+ File.join(base_directory, "#{path}.md")
73
49
  end
74
50
 
75
51
  def ensure_directories_exists!(path)
@@ -8,6 +8,22 @@ module Diary
8
8
  load_data
9
9
  end
10
10
 
11
+ def title
12
+ data.title
13
+ end
14
+
15
+ def author
16
+ data.author
17
+ end
18
+
19
+ def published_at
20
+ Time.parse(data.published_at)
21
+ end
22
+
23
+ def email
24
+ data.email
25
+ end
26
+
11
27
  def reload_data
12
28
  @data = load_data
13
29
  end
@@ -17,21 +33,10 @@ module Diary
17
33
  def load_data
18
34
  if File.exists?(path)
19
35
  @data ||= OpenStruct.new(YAML.load_file(path)).freeze
20
- create_attr_readers_from_data_table!
21
-
22
- @data
23
36
  else
24
37
  nil
25
38
  end
26
39
  end
27
-
28
- def create_attr_readers_from_data_table!
29
- data.instance_variable_get(:@table).tap do |h|
30
- h.each_key do |k|
31
- self.class.send(:define_method, k) { data.send k } unless self.class.method_defined?(k)
32
- end
33
- end
34
- end
35
40
  end
36
41
  end
37
- end
42
+ end
@@ -2,7 +2,7 @@ module Diary
2
2
  module Item
3
3
  module Snippet
4
4
  def snippet(name)
5
- Diary::Snippet.new(name.intern).content
5
+ ERB.new(Diary::Snippet.new(name.intern).content).result(binding)
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,21 @@ module Diary
2
2
  module Item
3
3
  module Url
4
4
  def link(name)
5
- "<a href=\"#{output_path.gsub("public/", "")}\">#{name}</a>"
5
+ "<a href=\"#{website_path}\">#{name}</a>"
6
+ end
7
+
8
+ private
9
+
10
+ def website_path
11
+ output_path.gsub("public/", website_config).gsub("index.html", "")
12
+ end
13
+
14
+ def website_config
15
+ if File.exists?("config.yml")
16
+ YAML.load_file("config.yml")["website"] || "/"
17
+ else
18
+ "/"
19
+ end
6
20
  end
7
21
  end
8
22
  end
@@ -1,7 +1,7 @@
1
1
  class Page < Diary::Item::Base
2
2
  include Diary::Item::Data
3
- include Diary::Item::Url
4
3
  include Diary::Item::Template
5
4
  include Diary::Item::Snippet
6
5
  include Diary::Item::Output
6
+ include Diary::Item::Url
7
7
  end
@@ -1,6 +1,7 @@
1
1
  class Post < Diary::Item::Base
2
2
  include Diary::Item::Data
3
3
  include Diary::Item::Template
4
+ include Diary::Item::Snippet
4
5
  include Diary::Item::Output
5
6
  include Diary::Item::Url
6
7
 
@@ -1,3 +1,3 @@
1
1
  module Diary
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robin Clart
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-05 00:00:00 +01:00
17
+ date: 2011-03-07 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,7 @@ files:
99
99
  - lib/diary/cli.rb
100
100
  - lib/diary/cli/commands.rb
101
101
  - lib/diary/cli/commands/compile.rb
102
+ - lib/diary/cli/commands/edit.rb
102
103
  - lib/diary/cli/commands/init.rb
103
104
  - lib/diary/cli/commands/new_item.rb
104
105
  - lib/diary/cli/commands/server.rb