postview 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/ABOUT +9 -0
  2. data/HISTORY +27 -1
  3. data/Rakefile +3 -1
  4. data/VERSION +4 -4
  5. data/bin/postview +2 -2
  6. data/lib/postview.rb +64 -13
  7. data/lib/postview/application.rb +34 -21
  8. data/lib/postview/authentication.rb +36 -0
  9. data/lib/postview/cli.rb +10 -0
  10. data/lib/postview/cli/create_command.rb +53 -37
  11. data/lib/postview/cli/server_command.rb +2 -2
  12. data/lib/postview/extensions.rb +10 -0
  13. data/lib/postview/helpers.rb +3 -0
  14. data/lib/postview/settings.rb +19 -17
  15. data/lib/postview/site.rb +13 -1
  16. data/lib/postview/version.rb +1 -1
  17. data/tasks/package.rake +80 -2
  18. data/test/application_test.rb +29 -14
  19. data/test/{extensions.rb → customizations.rb} +1 -0
  20. data/test/fixtures/application/config/settings.yml +4 -1
  21. data/test/fixtures/application/themes/{gemstone → mytheme}/images/banners/banner.jpg +0 -0
  22. data/test/fixtures/application/themes/{gemstone → mytheme}/images/favicon.ico +0 -0
  23. data/test/fixtures/application/themes/{gemstone → mytheme}/images/logo.png +0 -0
  24. data/test/fixtures/application/themes/{gemstone → mytheme}/images/navigation-bar.gif +0 -0
  25. data/test/fixtures/application/themes/{gemstone → mytheme}/images/postview.png +0 -0
  26. data/test/fixtures/application/themes/{gemstone → mytheme}/images/rack.png +0 -0
  27. data/test/fixtures/application/themes/{gemstone → mytheme}/images/ruby.png +0 -0
  28. data/test/fixtures/application/themes/{gemstone → mytheme}/images/sinatra.png +0 -0
  29. data/test/fixtures/application/themes/{gemstone → mytheme}/images/trojan.com +0 -0
  30. data/test/fixtures/application/themes/{gemstone/javascripts/gemstone.js → mytheme/javascripts/postview.js} +0 -0
  31. data/test/fixtures/application/themes/{gemstone → mytheme}/stylesheets/gemstone.css +0 -0
  32. data/test/fixtures/application/themes/{gemstone → mytheme}/stylesheets/postview.css +0 -0
  33. data/test/fixtures/application/themes/mytheme/templates/about.erb +1 -0
  34. data/test/fixtures/application/themes/mytheme/templates/archive/index.erb +3 -0
  35. data/test/fixtures/application/themes/mytheme/templates/archive/show.erb +1 -0
  36. data/test/fixtures/application/themes/mytheme/templates/drafts/index.erb +3 -0
  37. data/test/fixtures/application/themes/mytheme/templates/drafts/show.erb +1 -0
  38. data/test/fixtures/application/themes/mytheme/templates/error.erb +1 -0
  39. data/test/fixtures/application/themes/mytheme/templates/index.erb +3 -0
  40. data/{themes/default → test/fixtures/application/themes/mytheme/templates}/layout.erb +2 -2
  41. data/test/fixtures/application/themes/mytheme/templates/posts/index.erb +3 -0
  42. data/test/fixtures/application/themes/mytheme/templates/posts/show.erb +1 -0
  43. data/test/fixtures/application/themes/mytheme/templates/search.erb +6 -0
  44. data/test/fixtures/application/themes/mytheme/templates/tags/index.erb +3 -0
  45. data/test/fixtures/application/themes/mytheme/templates/tags/show.erb +6 -0
  46. data/test/fixtures/site/blog/config.ru +6 -0
  47. data/test/fixtures/site/blog/config/settings.yml +25 -0
  48. data/test/fixtures/{application/themes/gemstone/error.erb → site/blog/empty.yml} +0 -0
  49. data/test/fixtures/site/blog/posts/20090529-third_article.t1.t2.t3.mkd +4 -0
  50. data/test/fixtures/site/blog/posts/20090602-fourth_article.t1.t2.t3.t4.mkd +4 -0
  51. data/test/fixtures/site/blog/posts/archive/20080529-first_article.t1.mkd +4 -0
  52. data/test/fixtures/site/blog/posts/archive/20080602-second_article.t1.t2.mkd +4 -0
  53. data/test/fixtures/site/blog/posts/drafts/20090730-fifth_article.t1.t2.t3.t4.t5.mkd +4 -0
  54. data/{themes/default/error.erb → test/fixtures/site/themes/mytheme/images/banners/banner.jpg} +0 -0
  55. data/test/fixtures/site/themes/mytheme/images/favicon.ico +0 -0
  56. data/test/fixtures/site/themes/mytheme/images/logo.png +0 -0
  57. data/test/fixtures/site/themes/mytheme/images/navigation-bar.gif +0 -0
  58. data/test/fixtures/site/themes/mytheme/images/postview.png +0 -0
  59. data/test/fixtures/site/themes/mytheme/images/rack.png +0 -0
  60. data/test/fixtures/site/themes/mytheme/images/ruby.png +0 -0
  61. data/test/fixtures/site/themes/mytheme/images/sinatra.png +0 -0
  62. data/test/fixtures/site/themes/mytheme/images/trojan.com +0 -0
  63. data/test/fixtures/site/themes/mytheme/javascripts/postview.js +1 -0
  64. data/test/fixtures/site/themes/mytheme/stylesheets/gemstone.css +1 -0
  65. data/test/fixtures/site/themes/mytheme/stylesheets/postview.css +238 -0
  66. data/test/fixtures/site/themes/mytheme/templates/about.erb +1 -0
  67. data/test/fixtures/site/themes/mytheme/templates/archive/index.erb +3 -0
  68. data/test/fixtures/site/themes/mytheme/templates/archive/show.erb +1 -0
  69. data/test/fixtures/site/themes/mytheme/templates/drafts/index.erb +3 -0
  70. data/test/fixtures/site/themes/mytheme/templates/drafts/show.erb +1 -0
  71. data/test/fixtures/site/themes/mytheme/templates/error.erb +1 -0
  72. data/test/fixtures/site/themes/mytheme/templates/index.erb +3 -0
  73. data/test/fixtures/{application/themes/gemstone → site/themes/mytheme/templates}/layout.erb +20 -14
  74. data/test/fixtures/site/themes/mytheme/templates/posts/index.erb +3 -0
  75. data/test/fixtures/site/themes/mytheme/templates/posts/show.erb +1 -0
  76. data/test/fixtures/site/themes/mytheme/templates/search.erb +6 -0
  77. data/test/fixtures/site/themes/mytheme/templates/tags/index.erb +3 -0
  78. data/test/fixtures/site/themes/mytheme/templates/tags/show.erb +6 -0
  79. data/test/helpers_test.rb +1 -2
  80. data/test/settings_test.rb +12 -3
  81. data/test/site_test.rb +3 -4
  82. data/themes/default/stylesheets/postview.css +1 -0
  83. data/themes/default/{about.erb → templates/about.erb} +1 -1
  84. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/archive/index.erb +0 -0
  85. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/archive/show.erb +0 -0
  86. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/drafts/index.erb +1 -1
  87. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/drafts/show.erb +0 -0
  88. data/themes/default/templates/error.erb +13 -0
  89. data/themes/default/{index.erb → templates/index.erb} +1 -1
  90. data/themes/default/templates/layout.erb +130 -0
  91. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/posts/index.erb +0 -0
  92. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/posts/show.erb +0 -0
  93. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/search.erb +0 -0
  94. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/tags/index.erb +0 -0
  95. data/{test/fixtures/application/themes/gemstone → themes/default/templates}/tags/show.erb +0 -0
  96. metadata +164 -61
  97. data/INFO +0 -14
  98. data/lib/postview/about.rb +0 -34
  99. data/test/fixtures/application/themes/gemstone/about.erb +0 -22
  100. data/test/fixtures/application/themes/gemstone/index.erb +0 -38
  101. data/test/helper.rb +0 -9
  102. data/themes/default/archive/index.erb +0 -21
  103. data/themes/default/archive/show.erb +0 -17
  104. data/themes/default/drafts/index.erb +0 -21
  105. data/themes/default/drafts/show.erb +0 -17
  106. data/themes/default/posts/index.erb +0 -21
  107. data/themes/default/posts/show.erb +0 -17
  108. data/themes/default/search.erb +0 -40
  109. data/themes/default/tags/index.erb +0 -12
  110. data/themes/default/tags/show.erb +0 -40
