postview 0.7.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.
Files changed (71) hide show
  1. data/HISTORY +67 -0
  2. data/INFO +14 -0
  3. data/LICENSE +0 -0
  4. data/README.rdoc +103 -0
  5. data/Rakefile +174 -0
  6. data/VERSION +8 -0
  7. data/bin/postview +51 -0
  8. data/lib/postview.rb +68 -0
  9. data/lib/postview/about.rb +34 -0
  10. data/lib/postview/application.rb +130 -0
  11. data/lib/postview/cli.rb +71 -0
  12. data/lib/postview/cli/create_command.rb +362 -0
  13. data/lib/postview/cli/server_command.rb +115 -0
  14. data/lib/postview/helpers.rb +21 -0
  15. data/lib/postview/patches.rb +11 -0
  16. data/lib/postview/settings.rb +107 -0
  17. data/lib/postview/site.rb +51 -0
  18. data/lib/postview/version.rb +27 -0
  19. data/tasks/documentation.rake +21 -0
  20. data/tasks/history.rake +7 -0
  21. data/tasks/homepage.rake +10 -0
  22. data/tasks/package.rake +11 -0
  23. data/tasks/version.rake +56 -0
  24. data/test/application_test.rb +122 -0
  25. data/test/extensions.rb +23 -0
  26. data/test/fixtures/application/config.ru +6 -0
  27. data/test/fixtures/application/config/settings.yml +22 -0
  28. data/test/fixtures/application/empty.yml +0 -0
  29. data/test/fixtures/application/posts/20090529-postview_blogware.ruby.sinatra.mkd +4 -0
  30. data/test/fixtures/application/posts/20090602-postview_blogware.ruby.sinatra.mkd +4 -0
  31. data/test/fixtures/application/posts/archive/20080529-postview_blogware.ruby.sinatra.mkd +4 -0
  32. data/test/fixtures/application/posts/archive/20080602-postview_blogware.ruby.sinatra.mkd +4 -0
  33. data/test/fixtures/application/posts/drafts/20090730-draft_postview_blogware.ruby.sinatra.mkd +4 -0
  34. data/test/fixtures/application/themes/gemstone/about.erb +0 -0
  35. data/test/fixtures/application/themes/gemstone/archive/index.erb +0 -0
  36. data/test/fixtures/application/themes/gemstone/archive/show.erb +17 -0
  37. data/test/fixtures/application/themes/gemstone/images/banners/banner.jpg +0 -0
  38. data/test/fixtures/application/themes/gemstone/images/favicon.ico +0 -0
  39. data/test/fixtures/application/themes/gemstone/images/trojan.com +0 -0
  40. data/test/fixtures/application/themes/gemstone/index.erb +0 -0
  41. data/test/fixtures/application/themes/gemstone/javascripts/gemstone.js +1 -0
  42. data/test/fixtures/application/themes/gemstone/layout.erb +0 -0
  43. data/test/fixtures/application/themes/gemstone/posts/index.erb +0 -0
  44. data/test/fixtures/application/themes/gemstone/posts/show.erb +0 -0
  45. data/test/fixtures/application/themes/gemstone/search.erb +0 -0
  46. data/test/fixtures/application/themes/gemstone/stylesheets/gemstone.css +1 -0
  47. data/test/fixtures/application/themes/gemstone/tags/index.erb +0 -0
  48. data/test/fixtures/application/themes/gemstone/tags/show.erb +0 -0
  49. data/test/helper.rb +9 -0
  50. data/test/settings_test.rb +72 -0
  51. data/test/site_test.rb +62 -0
  52. data/themes/default/about.erb +24 -0
  53. data/themes/default/archive/index.erb +21 -0
  54. data/themes/default/archive/show.erb +17 -0
  55. data/themes/default/error.erb +0 -0
  56. data/themes/default/images/favicon.ico +0 -0
  57. data/themes/default/images/logo.png +0 -0
  58. data/themes/default/images/navigation-bar.gif +0 -0
  59. data/themes/default/images/postview.png +0 -0
  60. data/themes/default/images/rack.png +0 -0
  61. data/themes/default/images/ruby.png +0 -0
  62. data/themes/default/images/sinatra.png +0 -0
  63. data/themes/default/index.erb +38 -0
  64. data/themes/default/layout.erb +117 -0
  65. data/themes/default/posts/index.erb +21 -0
  66. data/themes/default/posts/show.erb +17 -0
  67. data/themes/default/search.erb +40 -0
  68. data/themes/default/stylesheets/postview.css +238 -0
  69. data/themes/default/tags/index.erb +12 -0
  70. data/themes/default/tags/show.erb +40 -0
  71. metadata +158 -0
