ruhoh 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Gemfile +2 -2
  2. data/README.md +16 -0
  3. data/bin/ruhoh +5 -1
  4. data/history.json +19 -0
  5. data/lib/ruhoh/client/client.rb +35 -48
  6. data/lib/ruhoh/client/console_methods.rb +9 -0
  7. data/lib/ruhoh/client/help.yml +0 -4
  8. data/lib/ruhoh/config.rb +3 -2
  9. data/lib/ruhoh/db.rb +7 -28
  10. data/lib/ruhoh/page.rb +1 -1
  11. data/lib/ruhoh/parsers/pages.rb +2 -4
  12. data/lib/ruhoh/parsers/partials.rb +11 -2
  13. data/lib/ruhoh/parsers/payload.rb +2 -2
  14. data/lib/ruhoh/parsers/posts.rb +21 -24
  15. data/lib/ruhoh/parsers/scaffolds.rb +35 -0
  16. data/lib/ruhoh/paths.rb +11 -3
  17. data/lib/ruhoh/previewer.rb +3 -2
  18. data/lib/ruhoh/urls.rb +5 -1
  19. data/lib/ruhoh/version.rb +1 -1
  20. data/lib/ruhoh.rb +3 -1
  21. data/ruhoh.gemspec +24 -25
  22. data/spec/config_spec.rb +3 -3
  23. data/spec/db_spec.rb +5 -9
  24. data/spec/page_spec.rb +1 -1
  25. data/spec/parsers/layouts_spec.rb +0 -4
  26. data/spec/parsers/pages_spec.rb +44 -36
  27. data/spec/parsers/posts_spec.rb +2 -7
  28. data/spec/parsers/routes_spec.rb +0 -7
  29. data/spec/parsers/site_spec.rb +2 -7
  30. data/spec/setup_spec.rb +0 -3
  31. data/spec/spec_helper.rb +10 -6
  32. data/spec/support/shared_contexts.rb +24 -0
  33. data/{dash.html → system/dash.html} +0 -0
  34. data/system/partials/categories_list.html +3 -0
  35. data/system/partials/pages_list.html +7 -0
  36. data/system/partials/posts_collate.html +9 -0
  37. data/system/partials/posts_list.html +1 -0
  38. data/system/partials/posts_summary.html +30 -0
  39. data/system/partials/tags_list.html +3 -0
  40. data/{scaffolds → system/scaffolds}/draft.html +0 -0
  41. data/{scaffolds → system/scaffolds}/layout.html +0 -0
  42. data/{scaffolds → system/scaffolds}/page.html +0 -0
  43. data/{scaffolds → system/scaffolds}/post.html +0 -0
  44. data/{widgets → system/widgets}/analytics/config.yml +0 -0
  45. data/{widgets → system/widgets}/analytics/layouts/getclicky.html +0 -0
  46. data/{widgets → system/widgets}/analytics/layouts/google.html +0 -0
  47. data/{widgets → system/widgets}/comments/config.yml +0 -0
  48. data/{widgets → system/widgets}/comments/layouts/disqus.html +0 -0
  49. data/{widgets → system/widgets}/comments/layouts/facebook.html +0 -0
  50. data/{widgets → system/widgets}/comments/layouts/intensedebate.html +0 -0
  51. data/{widgets → system/widgets}/comments/layouts/livefyre.html +0 -0
  52. data/{widgets → system/widgets}/google_prettify/config.yml +0 -0
  53. data/{widgets → system/widgets}/google_prettify/layouts/google_prettify.html +0 -0
  54. metadata +32 -42
  55. data/scaffolds/theme/javascripts/.gitkeep +0 -0
  56. data/scaffolds/theme/layouts/default.html +0 -15
  57. data/scaffolds/theme/layouts/page.html +0 -7
  58. data/scaffolds/theme/layouts/post.html +0 -8
  59. data/scaffolds/theme/media/.gitkeep +0 -0
  60. data/scaffolds/theme/partials/.gitkeep +0 -0
  61. data/scaffolds/theme/stylesheets/style.css +0 -0
  62. data/scaffolds/theme/theme.yml +0 -27
  63. data/scaffolds/theme/widgets/.gitkeep +0 -0