data/ABOUT ADDED
@@ -0,0 +1,9 @@
1
+ :summary:
2
+ Simple blogware that render Markdown files.
3
+ :description:
4
+ Postview is a simple blogware written in Ruby using the Sinatra DSL for render files written in Markdown.
5
+ :authors:
6
+ - Hallison Batista
7
+ :email: email@hallisonbatista.com
8
+ :homepage: http://postview.rubyforge.org/
9
+
data/HISTORY CHANGED
@@ -1,9 +1,35 @@
1
+ [0.9.0 - 2009-10-14 - Features, enhancements and improvements]
2
+ New features, enhancements and small improvements
3
+
4
+ * Features
5
+ * Support for authentication has been added.
6
+
7
+ * Enhancements
8
+ * Added instructions for use Rack::Static to serve static theme files.
9
+ * Added content in error theme template file.
10
+ * Added marshalling content in postview.gemspec file.
11
+ * Added tasks for build Gemspec file.
12
+ * Tests have been fixed for authorization feature.
13
+
14
+ * Fixes
15
+ * Fixes in default theme file for render list of drafts.
16
+ * The application path has been fixed.
17
+
18
+ * Improvements
19
+ * Small improvements in code.
20
+
21
+ [0.8.1 - 2009-09-17 - Updates]
22
+ * Added helper method for list all drafted posts.
23
+ * Added fixtures for tests in drafts path.
24
+ * Added new theme files for drafts.
25
+ * All unneeded path variables have been removed.
26
+
1
27
  [0.8.0 - 2009-09-15 - Improvements]