data/HISTORY ADDED
@@ -0,0 +1,67 @@
1
+ [0.7.0 - not released - Features]
2
+ * The project is a Gem package.
3
+ * Postview command for create a new directory structure.
4
+ * Added CLI commands.
5
+ * Added basic classes for version and information about project.
6
+ * Added basic files for versioning and informations.
7
+ * Updated methods and constants to path of directories.
8
+ * Updated default views.
9
+ * Support to themes using ERB.
10
+
11
+ [0.6.0 - 2009-07-31 - Features and enhancements]
12
+ * Added task for build settings file.
13
+ * Added task for build rackup file.
14
+ * Default root path has been added in settings.
15
+ * Improvements in synchronize tasks.
16
+ * Fixes in the page keywords.
17
+ * All tasks have been added in the rakefile.
18
+
19
+ [0.5.0 - 2009-07-21 - Features and enhancements]
20
+ * Task for synchronize post files has been added.
21
+ * New instructions in README file.
22
+ * Added instructions in task for new post.
23
+ * Fixes and updates in settings.
24
+ * Default values have been added in settings.
25
+ * All views have been improved.
26
+ * All views for new helper methods have been updated.
27
+ * All tests have been fixed.
28
+ * Mapping class has been removed in favour of Sinatra::Mapping extension.
29
+ * All methods in the application have been updated for new methods of the
30
+ Sinatra::Mapping extension.
31
+
32
+ [0.4.0 - 2009-07-13 - Features and enhancements]
33
+ * Postage have been used for handle post files.
34
+ * Several features have been updated for use Postage.
35
+
36
+ [0.3.2 - 2009-07-09 - Enhancements]
37
+ * Task for create new post.
38
+ * Task for create release package.
39
+
40
+ [0.3.1 - 2009-07-09 - Features]
41
+ * Added individual tasks.
42
+ * Added default settings to fix errors.
43
+
44
+ [0.3.0 - 2009-07-07 - Features]
45
+ * Added render wrapper method for simplified local variables in views.
46
+ * Support for listing drafts.
47
+ * Added new mapping for list all drafts.
48
+ * Added rescue errors in settings file not found.
49
+
50
+ [0.2.0 - 2009-07-02 - Features]
51
+ * The helper methods were improved.
52
+ * Improvements in routes and settings.
53
+ * Added class for mapping route paths.
54
+ * All tests and views were fixed.
55
+ * Improved methods in settings class.
56
+ * Improved initialize method in site, finder and mapping.
57
+
58
+ [0.1.0 - 2009-06-04 - Main features for alpha version]
59
+ * All posts are loaded from files.
60
+ * All attributes for a post are loaded from a file name.
61
+ * Support for tags, archiving and search.
62
+ * Support for configuration of routes and directories for posts and
63
+ archive.
64
+ * Lightweight interface.
65
+ * Added support for settings.
66
+ * Listing posts by tags and search.
67
+
data/INFO ADDED
@@ -0,0 +1,14 @@
1
+ :name: postview
2
+ :summary:
3
+ Simple blog-engine that render Markdown files.
4
+ :description:
5
+ Postview is a simple blog-engine written in Ruby using the Sinatra DSL for render files written in Markdown.
6
+ :authors:
7
+ - Hallison Batista
8
+ :email: email@hallisonbatista.com
9
+ :homepage: http://postview.rubyforge.org/
10
+ :dependencies:
11
+ sinatra: >= 0.9.1.1
12
+ sinatra-mapping: >= 1.0.5
13
+ postage: >= 0.1.4.1
14
+
data/LICENSE ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,103 @@
1
+ = Postview
2
+
3
+ Just write your posts ... and view!
4
+
5
+ Postview is a simple blogware written in Ruby using Sinatra DSL that
6
+ renders files written in Markdown.
7
+
8
+ * Easy to configure.
9
+ * Easy to synchronize.
10
+
11
+ Install {Ruby}[http://www.ruby-lang.org/] Gem package and try.
12
+
13
+ == Getting start
14
+
15
+ The Postview requires the following gems:
16
+
17
+ * {Rack}[http://rack.rubyforge.org/]
18
+ * {Rack-Test}[http://github.com/brynary/rack-test]
19
+ * {Sinatra}[http://www.sinatrarb.com/]
20
+ * {Sinatra-Mapping}[http://sinatra-mapping.rubyforge.org/]
21
+ * {Maruku}[http://maruku.rubyforge.org/]
22
+ * {Postage}[http://postage.rubyforge.org/]
23
+
24
+ Install stable gem from {RubyForge.org}[http://rubyforge.org/].
25
+
26
+ $ sudo gem install postview
27
+
28
+ Or, install development gem from {Github.com}[http://github.com/].
29
+
30
+ $ sudo gem install hallison-postview --source http://gems.github.com/
31
+
32
+ So, run command for create and setup a new Postview directory structure.
33
+
34
+ $ postview create path/to/website
35
+
36
+ After setup, run server with command:
37
+
38
+ $ RACK_ENV=production postview server
39
+
40
+ NOTE: Inopportunely, Postview not run server using production environment,
41
+ yet.
42
+
43
+ In your browser, access http://localhost:9000/.
44
+
45
+ == Create new post
46
+
47
+ New post can be created by using the task `post`:
48
+
49
+ $ cd path/to/postview
50
+ $ rake post
51
+
52
+ Following all instructions. Please, set environment variable +EDITOR+
53
+ or +VISUAL+ for editing your posts. Ether else, run:
54
+
55
+ $ cd path/to/postview
56
+ $ EDITOR=<your favorite editor> rake post
57
+
58
+ The new post will be written in drafts directory. You can pass other
59
+ directory.
60
+
61
+ $ cd path/to/postview
62
+ $ rake post[path/to/other/post/directory]
63
+
64
+ NOTE: New feature for creates new post from blog manager will be added.
65
+
66
+ == Synchronize your posts
67
+
68
+ You can synchronize your page using the synchronize tasks. For more
69
+ information about this task, run <code>rake -D sync</code>.
70
+
71
+ It's need creates and edit file placed in +/your/home/directory/.netrc+.
72
+ The +directory+ attribute most be setted in +settings.yml+ file.
73
+
74
+ Example:
75
+
76
+ # remote host
77
+ /remote/path/to/postview
78
+ `-- posts
79
+ |-- archive
80
+ `-- drafts
81
+ # local host
82
+ posts
83
+ |-- 20090702-foo_post_article.ruby.sinatra.git.mkd
84
+ |-- archive
85
+ | `-- 20080702-foo_post_article.ruby.sinatra.git.mkd
86
+ `-- drafts
87
+ `-- 20090703-foo_draft_article.ruby.sinatra.git.mkd
88
+
89
+ # To synchronize posts
90
+ $ rake sync:posts
91
+ $ rake sync:posts[remote/path/to/postview/posts]
92
+
93
+ # To synchronize archive
94
+ $ rake sync:archive
95
+ $ rake sync:archive[remote/path/to/postview/posts/archive]
96
+
97
+ # To synchronize drafts
98
+ $ rake sync:drafts
99
+ $ rake sync:drafts[remote/path/to/postview/posts/drafts]
100
+
101
+ # To synchronize all
102
+ $ rake sync:all
103
+
data/Rakefile ADDED
@@ -0,0 +1,174 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'lib/postview'
4
+ require 'net/ftp'
5
+ require 'rake/testtask'
6
+ require 'rake/packagetask'
7
+
8
+
9
+ # Show text message in console.
10
+ def banner(message)
11
+ printf "\n%s\n", Postview
12
+ printf "\n%s\n\n", message
13
+ end
14
+
15
+ # Prompt for values.
16
+ def prompt(label, default = nil)
17
+ while true
18
+ printf((default ? "%s [%s]: " : "%s: "), "#{label}", "#{default}")
19
+ value = $stdin.readline.chomp.strip
20
+ value = default if value.empty?
21
+ return value unless value.nil? || value.to_s.empty?
22
+ end
23
+ end
24
+
25
+ # Build default settings file and load.
26
+ def settings
27
+ #Postview::Settings.build_default_file
28
+ Postview::Settings.load
29
+ end
30
+
31
+ # Build and load the resource file for FTP connection.
32
+ def netrc
33
+ begin
34
+ @netrc ||= File.readlines(File.join(ENV['HOME'],".netrc"))
35
+ rescue Errno::ENOENT => message
36
+ puts <<-end_message.gsub(/^[ ]{6}/,'')
37
+ #{message}.
38
+ Please create the .netrc file in your home.
39
+ echo "\
40
+ machine #{settings.site[:domain]}
41
+ login <username>
42
+ password <password>
43
+ " >> #{ENV['HOME']}/.netrc
44
+ end_message
45
+ exit 1
46
+ end
47
+ match ||= @netrc.to_s.match(/machine (.*?)[\n ]login (.*?)[\n ]password (.*?)[\n ].*?/m)
48
+ { :machine => match[1].strip, :login => match[2].strip, :password => match[3].strip }
49
+ end
50
+
51
+ # Synchronize directory
52
+ def ftp(directory, destination = nil)
53
+ origin = settings.directories[directory]
54
+ destination ||= File.join(settings.site[:directory], settings.directories[directory])
55
+ posts = settings.build_finder_for(directory).all_posts
56
+
57
+ $stdout.puts ">> Connecting to #{netrc[:machine]} ..."
58
+
59
+ Net::FTP.open(netrc[:machine]) do |ftp|
60
+ ftp.login netrc[:login], netrc[:password]
61
+
62
+ $stdout.puts ">> Logged as #{netrc[:login]} ..."
63
+
64
+ $stdout.puts ">> Accessing #{destination} ..."
65
+
66
+ ftp.chdir destination
67
+
68
+ posts.each do |post|
69
+ $stdout.puts ">> Copying #{post} ..."
70
+ ftp.putbinaryfile(File.join(origin, post.file))
71
+ end
72
+
73
+ $stdout.puts ">> Synchronization for #{directory} is done."
74
+ end
75
+ end
76
+
77
+ def rsync(directory, destination = nil)
78
+ origin = settings.directories[directory]
79
+ destination ||= File.join(settings.site[:directory], settings.directories[directory])
80
+ posts = settings.build_finder_for(directory).all_posts
81
+
82
+ $stdout.puts ">> Connecting to #{netrc[:machine]} ..."
83
+
84
+ Net::FTP.open(netrc[:machine]) do |ftp|
85
+ ftp.login netrc[:login], netrc[:password]
86
+
87
+ $stdout.puts ">> Logged as #{netrc[:login]} ..."
88
+
89
+ $stdout.puts ">> Accessing #{destination} ..."
90
+
91
+ ftp.chdir destination
92
+
93
+ posts.each do |post|
94
+ $stdout.puts ">> Copying #{post} ..."
95
+ ftp.putbinaryfile(File.join(origin, post.file))
96
+ end
97
+
98
+ $stdout.puts ">> Synchronization for #{directory} is done."
99
+ end
100
+ end
101
+
102
+ desc <<-end_desc.gsub(/^[ ]{2}/,'')
103
+ Create new post in #{settings.directory_for(:posts)}.
104
+ For edit posts, set environment variable EDITOR or VISUAL. Otherwise,
105
+ pass editor="<your favorite editor command and arguments>".
106
+
107
+ Example:
108
+
109
+ $ rake post editor="gvim -f"
110
+
111
+ Or use directory argument for create a post in other directory.
112
+
113
+ $ rake post[other/path/for/new/post]
114
+ end_desc
115
+ task :post, [:directory] do |spec, args|
116
+ banner "New post. Type all attributes for new post.\n"
117
+ path = if args.directory
118
+ if settings.directories.has_key? args.directory.to_sym
119
+ settings.directory_for(args.directory.to_sym)
120
+ else
121
+ args.directory
122
+ end
123
+ else
124
+ settings.directory_for(:drafts)
125
+ end
126
+ post = Postage::Post.new :title => prompt("Post title"),
127
+ :publish_date => prompt("Publish date", Date.today),
128
+ :tags => prompt("Tags separated by spaces").split(' '),
129
+ :filter => :markdown,
130
+ :content => <<-end_content.gsub(/^[ ]{29}/,'')
131
+ Tanks for use #{Postview}.
132
+ Input here the content of your post.
133
+ end_content
134
+
135
+ begin
136
+ post.build_file
137
+ post.create_into(path)
138
+ rescue Errno::ENOENT => message
139
+ $stderr.puts message
140
+ $stderr.puts "Try create path #{args.directory}."
141
+ exit 1
142
+ end
143
+
144
+ printf "%s\n", "The post '#{post.title}' was created in '#{path}/#{post.file}'."
145
+
146
+ editor = ENV['editor'] || ENV['EDITOR'] || ENV['VISUAL'] || 'none'
147
+ if prompt("Edit post using '#{editor}'?", "y") =~ /y/i
148
+ if editor
149
+ sh "#{editor} #{path}/#{post.file}"
150
+ else
151
+ printf "%s", "Editor not specified."
152
+ end
153
+ end
154
+
155
+ $stdout.puts ">> Post done."
156
+ end
157
+
158
+ namespace :sync do
159
+ settings.directories.keys.each do |dirname|
160
+ desc "Synchronize #{dirname}."
161
+ task dirname, [:destination] do |spec,args|
162
+ banner "Synchronize #{dirname} directory."
163
+ ftp(dirname, args.destination)
164
+ end
165
+ end
166
+
167
+ desc "Synchronize all directories."
168
+ task :all => settings.directories.keys
169
+ end
170
+
171
+ Dir["tasks/**.rake"].each do |task_file|
172
+ load task_file
173
+ end
174
+
data/VERSION ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ :major: 0
3
+ :release:
4
+ :minor: 7
5
+ :cycle: Beta release
6
+ :patch: 0
7
+ :date: 2009-09-10
8
+ :timestamp: 2009-08-24 07:46:28 -04:00
data/bin/postview ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2009 Hallison Batista
3
+
4
+ require File.expand_path(File.join(__FILE__, "..", "..", "lib", "postview"))
5
+
6
+ command = ARGV.shift if Postview::CLI.commands.include? ARGV.first
7
+ program = File.basename(__FILE__)
8
+ ENV['RACK_ENV'] = 'production'
9
+
10
+ ARGV.options do |arguments|
11
+
12
+ arguments.summary_indent = " "
13
+ arguments.summary_width = 24
14
+ arguments.banner = <<-end_banner.gsub /^[ ]{4}/, ''
15
+ #{Postview::Version}
16
+
17
+ Usage:
18
+ #{program} <command> [options]
19
+ #{program} [options]
20
+
21
+ Commands:
22
+ #{Postview::CLI.commands.join("\n#{arguments.summary_indent}")}
23
+
24
+ Run command with option "-h" or "--help" for more information.
25
+
26
+ end_banner
27
+
28
+ arguments.separator "Global options:"
29
+
30
+ arguments.on("-h", "--help", nil, "Show this message.") { puts arguments }
31
+ arguments.on(nil, "--version", nil, "Show version information.") { puts Postview::About }
32
+
33
+ arguments.separator ""
34
+
35
+ begin
36
+ if command
37
+ Postview::CLI.run(command, ARGV)
38
+ elsif ARGV.empty?
39
+ puts arguments
40
+ exit 0
41
+ else
42
+ arguments.parse!
43
+ end
44
+ rescue => error
45
+ puts arguments
46
+ puts error
47
+ exit 1
48
+ end
49
+
50
+ end
51
+
data/lib/postview.rb ADDED
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2009 Hallison Batista
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
3
+
4
+ # Postview - The minimalist blogware and static page generator.
5
+ #
6
+ # == Configuration
7
+ #
8
+ # After create your blog, edit <tt>config/settings.yml</tt> file.
9
+ #
10
+ # *site*:: Attributes for your site.
11
+ # * *title*
12
+ # * *subtitle*
13
+ # * *author*
14
+ # * *email*
15
+ # * *domain* for connect by FTP.
16
+ # * *directory*, remote. This attribute will be used to synchronize your posts.
17
+ # * *theme*
18
+ # *sections*:: Attributes for sections (routes) used in site.
19
+ # * *root* for main section
20
+ # * *posts*
21
+ # * *tags*
22
+ # * *archive*
23
+ # * *drafts*
24
+ # * *search*
25
+ # * *about*
26
+ # *directories*:: Attributes for paths to post files.
27
+ # * *posts*
28
+ # * *archive*
29
+ # * *drafts*
30
+ #
31
+ # == Themes
32
+ #
33
+ # Default theme is generated in <tt>themes/default</tt>. Change or migrate your favorite
34
+ # theme.
35
+ #
36
+ module Postview
37
+
38
+ # RubyGems.
39
+ require 'rubygems'
40
+
41
+ # Core requires.
42
+ require 'optparse'
43
+ require 'pathname'
44
+ require 'ostruct'
45
+
46
+ # 3rd part libraries/projects.
47
+ require 'sinatra/base' unless defined? ::Sinatra::Base
48
+ require 'sinatra/mapping' unless defined? ::Sinatra::Mapping
49
+ require 'postage' unless defined? ::Postage
50
+
51
+ # Internal requires
52
+ require 'postview/patches' if RUBY_VERSION < "1.8.7"
53
+
54
+ ROOT = Pathname.new("#{File.dirname(__FILE__)}/..").expand_path
55
+ PATH = Pathname.new(".").expand_path
56
+
57
+ # Auto-load all internal requires.
58
+ autoload :About, 'postview/about'
59
+ autoload :Version, 'postview/version'
60
+
61
+ autoload :Settings, 'postview/settings'
62
+ autoload :Site, 'postview/site'
63
+ autoload :Helpers, 'postview/helpers'
64
+ autoload :Application, 'postview/application'
65
+ autoload :CLI, 'postview/cli'
66
+
67
+ end # module Postview
68
+