data/Gemfile CHANGED
@@ -3,11 +3,11 @@ gemspec
3
3
 
4
4
  gem 'rack', "~> 1.4"
5
5
  gem 'directory_watcher', "~> 1.4"
6
- gem 'psych', "~> 1.3"
6
+ gem 'psych', "~> 1.3", :platforms => [:ruby_18, :mingw_18]
7
7
  gem 'redcarpet', "~> 2.1"
8
8
  gem 'nokogiri', "~> 1.5"
9
9
 
10
10
  group :development do
11
- gem 'rspec'
11
+ gem 'rspec', "~> 2.11"
12
12
  gem 'rake'
13
13
  end
data/README.md CHANGED
@@ -3,6 +3,22 @@
3
3
  <http://ruhoh.com>
4
4
 
5
5
  ### Usage
6
+
6
7
  $ gem install ruhoh
7
8
  $ ruhoh help
8
9
 
10
+ ### Platforms
11
+
12
+ ruhoh is tested with ruby 1.9.2 on mac OSX Lion.
13
+ ruhoh runs in production with ruby 1.9.2 on Ubuntu 10.04.4 LTS.
14
+
15
+ ruby 1.8.7 will not be (consciously) supported unless enough users bother me about it.
16
+
17
+ **Windows**
18
+
19
+ ruhoh should run on Windows with a few considerations:
20
+
21
+ If you run into trouble with YAML and psych see: https://github.com/ruhoh/ruhoh.rb/issues/54
22
+ More help is available here: https://github.com/ruhoh/ruhoh.rb/issues/search?q=windows
23
+
24
+ I can't easily test ruhoh on a Windows machine, so please consider contributing back to the community for running on Windows.
data/bin/ruhoh CHANGED
@@ -8,7 +8,7 @@ require 'ruhoh/client/client'
8
8
 
9
9
  require 'optparse'
10
10
 
11
- Options = Struct.new(:title, :date, :ext, :verbose)
11
+ Options = Struct.new(:title, :date, :ext, :hg, :verbose)
12
12
  options = Options.new
13
13
 
14
14
  opt_parser = OptionParser.new do |opts|
@@ -18,6 +18,10 @@ opt_parser = OptionParser.new do |opts|
18
18
  options.ext = ext
19
19
  end
20
20
 
21
+ opts.on("--hg", "Use mercurial (hg) instead of git for source control.") do
22
+ options.hg = true
23
+ end
24
+
21
25
  opts.on("-v", "--[no-]verbose", "Run verbosely. For pages, shows extra title, url meta-data.") do |v|
22
26
  options.verbose = v
23
27
  end