2
28
  * Added helper methods for improves all theme views source.
3
29
  * Added core extensions.
4
30
 
5
31
  [0.7.0 - 2009-09-10 - Features, enhancements and improvements]
6
- New features and enhancements for version 0.7.0.
32
+ New features, enhancements and several improvements.
7
33
 
8
34
  * Features
9
35
  * Postview is a RubyGems project.
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'net/ftp'
5
5
  require 'rake/testtask'
6
6
  require 'rake/packagetask'
7
7
 
8
+ Rake::application.options.trace = true
8
9
 
9
10
  # Show text message in console.
10
11
  def banner(message)
@@ -100,7 +101,7 @@ def rsync(directory, destination = nil)
100
101
  end
101
102
 
102
103
  desc <<-end_desc.gsub(/^[ ]{2}/,'')
103
- Create new post in #{settings.directory_for(:posts)}.
104
+ Create new post in #{settings.path_to(:posts)}.
104
105
  For edit posts, set environment variable EDITOR or VISUAL. Otherwise,
105
106
  pass editor="<your favorite editor command and arguments>".
106
107
 
@@ -176,3 +177,4 @@ Dir["tasks/**.rake"].each do |task_file|
176
177
  load task_file
177
178
  end
178
179
 
180
+ task :default => :test
data/VERSION CHANGED
@@ -1,8 +1,8 @@
1
1
  ---
2
+ :minor: 9
2
3
  :release:
3
- :cycle: Beta release
4
+ :cycle: Beta
5
+ :patch: 0
4
6
  :timestamp: 2009-08-24 07:46:28 -04:00
7
+ :date: 2009-10-14
5
8
  :major: 0
6
- :date: 2009-09-17
7
- :minor: 8
8
- :patch: 1
data/bin/postview CHANGED
@@ -12,7 +12,7 @@ ARGV.options do |arguments|
12
12
  arguments.summary_indent = " "
13
13
  arguments.summary_width = 24
14
14
  arguments.banner = <<-end_banner.gsub /^[ ]{4}/, ''
15
- #{Postview::Version}
15
+ #{Postview::version_summary}
16
16
 
17
17
  Usage:
18
18
  #{program} <command> [options]
@@ -28,7 +28,7 @@ ARGV.options do |arguments|
28
28
  arguments.separator "Global options:"
29
29
 
30
30
  arguments.on("-h", "--help", nil, "Show this message.") { puts arguments }
