diary 0.1.5 → 0.2.0

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.
data/.gitignore CHANGED
@@ -1,22 +1,3 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- .document
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in diary.gemspec
4
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ diary (0.2.0)
5
+ activesupport (>= 3.0.0)
6
+ bluecloth (>= 2.0.11)
7
+ sinatra (>= 1.1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (3.0.3)
13
+ bluecloth (2.0.11)
14
+ rack (1.2.1)
15
+ sinatra (1.2.0)
16
+ rack (~> 1.1)
17
+ tilt (>= 1.2.2, < 2.0)
18
+ tilt (1.2.2)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activesupport (>= 3.0.0)
25
+ bluecloth (>= 2.0.11)
26
+ bundler (>= 1.0.0.rc.6)
27
+ diary!
28
+ sinatra (>= 1.1.0)
data/Rakefile CHANGED
@@ -1,20 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "diary"
8
- gem.summary = "Dead Simple, Static Blog Generator"
9
-
10
- gem.email = "robin@clart.me"
11
- gem.homepage = "http://github.com/robinclart/diary"
12
- gem.authors = ["Robin Clart"]
13
-
14
- gem.add_dependency('liquid', '>= 2.0.0')
15
- gem.add_dependency('bluecloth', '>= 2.0.7')
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/diary CHANGED
@@ -1,43 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
-
5
2
  require 'diary'
6
- require 'diary/cli'
7
-
8
- options = Diary::CLI.parse(ARGV)
9
- # Diary.config(options)
10
3
 
11
- case ARGV.size
12
- when 1
13
- case ARGV[0]
14
- when "compile"
15
- Diary::Site.compile(options.force)
16
- when "init"
17
- Diary::Site.new(options)
18
- else
19
- puts "Invalid option. Run `diary --help`."
20
- end
21
- when 2
22
- case ARGV[0]
23
- when "draft"
24
- Draft.new(ARGV[1])
25
- when "page"
26
- Page.new(ARGV[1])
27
- when "post"
28
- Post.new(ARGV[1])
29
- when "publish"
30
- Draft.new(ARGV[1]).publish
31
- else
32
- puts "Invalid option. Run `diary --help`."
33
- end
34
- when 3
35
- case ARGV[0]
36
- when "publish"
37
- Draft.new(ARGV[1]).publish(ARGV[2])
38
- else
39
- puts "Invalid option. Run `diary --help`."
40
- end
41
- else
42
- puts "Invalid option(s). Run `diary --help`."
43
- end
4
+ Diary::CLI.command(*ARGV)
@@ -1,67 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/diary/version", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{diary}
8
- s.version = "0.1.5"
5
+ s.name = "diary"
6
+ s.version = Diary::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Robin Clart"]
9
+ s.email = ["robin@charlin.be"]
10
+ s.homepage = "http://rubygems.org/gems/diary"
11
+ s.summary = "Another static blog generator"
12
+ s.description = "Diary makes it easy to maintain a file based website with template blog posts and pages."
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Robin Clart"]
12
- s.date = %q{2010-07-02}
13
- s.default_executable = %q{diary}
14
- s.email = %q{robin@clart.me}
15
- s.executables = ["diary"]
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "bin/diary",
27
- "diary.gemspec",
28
- "lib/diary.rb",
29
- "lib/diary/cli.rb",
30
- "lib/diary/draft.rb",
31
- "lib/diary/item.rb",
32
- "lib/diary/message.rb",
33
- "lib/diary/output.rb",
34
- "lib/diary/page.rb",
35
- "lib/diary/post.rb",
36
- "lib/diary/site.rb",
37
- "lib/diary/template.rb",
38
- "test/helper.rb",
39
- "test/test_diary.rb"
40
- ]
41
- s.homepage = %q{http://github.com/robinclart/diary}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.6}
45
- s.summary = %q{Dead Simple, Static Blog Generator}
46
- s.test_files = [
47
- "test/helper.rb",
48
- "test/test_diary.rb"
49
- ]
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "diary"
50
16
 
51
- if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 3
17
+ s.add_dependency "activesupport", ">= 3.0.0"
18
+ s.add_dependency "bluecloth", ">= 2.0.11"
19
+ s.add_dependency "sinatra", ">= 1.1.0"
54
20
 
55
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<liquid>, [">= 2.0.0"])
57
- s.add_runtime_dependency(%q<bluecloth>, [">= 2.0.7"])
58
- else
59
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
60
- s.add_dependency(%q<bluecloth>, [">= 2.0.7"])
61
- end
62
- else
63
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
64
- s.add_dependency(%q<bluecloth>, [">= 2.0.7"])
65
- end
66
- end
21
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
67
22
 
23
+ s.files = `git ls-files`.split("\n")
24
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
25
+ s.require_path = 'lib'
26
+ end
@@ -1,30 +1,33 @@
1
- $:.unshift File.dirname(__FILE__)
2
-
3
- # rubygems
4
- require 'rubygems'
5
-
6
- # stdlib
7
1
  require 'fileutils'
8
2
  require 'date'
9
3
  require 'yaml'
10
4
  require 'ostruct'
5
+ require 'singleton'
6
+ require 'erb'
11
7
 
12
- # third party
13
- require 'liquid'
8
+ require 'active_support/inflector'
14
9
  require 'bluecloth'
15
10
 
16
- # internals
17
- require 'diary/message'
18
- require 'diary/site'
19
- require 'diary/template'
20
- require 'diary/output'
21
- require 'diary/item'
22
- require 'diary/draft'
23
- require 'diary/page'
24
- require 'diary/post'
25
-
26
11
  module Diary