data/history.json CHANGED
@@ -1,4 +1,23 @@
1
1
  [
2
+ {
3
+ "version" : "1.1",
4
+ "date" : "26.08.2012",
5
+ "changes" : [
6
+ "All urls are normalized to never have trailing slashes. Fixes unfound urls when user forgets to add trailing slash to permalink formats.",
7
+ "Default partials have been moved to the 'system' level; ruhoh gem. User may still override them at the blog/theme level.",
8
+ "Partial files may now have extensions but wil still be referenced by name excluding extension.",
9
+ "(Internal) All system level assets are namespaced into the 'system' folder.",
10
+ "Theme scaffolding has been removed from the command line tool. `ruhoh theme <name>`"
11
+ ],
12
+ "features" : [
13
+ "@MrWerewolf adds ability to use custom blog scaffold url. Supports mercurial(hg) repository endpoints.",
14
+ "Add IRB console for ruhoh environment: `ruhoh console` ",
15
+ "Add scaffolds for file generation: post, page, layout, etc. System level scaffolds may be overwritten by blog level files."
16
+ ],
17
+ "bugs" : [
18
+ "@MrWerewolf removes psych gem dependency for ruby 1.9+ users."
19
+ ]
20
+ },
2
21
  {
3
22
  "version" : "1.0",
4
23
  "date" : "22.08.2012",
@@ -1,14 +1,16 @@
1
1
  require 'ruhoh/compiler'
2
+ require 'ruhoh/client/console_methods'
3
+ require 'irb'
2
4
 
3
5
  class Ruhoh
6
+
4
7
  class Client
5
8
 
6
9
  Paths = Struct.new(:page_template, :draft_template, :post_template, :layout_template, :theme_template)
7
- BlogScaffold = 'git://github.com/ruhoh/blog.git'
10
+ DefaultBlogScaffold = 'git://github.com/ruhoh/blog.git'
8
11
 
9
12
  def initialize(data)
10
13
  @iterator = 0
11
- self.setup_paths
12
14
  self.setup_options(data)
13
15
 
14
16
  cmd = (data[:args][0] == 'new') ? 'blog' : (data[:args][0] || 'help')
@@ -26,6 +28,14 @@ class Ruhoh
26
28
  self.__send__(cmd)
27
29
  end
28
30
 
31
+ # Thanks rails! https://github.com/rails/rails/blob/master/railties/lib/rails/commands/console.rb
32
+ def console
33
+ ARGV.clear # IRB throws an error otherwise.
34
+ require 'pp'
35
+ IRB::ExtendCommandBundle.send :include, Ruhoh::ConsoleMethods
36
+ IRB.start
37
+ end
38
+
29
39
  def setup_options(data)
30
40
  @args = data[:args]
31
41
  @options = data[:options]
@@ -33,15 +43,6 @@ class Ruhoh
33
43
  @options.ext = (@options.ext || 'md').gsub('.', '')
34
44
  end
35
45
 
36
- def setup_paths
37
- @paths = Paths.new
38
- @paths.page_template = File.join(Ruhoh::Root, "scaffolds", "page.html")
39
- @paths.draft_template = File.join(Ruhoh::Root, "scaffolds", "draft.html")
40
- @paths.post_template = File.join(Ruhoh::Root, "scaffolds", "post.html")
41
- @paths.layout_template = File.join(Ruhoh::Root, "scaffolds", "layout.html")
42
- @paths.theme_template = File.join(Ruhoh::Root, "scaffolds", "theme")
43
- end
44
-
45
46
  # Internal: Show Client Utility help documentation.
46
47
  def help
47
48
  file = File.join(Ruhoh::Root, 'lib', 'ruhoh', 'client', 'help.yml')
@@ -78,9 +79,10 @@ class Ruhoh
78
79
  @iterator += 1
79
80
  end while File.exist?(filename)
80
81
 
81
- FileUtils.mkdir_p File.dirname(filename)
82
+ Ruhoh::DB.update(:scaffolds)
82
83
 
83
- output = File.open(@paths.send("#{type}_template"), 'r:UTF-8') { |f| f.read }
84
+ FileUtils.mkdir_p File.dirname(filename)
85
+ output = Ruhoh::DB.scaffolds["#{type}.html"].to_s
84
86
  output = output.gsub('{{DATE}}', Ruhoh::Parsers::Posts.formatted_date(Time.now))
85
87
  File.open(filename, 'w:UTF-8') {|f| f.puts output }
86
88
 
@@ -105,12 +107,12 @@ class Ruhoh
105
107
  if File.exist?(filename)
106
108
  abort("Create new page: aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
107
109
  end
108
-
110
+
111
+ Ruhoh::DB.update(:scaffolds)
112
+
109
113
  FileUtils.mkdir_p File.dirname(filename)
110
- File.open(@paths.page_template, 'r:UTF-8') do |template|
111
- File.open(filename, 'w:UTF-8') do |page|
112
- page.puts template.read
113
- end
114
+ File.open(filename, 'w:UTF-8') do |page|
115
+ page.puts Ruhoh::DB.scaffolds['page.html'].to_s
114
116
  end
115
117
 
116
118
  Ruhoh::Friend.say {
@@ -140,6 +142,8 @@ class Ruhoh
140
142
  # Public: Create a new blog at the directory provided.
141
143
  def blog
142
144
  name = @args[1]
145
+ scaffold = @args.length > 2 ? @args[2] : DefaultBlogScaffold
146
+ useHg = @options.hg
143
147
  Ruhoh::Friend.say {
144
148
  red "Please specify a directory path."
145
149
  plain " ex: ruhoh new the-blogist"
@@ -156,9 +160,16 @@ class Ruhoh
156
160
 
157
161
  Ruhoh::Friend.say {
158
162
  plain "Trying this command:"
159
- cyan " git clone #{BlogScaffold} #{target_directory}"
160
163
 
161
- if system('git', 'clone', BlogScaffold, target_directory)
164
+ if useHg
165
+ cyan " hg clone #{scaffold} #{target_directory}"
166
+ success = system('hg', 'clone', scaffold, target_directory)
167
+ else
168
+ cyan " git clone #{scaffold} #{target_directory}"
169
+ success = system('git', 'clone', scaffold, target_directory)
170
+ end
171
+
172
+ if success
162
173
  green "Success! Now do..."
163
174
  cyan " cd #{target_directory}"
164
175
  cyan " rackup -p9292"
@@ -170,30 +181,6 @@ class Ruhoh
170
181
  }
171
182
  end
172
183
 
173
- # Public: Create a new theme scaffold with the given name.
174
- def theme
175
- name = @args[1]
176
- Ruhoh::Friend.say {
177
- red "Please specify a theme name."
178
- cyan "ex: ruhoh new theme the-rain"
179
- exit
180
- } if name.nil?
181
-
182
- target_directory = File.expand_path(File.join(Ruhoh.paths.theme, '..', name.gsub(/\s/, '-').downcase))
183
-
184
- if File.exist?(target_directory)
185
- abort("Create new theme: \e[31mAborted!\e[0m") if ask("#{target_directory} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
186
- end
187
-
188
- FileUtils.mkdir target_directory unless File.exist?(target_directory)
189
- FileUtils.cp_r "#{@paths.theme_template}/.", target_directory
190
-
191
- Ruhoh::Friend.say {
192
- green "New theme scaffold:"
193
- green target_directory
194
- }
195
- end
196
-
197
184
  # Public: Create a new layout file for the active theme.
198
185
  def layout
199
186
  name = @args[1]
@@ -208,11 +195,11 @@ class Ruhoh
208
195
  abort("Create new layout: aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
209
196
  end
210
197
 
198
+ Ruhoh::DB.update(:scaffolds)
199
+
211
200
  FileUtils.mkdir_p File.dirname(filename)
212
- File.open(@paths.layout_template) do |template|
213
- File.open(filename, 'w:UTF-8') do |page|
214
- page.puts template.read
215
- end
201
+ File.open(filename, 'w:UTF-8') do |page|
202
+ page.puts Ruhoh::DB.scaffolds['layout.html'].to_s
216
203
  end
217
204
 
218
205
  Ruhoh::Friend.say {
@@ -0,0 +1,9 @@
1
+ class Ruhoh
2
+ module ConsoleMethods
3
+ def reload!
4
+ Ruhoh.setup
5
+ Ruhoh.setup_paths
6
+ Ruhoh.setup_urls
7
+ end
8
+ end
9
+ end
@@ -50,10 +50,6 @@ commands:
50
50
  "command" : "layout <name>"
51
51
  "desc" : |
52
52
  Create a new layout for the currently active theme.
53
- -
54
- "command" : "theme <name>"
55
- "desc" : |
56
- Create a new theme scaffold.
57
53
  -
58
54
  "command" : "help"
59
55
  "desc" : |
data/lib/ruhoh/config.rb CHANGED
@@ -14,8 +14,8 @@ class Ruhoh
14
14
  :base_path
15
15
  )
16
16
 
17
- def self.generate(path_to_config)
18
- site_config = Ruhoh::Utils.parse_yaml_file(path_to_config)
17
+ def self.generate
18
+ site_config = Ruhoh::Utils.parse_yaml_file(Ruhoh.base, Ruhoh.names.config_data)
19
19
  unless site_config
20
20
  Ruhoh.log.error("Empty site_config.\nEnsure ./#{Ruhoh.names.config_data} exists and contains valid YAML")
21
21
  return false
@@ -42,6 +42,7 @@ class Ruhoh
42
42
  config.rss_limit = 20 if config.rss_limit.nil?
43
43
 
44
44
  config.posts_permalink = site_config['posts']['permalink'] rescue nil
45
+ config.posts_permalink ||= "/:categories/:year/:month/:day/:title.html"
45
46
  config.posts_layout = site_config['posts']['layout'] rescue nil
46
47
  config.posts_layout = 'post' if config.posts_layout.nil?
47
48
  excluded_posts = site_config['posts']['exclude'] rescue nil
data/lib/ruhoh/db.rb CHANGED
@@ -9,44 +9,23 @@ require 'ruhoh/parsers/stylesheets'
9
9
  require 'ruhoh/parsers/javascripts'
10
10
  require 'ruhoh/parsers/payload'
11
11
  require 'ruhoh/parsers/site'
12
+ require 'ruhoh/parsers/scaffolds'
12
13
 
13
14
  class Ruhoh
14
15
  # Public: Database class for interacting with "data" in Ruhoh.
15
16
  class DB
16
- WhiteList = [:site, :posts, :pages, :routes, :layouts, :partials, :widgets, :theme_config, :stylesheets, :javascripts, :payload]
17
+ WhiteList = [:site, :posts, :pages, :routes, :layouts, :partials, :widgets, :theme_config, :stylesheets, :javascripts, :payload, :scaffolds]
17
18
 
18
19
  class << self
19
20
  self.__send__ :attr_reader, *WhiteList
20
21
 
21
22
  def update(name)
22
- self.instance_variable_set("@#{name}",
23
- case name
24
- when :site
25
- Ruhoh::Parsers::Site.generate
26
- when :routes
27
- Ruhoh::Parsers::Routes.generate
28
- when :posts
29
- Ruhoh::Parsers::Posts.generate
30
- when :pages
31
- Ruhoh::Parsers::Pages.generate
32
- when :layouts
33
- Ruhoh::Parsers::Layouts.generate
34
- when :partials
35
- Ruhoh::Parsers::Partials.generate
36
- when :widgets
37
- Ruhoh::Parsers::Widgets.generate
38
- when :theme_config
39
- Ruhoh::Parsers::ThemeConfig.generate
40
- when :stylesheets
41
- Ruhoh::Parsers::Stylesheets.generate
42
- when :javascripts
43
- Ruhoh::Parsers::Javascripts.generate
44
- when :payload
45
- Ruhoh::Parsers::Payload.generate
46
- else
47
- raise "Data type: '#{name}' is not a valid data type."
48
- end
23
+ camelized_name = name.to_s.split('_').map {|a| a.capitalize}.join
24
+ self.instance_variable_set("@#{name}",
25
+ Ruhoh::Parsers.const_get(camelized_name).generate
49
26
  )
27
+ rescue NameError
28
+ raise NameError, "Data type: '#{name}' is not a valid data type."
50
29
  end
51
30
 
52
31
  # Always regenerate a fresh payload since it
data/lib/ruhoh/page.rb CHANGED
@@ -86,7 +86,7 @@ class Ruhoh
86
86
  self.ensure_id
87
87
  path = CGI.unescape(@data['url']).gsub(/^\//, '') #strip leading slash.
88
88
  path = "index.html" if path.empty?
89
- path += 'index.html' unless path =~ /\.\w+$/
89
+ path += '/index.html' unless path =~ /\.\w+$/
90
90
  path
91
91
  end
92
92
 
@@ -67,13 +67,11 @@ class Ruhoh
67
67
  url = name.split('/').map {|p| Ruhoh::Urls.to_url_slug(p) }.join('/')
68
68
  url = "#{url}#{ext}".gsub(/index.html$/, '')
69
69
  if page['permalink'] == 'pretty' || Ruhoh.config.pages_permalink == 'pretty'
70
- url = url.gsub(/\.html$/, '/')
70
+ url = url.gsub(/\.html$/, '')
71
71
  end
72
72
 
73
- url = "#{Ruhoh.config.base_path}#{url}"
74
73
  url = '/' if url.empty?
75
-
76
- url
74
+ Ruhoh::Urls.to_url(url)
77
75
  end
78
76
 
79
77
  end # Pages
@@ -3,7 +3,11 @@ class Ruhoh
3
3
  module Partials
4
4
 
5
5
  def self.generate
6
- self.global_partials.merge(self.theme_partials)
6
+ self.system_partials.merge(
7
+ self.global_partials
8
+ ).merge(
9
+ self.theme_partials
10
+ )
7
11
  end
8
12
 
9
13
  def self.theme_partials
@@ -13,6 +17,10 @@ class Ruhoh
13
17
  def self.global_partials
14
18
  self.process(Ruhoh.paths.partials)
15
19
  end
20
+
21
+ def self.system_partials
22
+ self.process(Ruhoh.paths.system_partials)
23
+ end
16
24
 
17
25
  def self.process(path)
18
26
  return {} unless File.exist?(path)
@@ -22,7 +30,8 @@ class Ruhoh
22
30
  Dir.glob("**/*").each { |filename|
23
31
  next if FileTest.directory?(filename)
24
32
  next if ['.'].include? filename[0]
25
- File.open(filename, 'r:UTF-8') { |f| partials[filename] = f.read }
33
+ name = filename.chomp(File.extname(filename))
34
+ File.open(filename, 'r:UTF-8') { |f| partials[name] = f.read }
26
35
  }
27
36
  }
28
37
  partials
@@ -26,7 +26,7 @@ class Ruhoh
26
26
  def self.determine_category_and_tag_urls
27
27
  return nil unless Ruhoh::DB.routes && Ruhoh::DB.posts
28
28
  categories_url = nil
29
- ["#{Ruhoh.config.base_path}categories/", "#{Ruhoh.config.base_path}categories.html"].each { |url|
29
+ [Ruhoh::Urls.to_url("categories"), Ruhoh::Urls.to_url("categories.html")].each { |url|
30
30
  categories_url = url and break if Ruhoh::DB.routes.key?(url)
31
31
  }
32
32
  Ruhoh::DB.posts['categories'].each do |key, value|
@@ -34,7 +34,7 @@ class Ruhoh
34
34
  end
35
35
 
36
36
  tags_url = nil
37
- ["#{Ruhoh.config.base_path}tags/", "#{Ruhoh.config.base_path}tags.html"].each { |url|
37
+ [Ruhoh::Urls.to_url("tags"), Ruhoh::Urls.to_url("tags.html")].each { |url|
38
38
  tags_url = url and break if Ruhoh::DB.routes.key?(url)
39
39
  }
40
40
  Ruhoh::DB.posts['tags'].each do |key, value|
@@ -137,34 +137,31 @@ class Ruhoh
137
137
  def self.permalink(post)
138
138
  date = Date.parse(post['date'])
139
139
  title = Ruhoh::Urls.to_url_slug(post['title'])
140
- format = post['permalink'] || Ruhoh.config.posts_permalink || "/:categories/:year/:month/:day/:title.html"
140
+ format = post['permalink'] || Ruhoh.config.posts_permalink
141
141
 
142
- # Use the literal permalink if it is a non-tokenized string.
143
- unless format.include?(':')
142
+ if format.include?(':')
143
+ filename = File.basename(post['id'], File.extname(post['id']))
144
+ category = Array(post['categories'])[0]
145
+ category = category.split('/').map {|c| Ruhoh::Urls.to_url_slug(c) }.join('/') if category
146
+
147
+ url = {
148
+ "year" => date.strftime("%Y"),
149
+ "month" => date.strftime("%m"),
150
+ "day" => date.strftime("%d"),
151
+ "title" => title,
152
+ "filename" => filename,
153
+ "i_day" => date.strftime("%d").to_i.to_s,
154
+ "i_month" => date.strftime("%m").to_i.to_s,
155
+ "categories" => category || '',
156
+ }.inject(format) { |result, token|
157
+ result.gsub(/:#{Regexp.escape token.first}/, token.last)
158
+ }.gsub(/\/+/, "/")
159
+ else
160
+ # Use the literal permalink if it is a non-tokenized string.
144
161
  url = format.gsub(/^\//, '').split('/').map {|p| CGI::escape(p) }.join('/')
145
- return "#{Ruhoh.config.base_path}#{url}"
146
162
  end
147
163
 
148
- filename = File.basename(post['id'], File.extname(post['id']))
149
- category = Array(post['categories'])[0]
150
- category = category.split('/').map {|c| Ruhoh::Urls.to_url_slug(c) }.join('/') if category
151
-
152
- url = {
153
- "year" => date.strftime("%Y"),
154
- "month" => date.strftime("%m"),
155
- "day" => date.strftime("%d"),
156
- "title" => title,
157
- "filename" => filename,
158
- "i_day" => date.strftime("%d").to_i.to_s,
159
- "i_month" => date.strftime("%m").to_i.to_s,
160
- "categories" => category || '',
161
- }.inject(format) { |result, token|
162
- result.gsub(/:#{Regexp.escape token.first}/, token.last)
163
- }.gsub(/\/+/, "/")
164
-
165
- url = url.gsub(/^\//, '') #prep for prepending the base_path
166
- url = "#{Ruhoh.config.base_path}#{url}"
167
- url
164
+ Ruhoh::Urls.to_url(url)
168
165
  end
169
166
 
170
167
  def self.build_chronology(ordered_posts)
@@ -0,0 +1,35 @@
1
+ class Ruhoh
2
+ module Parsers
3
+ module Scaffolds
4
+
5
+ def self.generate
6
+ self.system_scaffolds.merge(
7
+ self.scaffolds
8
+ )
9
+ end
10
+
11
+ def self.scaffolds
12
+ self.process(Ruhoh.paths.scaffolds)
13
+ end
14
+
15
+ def self.system_scaffolds
16
+ self.process(Ruhoh.paths.system_scaffolds)
17
+ end
18
+
19
+ def self.process(path)
20
+ return {} unless File.exist?(path)
21
+
22
+ scaffolds = {}
23
+ FileUtils.cd(path) {
24
+ Dir.glob("**/*").each { |filename|
25
+ next if FileTest.directory?(filename)
26
+ next if ['.'].include? filename[0]
27
+ File.open(filename, 'r:UTF-8') { |f| scaffolds[filename] = f.read }
28
+ }
29
+ }
30
+ scaffolds
31
+ end
32
+
33
+ end #Scaffolds
34
+ end #Parsers
35
+ end #Ruhoh
data/lib/ruhoh/paths.rb CHANGED
@@ -14,6 +14,7 @@ class Ruhoh
14
14
  :partials,
15
15
  :plugins,
16
16
  :posts,
17
+ :scaffolds,
17
18
  :site_data,
18
19
  :themes,
19
20
  :widgets,
@@ -27,8 +28,11 @@ class Ruhoh
27
28
  :theme_javascripts,
28
29
  :theme_stylesheets,
29
30
  :theme_widgets,
30
-
31
+
32
+ :system,
31
33
  :system_dashboard_file,
34
+ :system_scaffolds,
35
+ :system_partials,
32
36
  :system_widgets
33
37
  )
34
38
 
@@ -46,6 +50,7 @@ class Ruhoh
46
50
  paths.site_data = File.join(Ruhoh.base, Ruhoh.names.site_data)
47
51
  paths.themes = File.join(Ruhoh.base, Ruhoh.names.themes)
48
52
  paths.plugins = File.join(Ruhoh.base, Ruhoh.names.plugins)
53
+ paths.scaffolds = File.join(Ruhoh.base, Ruhoh.names.scaffolds)
49
54
 
50
55
  paths.theme = File.join(Ruhoh.base, Ruhoh.names.themes, Ruhoh.config.theme)
51
56
  paths.theme_dashboard_file= File.join(paths.theme, Ruhoh.names.dashboard_file)
@@ -59,8 +64,11 @@ class Ruhoh
59
64
 
60
65
  return false unless self.theme_is_valid?(paths)
61
66
 
62
- paths.system_dashboard_file = File.join(Ruhoh::Root, Ruhoh.names.dashboard_file)
63
- paths.system_widgets = File.join(Ruhoh::Root, Ruhoh.names.widgets)
67
+ paths.system = File.join(Ruhoh::Root, Ruhoh.names.system)
68
+ paths.system_dashboard_file = File.join(paths.system, Ruhoh.names.dashboard_file)
69
+ paths.system_partials = File.join(paths.system, Ruhoh.names.partials)
70
+ paths.system_scaffolds = File.join(paths.system, Ruhoh.names.scaffolds)
71
+ paths.system_widgets = File.join(paths.system, Ruhoh.names.widgets)
64
72
 
65
73
  paths
66
74
  end
@@ -14,8 +14,9 @@ class Ruhoh
14
14
 
15
15
  def call(env)
16
16
  return favicon if env['PATH_INFO'] == '/favicon.ico'
17
- env['PATH_INFO'] += "/" unless (env['PATH_INFO'] =~ /\.\w+$/ || env['PATH_INFO'][-1] == "/")
18
- return admin if env['PATH_INFO'] == "#{Ruhoh.urls.dashboard}/"
17
+ # Always remove trailing slash if sent unless it's the root page.
18
+ env['PATH_INFO'].gsub!(/\/$/, '') unless env['PATH_INFO'] == "/"
19
+ return admin if env['PATH_INFO'] == Ruhoh.urls.dashboard
19
20
 
20
21
  id = Ruhoh::DB.routes[env['PATH_INFO']]
21
22
  raise "Page id not found for url: #{env['PATH_INFO']}" unless id
data/lib/ruhoh/urls.rb CHANGED
@@ -28,8 +28,12 @@ class Ruhoh
28
28
  urls
29
29
  end
30
30
 
31
+ # Ruhoh.config.base_path is assumed to be well-formed.
32
+ # Always remove trailing slash.
33
+ # Returns String - normalized url with prepended base_path
31
34
  def self.to_url(*args)
32
- Ruhoh.config.base_path + args.join('/')
35
+ url = args.join('/').chomp('/').reverse.chomp('/').reverse
36
+ url = Ruhoh.config.base_path + url
33
37
  end
34
38
 
35
39
  def self.to_url_slug(title)
data/lib/ruhoh/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class Ruhoh
2
- Version = VERSION = '1.0'
2
+ Version = VERSION = '1.1'
3
3
  RuhohSpec = '1.0'
4
4
  end
data/lib/ruhoh.rb CHANGED
@@ -47,8 +47,10 @@ class Ruhoh
47
47
  :plugins => 'plugins',
48
48
  :posts => 'posts',
49
49
  :javascripts => 'javascripts',
50
+ :scaffolds => 'scaffolds',
50
51
  :site_data => 'site.yml',
51
52
  :stylesheets => 'stylesheets',
53
+ :system => 'system',
52
54
  :themes => 'themes',
53
55
  :theme_config => 'theme.yml',
54
56
  :widgets => 'widgets',
@@ -63,7 +65,7 @@ class Ruhoh
63
65
  self.reset
64
66
  @log.log_file = opts[:log_file] if opts[:log_file]
65
67
  @base = opts[:source] if opts[:source]
66
- @config = Ruhoh::Config.generate(@names.config_data)
68
+ @config = Ruhoh::Config.generate
67
69
  !!@config
68
70
  end
69
71