31
- arguments.on(nil, "--version", nil, "Show version information.") { puts Postview::About }
31
+ arguments.on(nil, "--version", nil, "Show version information.") { puts Postview::about }
32
32
 
33
33
  arguments.separator ""
34
34
 
data/lib/postview.rb CHANGED
@@ -36,7 +36,7 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
36
36
  module Postview
37
37
 
38
38
  # RubyGems.
39
- require 'rubygems'
39
+ require 'rubygems' unless $LOADED_FEATURES.include? 'rubygems.rb'
40
40
 
41
41
  # Core requires.
42
42
  require 'optparse'
@@ -44,7 +44,6 @@ module Postview
44
44
  require 'ostruct'
45
45
 
46
46
  # 3rd part libraries/projects.
47
- require 'rack'
48
47
  require 'sinatra/base' unless defined? ::Sinatra::Base
49
48
  require 'sinatra/mapping' unless defined? ::Sinatra::Mapping
50
49
  require 'postage' unless defined? ::Postage
@@ -56,18 +55,70 @@ module Postview
56
55
  # Root path for Postview source.
57
56
  ROOT = Pathname.new("#{File.dirname(__FILE__)}/..").expand_path
58
57
 
59
- # Current path.
60
- PATH = Pathname.new(".").expand_path
61
-
62
58
  # Auto-load all internal requires.
63
- autoload :About, 'postview/about'
64
- autoload :Version, 'postview/version'
65
-
66
- autoload :Settings, 'postview/settings'
67
- autoload :Site, 'postview/site'
68
- autoload :Helpers, 'postview/helpers'
69
- autoload :Application, 'postview/application'
70
- autoload :CLI, 'postview/cli'
59
+ autoload :Settings, 'postview/settings'
60
+ autoload :Site, 'postview/site'
61
+ autoload :Helpers, 'postview/helpers'
62
+ autoload :Authentication, 'postview/authentication'
63
+ autoload :Application, 'postview/application'
64
+ autoload :CLI, 'postview/cli'
65
+
66
+ class << self
67
+
68
+ # Current application path.
69
+ def path
70
+ @path ||= Pathname.new(Dir.pwd).expand_path
71
+ end
72
+
73
+ # Change current directory path for load all settings from other
74
+ # path.
75
+ def path=(pathname)
76
+ @path = Pathname.new(pathname).expand_path
77
+ end
78
+
79
+ # Version
80
+ def version_spec
81
+ @version_spec ||= OpenStruct.new(YAML.load_file(ROOT.join("VERSION")))
82
+ end
83
+
84
+ # Current version tag.
85
+ def version_tag
86
+ %w{major minor patch release}.map do |tag|
87
+ version_spec.send(tag)
88
+ end.compact.join(".")
89
+ end
90
+
91
+ # Version information.
92
+ def version_summary
93
+ "#{name.sub(/::.*/,'')} v#{version_tag} (#{version_spec.date.strftime('%B %d, %Y')}, #{version_spec.cycle})"
94
+ end
95
+
96
+ # About information loaded from +ABOUT+ file.
97
+ def about_info
98
+ @about_info ||= OpenStruct.new(YAML.load_file(File.join(ROOT, "ABOUT")))
99
+ end
100
+
101
+ # About
102
+ def about
103
+ <<-end_info.gsub(/^[ ]{6}/,'')
104
+ #{version_summary}
105
+
106
+ Copyright (C) #{version_spec.timestamp.year} #{about_info.authors.join(', ')}
107
+
108
+ #{about_info.description}
109
+
110
+ For more information, please see the project homepage
111
+ #{about_info.homepage}. Bugs, enhancements and improvements,
112
+ please send message to #{about_info.email}.
113
+ end_info
114
+ end
115
+
116
+ # Render about text to HTML.
117
+ def about_to_html
118
+ Maruku.new(about).to_html
119
+ end
120
+
121
+ end
71
122
 
72
123
  end # module Postview
73
124
 
@@ -7,16 +7,16 @@ class Application < Sinatra::Base #:nodoc: all
7
7
 
8
8
  configure do
9
9
  set :settings, Postview::Settings.load