27
- def self.version
28
- File.read(File.expand_path("../../VERSION", __FILE__))
12
+ autoload :CLI, "diary/cli"
13
+ autoload :Message, "diary/message"
14
+ autoload :Snippet, "diary/snippet"
15
+ autoload :VERSION, "diary/version"
16
+
17
+ module Item
18
+ autoload :Base, "diary/item/base"
19
+ autoload :Data, "diary/item/data"
20
+ autoload :Template, "diary/item/template"
21
+ autoload :Url, "diary/item/url"
22
+ autoload :Snippet, "diary/item/snippet"
23
+ autoload :Output, "diary/item/output"
24
+ autoload :Creator, "diary/item/creator"
25
+ autoload :Finder, "diary/item/finder"
29
26
  end
27
+
28
+ extend Message::Shorthand
29
+ end
30
+
31
+ Dir["#{File.dirname(__FILE__)}/diary/items/*.rb"].sort.each do |path|
32
+ require "diary/items/#{File.basename(path, '.rb')}"
30
33
  end
@@ -1,47 +1,9 @@
1
- require 'optparse'
2
-
3
1
  module Diary
4
- class CLI
5
- def self.parse(args)
6
- # The options specified on the command line will be collected in *options*.
7
- # We set default values here.
8
- options = OpenStruct.new
9
- options.verbose = false
10
- options.force = false
11
-
12
- opts = OptionParser.new do |opts|
13
- opts.banner = "Usage: diary ACTION [-vf]"
14
-
15
- opts.separator "\nSpecific options:"
16
-
17
- # Verbose
18
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
19
- options.verbose = v
20
- end
21
-
22
- # Force
23
- opts.on("-f", "--[no-]force", "Force all items to compile") do |f|
24
- options.force = f
25
- end
26
-
27
- opts.separator "\nCommon options:"
28
-
29
- # No argument, shows at tail. This will print an options summary.
30
- # Try it and see!
31
- opts.on_tail("-h", "--help", "Show this message") do
32
- puts opts
33
- exit
34
- end
35
-
36
- # Another typical switch to print the version.
37
- opts.on_tail("--version", "Show version") do
38
- puts "diary #{Diary.version}"
39
- exit
40
- end
41
- end
2
+ module CLI
3
+ autoload :Parser, "diary/cli/parser"
4
+ autoload :Commands, "diary/cli/commands"
42
5
 
43
- opts.parse!(args)
44
- options
45
- end
6
+ extend Parser
7
+ extend Commands
46
8
  end
47
9
  end
@@ -0,0 +1,23 @@
1
+ Dir["#{File.dirname(__FILE__)}/commands/*.rb"].sort.each do |path|
2
+ require "diary/cli/commands/#{File.basename(path, '.rb')}"
3
+ end
4
+
5
+ module Diary
6
+ module CLI
7
+ module Commands
8
+ def command(*args)
9
+ options = Diary::CLI.parse(args)
10
+
11
+ if args.size == 0
12
+ return
13
+ end
14
+
15
+ if respond_to?(args.first)
16
+ self.send(args.shift, args, options)
17
+ elsif
18
+ Diary.message :error, "No command found", :red
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def compile(args, options)
5
+ if (args.first == "all") or (args.size == 0)
6
+ Post.all.each { |p| p.output(options.force) }
7
+ Page.all.each { |p| p.output(options.force) }
8
+ elsif args.size >= 2
9
+ const_get(args.shift.capitalize).find(args.first).output(options.force)
10
+ else
11
+ const_get(args.shift.capitalize).all.each { |p| p.output(options.force) }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def init(args, options)
5
+ # Create directories
6
+ %w{ templates posts pages snippets public }.each do |directory|
7
+ create_dir directory
8
+ end
9
+
10
+ # Create files
11
+ create_file "templates/index.html.erb", "<%= content %>"
12
+ create_file "config.yml", "sync:\n user: \n server: \n path: \n"
13
+ end
14
+
15
+ private
16
+
17
+ def create_dir(path)
18
+ unless File.exists?(path)
19
+ FileUtils.mkdir_p(path)
20
+
21
+ Diary.message :create, path, :green
22
+ else
23
+ Diary.message :exist, path, :yellow
24
+ end
25
+ end
26
+
27
+ def create_file(path, content)
28
+ unless File.exists?(path)
29
+ f = File.new(path, "w+")
30
+ f.puts(content)
31
+ f.close
32
+
33
+ Diary.message :create, path, :green
34
+ else
35
+ Diary.message :exist, path, :yellow
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def new(args, options)
5
+ const_get(args.shift.capitalize).create(args.first)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def server(args, options)
5
+ Diary.message :start, "Diary server is starting...", :green
6
+ `ruby #{File.expand_path("../../../server.rb", __FILE__)}`
7
+ rescue Interrupt
8
+ Diary.message :close, "Diary server is closing...", :red
9
+ sleep(2)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module Diary
2
+ module CLI
3
+ module Commands
4
+ def sync(args, options)
5
+ Diary.message :sync, sync_path, :magenta
6
+ `rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete --exclude "*bak" ./public/* #{sync_path}`
7
+ end
8
+
9
+ private
10
+
11
+ def sync_path
12
+ "#{sync_config.user}@#{sync_config.server}:#{sync_config.path}"
13
+ end
14
+
15
+ def sync_config
16
+ OpenStruct.new(YAML.load_file("config.yml")["sync"]) if File.exists?("config.yml")
17
+ end
18
+ end
19
+ end
20
+ end