10
- set :site, settings.build_site
11
- set :page, settings.build_page
10
+ set :site, settings.build_site
11
+ set :page, settings.build_page
12
+ set :theme, settings.path_to(:themes).join(site.theme)
12
13
 
13
- set :static, true
14
+ enable :static
15
+ enable :session
14
16
 
15
- set :root, Postview::PATH
16
- set :public, Postview::PATH.join("public")
17
- set :views, Postview::PATH.join("themes", site.theme)
18
-
19
- map :theme, "/"
17
+ set :root, Postview::path
18
+ set :public, root.join("public")
19
+ set :views, theme.join("templates")
20
20
 
21
21
  mapping settings.sections
22
22
  end
@@ -34,11 +34,7 @@ class Application < Sinatra::Base #:nodoc: all
34
34
 
35
35
  helpers Postview::Helpers
36
36
 
37
- # Get theme resources
38
- # TOFIX: Check security and other problems
39
- get theme_path "/:resource/*.*" do |resource, file, ext|
40
- send_file options.views.join(resource, "#{file}.#{ext}")
41
- end
37
+ use Rack::Static, :urls => ["/stylesheets", "/images", "/javascripts"], :root => theme
42
38
 
43
39
  # Show all information for site.
44
40
  get root_path do
@@ -88,17 +84,23 @@ class Application < Sinatra::Base #:nodoc: all
88
84
 
89
85
  # Show all drafts.
90
86
  get drafts_path do
91
- @all_tags = @site.find_in_drafts.all_tags.sort
92
- @page.title, @page.keywords = title_path(:drafts), "drafts #{@all_tags.join(' ')}"
93
- show :"drafts/index"
87
+ authenticate!
88
+ if authenticated?
89
+ @all_tags = @site.find_in_drafts.all_tags.sort
90
+ @page.title, @page.keywords = title_path(:drafts), "drafts #{@all_tags.join(' ')}"
91
+ show :"drafts/index"
92
+ end
94
93
  end
95
94
 
96
95
  # Show selected drafted post.
97
96
  get drafts_path "/:year/:month/:day/:name" do |year, month, day, name|
98
- @current_post = @site.find_in_drafts.post(year, month, day, name)
99
- @all_tags = @site.find_in_drafts.all_tags.sort
100
- @page.title, @page.keywords = @current_post.title, @current_post.tags.join(' ')
101
- show :"drafts/show"
97
+ authenticate!
98
+ if authenticated?
99
+ @current_post = @site.find_in_drafts.post(year, month, day, name)
100
+ @all_tags = @site.find_in_drafts.all_tags.sort
101
+ @page.title, @page.keywords = @current_post.title, @current_post.tags.join(' ')
102
+ show :"drafts/show"
103
+ end
102
104
  end
103
105
 
104
106
  # Show information site.
@@ -113,10 +115,21 @@ class Application < Sinatra::Base #:nodoc: all
113
115
  show :search
114
116
  end
115
117
 
118
+ get manager_path do
119
+ authenticate!
120
+ if authenticated?
121
+ @page.title, @page.keywords = title_path(:manager, :posts), @all_tags.join(' ')
122
+ show :"posts/index"
123
+ end
124
+ end
125
+
126
+ private
127
+
128
+ include Postview::Authentication
129
+
116
130
  def show(template, locals = {}, options = {})
117
131
  erb template, options.update(:locals => locals)
118
132
  end
119
- private :show
120
133
 
121
134
  end # class Application
122
135
 
@@ -0,0 +1,36 @@
1
+ module Postview
2
+
3
+ # Copyright (c) 2009 Hallison Batista
4
+ module Authentication
5
+
6
+ # ...
7
+ def authentication
8
+ @authentication ||= Rack::Auth::Basic::Request.new(request.env)
9
+ end
10
+
11
+ def username
12
+ env["REMOTE_USER"] || authentication.credentials.first
13
+ end
14
+
15
+ def password
16
+ authentication.credentials.last
17
+ end
18
+
19
+ # Run basic authentication.
20
+ def authenticate!
21
+ headers "WWW-Authenticate" => %(Basic realm="#{@site.title}") and
22
+ @error_message = "Not authorized\n" and throw(:halt, [401, erb(:error)]) and
23
+ return unless authenticated?
24
+ end
25
+
26
+ def authenticated?
27
+ authentication.provided? &&
28
+ authentication.basic? &&
29
+ authentication.credentials &&
30
+ @site.authenticate?(username, password)
31
+ end
32
+
33
+ end # module Authorization
34
+
35
+ end # module Postview
36
+
data/lib/postview/cli.rb CHANGED
@@ -41,6 +41,16 @@ module CLI
41
41
  end
42
42
  end
43
43
 
44
+ def hidden_prompt label
45
+ while true
46
+ system "stty -echo"
47
+ printf "%1$s %2$s: ", " "*2, "#{label}"
48
+ value = $stdin.readline.chomp.strip
49
+ system "stty echo"
50
+ return value unless value.nil? || value.to_s.empty?
51
+ end
52
+ end
53
+
44
54
  def start process, &block
45
55
  printf "%1$s %2$s ", ">"*2, process
46
56
  if block_given?
@@ -21,7 +21,7 @@ class CreateCommand #:nodoc: all
21
21
  if args.first =~ /^\w.*|^\/\w.*/
22
22
  new(args.shift, args.options).run
23
23
  else
24
- new(".", args.options).run
24
+ new(nil, args.options).run
25
25
  end
26
26
  end
27
27
 
@@ -40,7 +40,7 @@ private
40
40
  @arguments.summary_indent = " "
41
41
  @arguments.summary_width = 24
42
42
  @arguments.banner = <<-end_banner.gsub(/^[ ]{6}/, '')
43
- #{Postview::Version}
43
+ #{Postview::version_summary}
44
44
 
45
45
  Usage:
46
46
  #{Postview.name.downcase} create <path>
@@ -55,21 +55,27 @@ private
55
55
  @arguments.separator ""
56
56
 
57
57
  begin
58
- @arguments.parse!
58
+ unless @path
59
+ puts @arguments
60
+ exit 1
61
+ else
62
+ @arguments.parse!
63
+ end
59
64
  rescue => error
60
65
  puts error
61
66
  puts @arguments
62
67
  end
63
- puts "#{Postview::Version}\n\n"
68
+ puts "#{Postview::version_summary}\n\n"
64
69
  end
65
70
 
66
71
  def build_settings
67
- create_path
72
+ create_root_path
68
73
  if @options[:prompt]
69
74
  prompt_for_site_settings
70
75
  prompt_for_directories_settings
71
76
  prompt_for_sections_settings
72
77
  end
78
+ prompt_for_site_password
73
79
  create_settings
74
80
  create_directories
75
81
  create_default_theme
@@ -87,7 +93,7 @@ private
87
93
  end
88
94
  end
89
95
 
90
- def create_path
96
+ def create_root_path
91
97
  start "Creating #{@path} path" do
92
98
  step { @path = Pathname.new(@path) }
93
99
  step { @path.exist? ? raise("Path #{@path} exist") : true }
@@ -131,37 +137,38 @@ private
131
137
  end
132
138
 
133
139
  def create_default_theme
134
- create = lambda do |path|
135
- start "Creating #{path}" do
136
- step { path.exist? ? raise("Theme path #{path} exist") : true }
137
- step { path.mkpath; true }
138
- step { path.exist? }
139
- end
140
- end
140
+ create_path @theme
141
+ copy_default_theme @theme_default, @theme
142
+ end
141
143
 
142
- copy = lambda do |origin, destination|
143
- start "Creating #{destination}" do
144
- step { destination.exist? ? raise("Theme file #{destination} exist") : true }
145
- step { FileUtils.copy(origin, destination); true }
146
- step { destination.exist? }
147
- end
144
+ def create_path(path)
145
+ start "Creating #{path}" do
146
+ step { path.exist? ? raise("Path #{path} exist") : true }
147
+ step { path.mkpath; true }
148
+ step { path.exist? }
148
149
  end
150
+ end
149
151
 
150
- create.call @theme
151
-
152
- @theme_default.children.map do |origin|
153
- if origin.directory?
154
- path = @theme.join origin.basename
155
- create.call path
156
- origin.children.map do |file|
157
- copy.call file, path.join(file.basename)
158
- end
152
+ def copy_default_theme(origin, destination)
153
+ origin.children.map do |origin_path|
154
+ if origin_path.directory?
155
+ destination_path = destination.join(origin_path.basename)
156
+ create_path destination_path
157
+ copy_default_theme origin_path, destination_path
159
158
  else
160
- copy.call origin, @theme.join(origin.basename)
159
+ copy_file origin_path, destination.join(origin_path.basename)
161
160
  end
162
161
  end
163
162
  end
164
163
 
164
+ def copy_file(origin, destination)
165
+ start "Creating #{destination}" do
166
+ step { destination.exist? ? raise("Theme file #{destination} exist") : true }
167
+ step { FileUtils.copy(origin, destination); true }
168
+ step { destination.exist? }
169
+ end
170
+ end
171
+
165
172
  def create_rackup
166
173
  config = @path.join("config.ru")
167
174
  start "Creating #{config} file" do
@@ -182,10 +189,10 @@ private
182
189
  rakefile.open("w+") do |file|
183
190
  content = []
184
191
  content << "require 'postview'\n"
192
+ content << "include Postview::CLI::Command\n"
185
193
  content << <<-'end_def'.gsub(/^[ ]{10}/, '')
186
194
  # Build default settings file and load.
187
195
  def settings
188
- #Postview::Settings.build_default_file
189
196
  Postview::Settings.load
190
197
  end
191
198
  end_def
@@ -242,7 +249,7 @@ private
242
249
 
243
250
  content << <<-'end_task'.gsub(/^[ ]{10}/, '')
244
251
  desc <<-end_desc.gsub(/^[ ]{2}/,'')
245
- Create new post in #{settings.directory_for(:posts)}.
252
+ Create new post in #{settings.path_to(:posts)}.
246
253
  For edit posts, set environment variable EDITOR or VISUAL. Otherwise,
247
254
  pass editor="<your favorite editor command and arguments>".
248
255
 
@@ -255,22 +262,22 @@ private
255
262
  $ rake post[other/path/for/new/post]
256
263
  end_desc
257
264
  task :post, [:directory] do |spec, args|
258
- banner "New post. Type all attributes for new post.\n"
265
+ puts "New post. Type all attributes for new post.\n"
259
266
  path = if args.directory
260
267
  if settings.directories.has_key? args.directory.to_sym
261
- settings.directory_for(args.directory.to_sym)
268
+ settings.path_to(args.directory.to_sym)
262
269
  else
263
270
  args.directory
264
271
  end
265
272
  else
266
- settings.directory_for(:drafts)
273
+ settings.path_to(:drafts)
267
274
  end
268
275
  post = Postage::Post.new :title => prompt("Post title"),
269
276
  :publish_date => prompt("Publish date", Date.today),
270
277
  :tags => prompt("Tags separated by spaces").split(' '),
271
278
  :filter => :markdown,
272
- :content => <<-end_content.gsub(/^[ ]{29}/,'')
273
- Tanks for use #{Postview}.
279
+ :content => <<-end_content.gsub(/^[ ]{28}/,'')
280
+ Thanks for use #{Postview.version_summary}.
274
281
  Input here the content of your post.
275
282
  end_content
276
283
 
@@ -303,7 +310,7 @@ private
303
310
  settings.directories.keys.each do |dirname|
304
311
  desc "Synchronize #{dirname}."
305
312
  task dirname, [:destination] do |spec,args|
306
- banner "Synchronize #{dirname} directory."
313
+ puts "Synchronize #{dirname} directory."
307
314
  ftp(dirname, args.destination)
308
315
  end
309
316
  end
@@ -332,6 +339,15 @@ private
332
339
  end
333
340
  end
334
341
 
342
+ def prompt_for_site_password
343
+ init "Settings required for generate new token" do |site|
344
+ site[:author] = prompt "Author name", @settings.site[:author]
345
+ site[:domain] = prompt "Domain", @settings.site[:domain], %r{.*\..*}
346
+ site[:token] = Postview::Site::tokenize(site[:author], hidden_prompt("Password"), site[:domain])
347
+ @site.update site
348
+ end
349
+ end
350
+
335
351
  def prompt_for_directories_settings
336
352
  init "Settings for directories" do |directories|
337
353
  directories[:posts] = prompt "Posts", @settings.directories[:posts]