ruhoh 0.3.0 → 1.0.0.alpha

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/Gemfile +1 -0
  2. data/README.md +0 -33
  3. data/dash.html +1 -0
  4. data/history.json +29 -0
  5. data/lib/ruhoh/client/client.rb +30 -22
  6. data/lib/ruhoh/client/help.yml +6 -2
  7. data/lib/ruhoh/compiler.rb +8 -20
  8. data/lib/ruhoh/compilers/rss.rb +36 -0
  9. data/lib/ruhoh/compilers/theme.rb +41 -0
  10. data/lib/ruhoh/config.rb +49 -0
  11. data/lib/ruhoh/converters/converter.rb +17 -4
  12. data/lib/ruhoh/converters/markdown.rb +2 -2
  13. data/lib/ruhoh/db.rb +29 -2
  14. data/lib/ruhoh/deployers/s3.rb +1 -1
  15. data/lib/ruhoh/logger.rb +1 -1
  16. data/lib/ruhoh/page.rb +38 -22
  17. data/lib/ruhoh/parsers/javascripts.rb +67 -0
  18. data/lib/ruhoh/parsers/layouts.rb +6 -10
  19. data/lib/ruhoh/parsers/pages.rb +17 -24
  20. data/lib/ruhoh/parsers/partials.rb +6 -14
  21. data/lib/ruhoh/parsers/payload.rb +47 -0
  22. data/lib/ruhoh/parsers/posts.rb +27 -29
  23. data/lib/ruhoh/parsers/site.rb +2 -2
  24. data/lib/ruhoh/parsers/stylesheets.rb +75 -0
  25. data/lib/ruhoh/parsers/widgets.rb +104 -0
  26. data/lib/ruhoh/paths.rb +75 -0
  27. data/lib/ruhoh/previewer.rb +11 -5
  28. data/lib/ruhoh/program.rb +35 -4
  29. data/lib/ruhoh/templaters/asset_helpers.rb +66 -0
  30. data/lib/ruhoh/templaters/base_helpers.rb +143 -0
  31. data/lib/ruhoh/templaters/helpers.rb +1 -148
  32. data/lib/ruhoh/templaters/rmustache.rb +45 -4
  33. data/lib/ruhoh/urls.rb +46 -0
  34. data/lib/ruhoh/utils.rb +59 -17
  35. data/lib/ruhoh/version.rb +2 -2
  36. data/lib/ruhoh/watch.rb +26 -14
  37. data/lib/ruhoh.rb +38 -96
  38. data/ruhoh.gemspec +29 -10
  39. data/scaffolds/draft.html +9 -0
  40. data/scaffolds/page.html +0 -2
  41. data/scaffolds/post.html +0 -4
  42. data/scaffolds/theme/{images → javascripts}/.gitkeep +0 -0
  43. data/scaffolds/theme/layouts/default.html +2 -4
  44. data/scaffolds/theme/layouts/page.html +1 -1
  45. data/scaffolds/theme/layouts/post.html +1 -1
  46. data/scaffolds/theme/{css/style.css → media/.gitkeep} +0 -0
  47. data/scaffolds/theme/stylesheets/style.css +0 -0
  48. data/scaffolds/theme/theme.yml +27 -0
  49. data/scaffolds/theme/widgets/.gitkeep +0 -0
  50. data/spec/config_spec.rb +50 -0
  51. data/spec/db_spec.rb +28 -14
  52. data/spec/page_spec.rb +24 -35
  53. data/spec/parsers/layouts_spec.rb +5 -13
  54. data/spec/parsers/pages_spec.rb +13 -11
  55. data/spec/parsers/posts_spec.rb +34 -29
  56. data/spec/parsers/routes_spec.rb +2 -1
  57. data/spec/parsers/site_spec.rb +6 -5
  58. data/spec/setup_spec.rb +3 -47
  59. data/widgets/analytics/config.yml +5 -0
  60. data/{system_partials/analytics/getclicky → widgets/analytics/layouts/getclicky.html} +2 -2
  61. data/{system_partials/analytics/google → widgets/analytics/layouts/google.html} +1 -1
  62. data/widgets/comments/config.yml +12 -0
  63. data/{system_partials/comments/disqus → widgets/comments/layouts/disqus.html} +2 -2
  64. data/{system_partials/comments/facebook → widgets/comments/layouts/facebook.html} +1 -1
  65. data/{system_partials/comments/intensedebate → widgets/comments/layouts/intensedebate.html} +1 -1
  66. data/{system_partials/comments/livefyre → widgets/comments/layouts/livefyre.html} +1 -1
  67. data/widgets/google_prettify/config.yml +1 -0
  68. data/widgets/google_prettify/layouts/google_prettify.html +10 -0
  69. metadata +54 -31
  70. data/lib/ruhoh/templaters/base.rb +0 -57
  71. data/system_partials/syntax/google_prettify +0 -11
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem 'rack', "~> 1.4"
5
5
  gem 'directory_watcher', "~> 1.4"
6
6
  gem 'psych', "~> 1.3"
7
7
  gem 'redcarpet', "~> 2.1"
8
+ gem 'nokogiri', "~> 1.5"
8
9
 
9
10
  group :development do
10
11
  gem 'rspec'
data/README.md CHANGED
@@ -7,36 +7,3 @@
7
7
 
8
8
  $ gem install ruhoh
9
9
  $ ruhoh help
10
-
11
-
12
- - setup
13
- - database
14
- - page
15
- - templater
16
- - converter
17
- - preview
18
- - compiler
19
-
20
- ### Plugins
21
-
22
-
23
- 1. Mustache method additions
24
- Extend the templating language
25
- * Mounted onto the page object
26
-
27
-
28
- 2. Add additional converter support (textile)
29
- * Mounted onto the page object
30
-
31
- 3. Generators ? compose extra pages?
32
- I'm leaning toward why? any page should be able to be made
33
- by calling a custom mustache method within a given textfile.
34
- Jekyll's relevant example is to create mass-pages per each category.
35
- Generating extra pages can be mounted onto the compiler
36
-
37
-
38
-
39
-
40
-
41
-
42
-
data/dash.html CHANGED
@@ -1,6 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
+ <meta charset="utf-8">
4
5
  <style type="text/css">
5
6
  /*!
6
7
  * Bootstrap v2.0.2
data/history.json CHANGED
@@ -1,4 +1,33 @@
1
1
  [
2
+ {
3
+ "version" : "1.0.0.alpha",
4
+ "date" : "05.06.2012",
5
+ "changes" : [
6
+ "Converters now take in (content, id), rather than page object: (page).",
7
+ "Client now has both post and draft generation. Optionally can pass in a title.",
8
+ "Change config format for pages and posts; now must be namespaced respectively.",
9
+ "Major changes to theme directory API",
10
+ "Re-implement how internal config, path, and url parameters are generated and accessed.",
11
+ "Payload object 'paths' is now 'urls' and namespaced with theme_* for consistency",
12
+ "Master and sub layout templating is now handled entirely by mustache.",
13
+ "Add nokogiri as dependency"
14
+ ],
15
+ "features" : [
16
+ "YAML meta-data is now optional",
17
+ "Provide default, global layout attribute for post/page",
18
+ "Add summary and posts_latest helper methods",
19
+ "Add widget system",
20
+ "Add stylesheets asset manager",
21
+ "Add javascripts asset manager",
22
+ "Add RSS compiler",
23
+ "Add ability to run previewer in production mode",
24
+ "Make post filename available to permalink"
25
+ ],
26
+ "bugs" : [
27
+ "Fix permalinks and titlelize methods to support international characters",
28
+ "Transform all extensions registered in a convertable module to .html"
29
+ ]
30
+ },
2
31
  {
3
32
  "version" : "0.3.0",
4
33
  "date" : "13.5.2012",
@@ -3,7 +3,7 @@ require 'ruhoh/compiler'
3
3
  class Ruhoh
4
4
  class Client
5
5
 
6
- Paths = Struct.new(:page_template, :post_template, :layout_template, :theme_template)
6
+ Paths = Struct.new(:page_template, :draft_template, :post_template, :layout_template, :theme_template)
7
7
  BlogScaffold = 'git://github.com/ruhoh/blog.git'
8
8
 
9
9
  def initialize(data)
@@ -17,7 +17,7 @@ class Ruhoh
17
17
  exit
18
18
  } unless self.respond_to?(cmd)
19
19
 
20
- Ruhoh.setup unless ['help','blog'].include?(cmd)
20
+ Ruhoh.setup unless ['help','blog','compile'].include?(cmd)
21
21
 
22
22
  self.__send__(cmd)
23
23
  end
@@ -32,6 +32,7 @@ class Ruhoh
32
32
  def setup_paths
33
33
  @paths = Paths.new
34
34
  @paths.page_template = File.join(Ruhoh::Root, "scaffolds", "page.html")
35
+ @paths.draft_template = File.join(Ruhoh::Root, "scaffolds", "draft.html")
35
36
  @paths.post_template = File.join(Ruhoh::Root, "scaffolds", "post.html")
36
37
  @paths.layout_template = File.join(Ruhoh::Root, "scaffolds", "layout.html")
37
38
  @paths.theme_template = File.join(Ruhoh::Root, "scaffolds", "theme")
@@ -40,7 +41,7 @@ class Ruhoh
40
41
  # Internal: Show Client Utility help documentation.
41
42
  def help
42
43
  file = File.join(Ruhoh::Root, 'lib', 'ruhoh', 'client', 'help.yml')
43
- content = Ruhoh::Utils.parse_file_as_yaml(file)
44
+ content = Ruhoh::Utils.parse_yaml_file(file)
44
45
  options = @opt_parser.help
45
46
  Ruhoh::Friend.say {
46
47
  plain content['description']
@@ -56,27 +57,35 @@ class Ruhoh
56
57
  }
57
58
  end
58
59
 
59
- # Public: Create a new draft file.
60
- # Requires no settings as it is meant to be fastest way to create content.
61
60
  def draft
61
+ self.draft_or_post(:draft)
62
+ end
63
+
64
+ def post
65
+ self.draft_or_post(:post)
66
+ end
67
+
68
+ def draft_or_post(type)
62
69
  begin
63
- filename = File.join(Ruhoh.paths.posts, "untitled-#{@iterator}.#{@options.ext}")
70
+ name = @args[1] || "untitled-#{type}"
71
+ name = "#{name}-#{@iterator}" unless @iterator.zero?
72
+ name = Ruhoh::Urls.to_slug(name)
73
+ filename = File.join(Ruhoh.paths.posts, "#{name}.#{@options.ext}")
64
74
  @iterator += 1
65
75
  end while File.exist?(filename)
66
76
 
67
77
  FileUtils.mkdir_p File.dirname(filename)
68
78
 
69
- output = File.open(@paths.post_template) { |f| f.read }
79
+ output = File.open(@paths.send("#{type}_template"), 'r:UTF-8') { |f| f.read }
70
80
  output = output.gsub('{{DATE}}', Ruhoh::Parsers::Posts.formatted_date(Time.now))
71
- File.open(filename, 'w') {|f| f.puts output }
81
+ File.open(filename, 'w:UTF-8') {|f| f.puts output }
72
82
 
73
83
  Ruhoh::Friend.say {
74
- green "New draft:"
75
- green Ruhoh.relative_path(filename)
84
+ green "New #{type}:"
85
+ green Ruhoh::Utils.relative_path(filename)
76
86
  green 'View drafts at the URL: /dash'
77
87
  }
78
88
  end
79
- alias_method :post, :draft
80
89
 
81
90
  # Public: Create a new page file.
82
91
  def page
@@ -94,15 +103,15 @@ class Ruhoh
94
103
  end
95
104
 
96
105
  FileUtils.mkdir_p File.dirname(filename)
97
- File.open(@paths.page_template) do |template|
98
- File.open(filename, 'w') do |page|
106
+ File.open(@paths.page_template, 'r:UTF-8') do |template|
107
+ File.open(filename, 'w:UTF-8') do |page|
99
108
  page.puts template.read
100
109
  end
101
110
  end
102
111
 
103
112
  Ruhoh::Friend.say {
104
113
  green "New page:"
105
- plain Ruhoh.relative_path(filename)
114
+ plain Ruhoh::Utils.relative_path(filename)
106
115
  }
107
116
  end
108
117
 
@@ -110,9 +119,9 @@ class Ruhoh
110
119
  def titleize
111
120
  Ruhoh::Parsers::Posts.files.each do |file|
112
121
  next unless File.basename(file) =~ /^untitled/
113
- parsed_page = Ruhoh::Utils.parse_file(file)
122
+ parsed_page = Ruhoh::Utils.parse_page_file(file)
114
123
  next unless parsed_page['data']['title']
115
- new_name = Ruhoh::Parsers::Posts.to_slug(parsed_page['data']['title'])
124
+ new_name = Ruhoh::Urls.to_slug(parsed_page['data']['title'])
116
125
  new_file = File.join(File.dirname(file), "#{new_name}#{File.extname(file)}")
117
126
  FileUtils.mv(file, new_file)
118
127
  Ruhoh::Friend.say { green "Renamed #{file} to: #{new_file}" }
@@ -121,8 +130,7 @@ class Ruhoh
121
130
 
122
131
  # Public: Compile to static website.
123
132
  def compile
124
- Ruhoh::DB.update_all
125
- Ruhoh::Compiler.compile(@args[1])
133
+ Ruhoh::Program.compile(@args[1])
126
134
  end
127
135
 
128
136
  # Public: Create a new blog at the directory provided.
@@ -191,21 +199,21 @@ class Ruhoh
191
199
  exit
192
200
  } if name.nil?
193
201
 
194
- filename = File.join(Ruhoh.paths.layouts, name.gsub(/\s/, '-').downcase) + ".html"
202
+ filename = File.join(Ruhoh.paths.theme_layouts, name.gsub(/\s/, '-').downcase) + ".html"
195
203
  if File.exist?(filename)
196
204
  abort("Create new layout: aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
197
205
  end
198
206
 
199
207
  FileUtils.mkdir_p File.dirname(filename)
200
208
  File.open(@paths.layout_template) do |template|
201
- File.open(filename, 'w') do |page|
209
+ File.open(filename, 'w:UTF-8') do |page|
202
210
  page.puts template.read
203
211
  end
204
212
  end
205
213
 
206
214
  Ruhoh::Friend.say {
207
215
  green "New layout:"
208
- plain Ruhoh.relative_path(filename)
216
+ plain Ruhoh::Utils.relative_path(filename)
209
217
  }
210
218
  end
211
219
 
@@ -229,7 +237,7 @@ class Ruhoh
229
237
  require 'pp'
230
238
  Ruhoh::DB.update_all
231
239
  Ruhoh::Friend.say {
232
- plain Ruhoh::Templaters::Base.build_payload.pretty_inspect
240
+ plain Ruhoh::DB.payload.pretty_inspect
233
241
  }
234
242
  end
235
243
 
@@ -15,9 +15,13 @@ commands:
15
15
  "desc" : |
16
16
  Compile to static website.
17
17
  -
18
- "command" : "post | draft"
18
+ "command" : "draft <title>"
19
19
  "desc" : |
20
- Create a new draft.
20
+ Create a new draft. Post title is optional.
21
+ -
22
+ "command" : "post <title>"
23
+ "desc" : |
24
+ Create a new post. Post title is optional.
21
25
  -
22
26
  "command" : "page <path>"
23
27
  "desc" : |
@@ -1,11 +1,13 @@
1
+ require 'ruhoh/compilers/theme'
2
+ require 'ruhoh/compilers/rss'
3
+
1
4
  class Ruhoh
2
5
  module Compiler
3
6
 
4
7
  # TODO: seems rather dangerous to delete the incoming target directory?
5
8
  def self.compile(target_directory = nil, page = nil)
6
- Ruhoh.config.env ||= 'production'
7
9
  Ruhoh::Friend.say { plain "Compiling for environment: '#{Ruhoh.config.env}'" }
8
- target = target_directory || "./#{Ruhoh.folders.compiled}"
10
+ target = target_directory || "./#{Ruhoh.names.compiled}"
9
11
  page = page || Ruhoh::Page.new
10
12
 
11
13
  FileUtils.rm_r target if File.exist?(target)
@@ -23,9 +25,7 @@ class Ruhoh
23
25
 
24
26
  def self.run(target, page)
25
27
  self.pages(target, page)
26
- self.theme(target, page)
27
28
  self.media(target, page)
28
- self.syntax(target, page)
29
29
  end
30
30
 
31
31
  def self.pages(target, page)
@@ -40,24 +40,12 @@ class Ruhoh
40
40
  end
41
41
  }
42
42
  end
43
-
44
- def self.theme(target, page)
45
- return unless FileTest.directory? Ruhoh.paths.theme
46
- FileUtils.mkdir_p File.join(target, Ruhoh.config.theme_path)
47
- FileUtils.cp_r Ruhoh.paths.theme, File.join(target, Ruhoh.folders.templates, Ruhoh.folders.themes)
48
- end
49
-
43
+
50
44
  def self.media(target, page)
51
45
  return unless FileTest.directory? Ruhoh.paths.media
52
- FileUtils.mkdir_p File.join(target, Ruhoh.folders.media)
53
- FileUtils.cp_r Ruhoh.paths.media, target
54
- end
55
-
56
- def self.syntax(target, page)
57
- return unless FileTest.directory? Ruhoh.paths.syntax
58
- syntax_path = File.join(target, Ruhoh.folders.templates, Ruhoh.folders.syntax)
59
- FileUtils.mkdir_p syntax_path
60
- FileUtils.cp_r "#{Ruhoh.paths.syntax}/.", syntax_path
46
+ media = Ruhoh::Utils.url_to_path(Ruhoh.urls.media, target)
47
+ FileUtils.mkdir_p media
48
+ FileUtils.cp_r File.join(Ruhoh.paths.media, '.'), media
61
49
  end
62
50
 
63
51
  end #Defaults
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+ class Ruhoh
3
+ module Compiler
4
+ # This rss compiler is provided by David Long
5
+ # http://www.davejlong.com/
6
+ # https://github.com/davejlong
7
+ # Thanks David!
8
+ module Rss
9
+ # TODO: This renders the page content even though we already need to
10
+ # render the content to save to disk. This will be a problem when
11
+ # posts numbers expand. Merge this in later.
12
+ def self.run(target, page)
13
+ feed = Nokogiri::XML::Builder.new do |xml|
14
+ xml.rss(:version => '2.0') {
15
+ xml.channel {
16
+ xml.title_ Ruhoh::DB.site['title']
17
+ xml.link_ Ruhoh::DB.site['config']['production_url']
18
+ xml.pubDate_ Time.now
19
+ Ruhoh::DB.posts['chronological'].each do |post_id|
20
+ post = Ruhoh::DB.posts['dictionary'][post_id]
21
+ page.change(post_id)
22
+ xml.item {
23
+ xml.title_ post['title']
24
+ xml.link "#{Ruhoh::DB.site['config']['production_url']}#{post['url']}"
25
+ xml.pubDate_ post['date']
26
+ xml.description_ (post['description'] ? post['description'] : page.render)
27
+ }
28
+ end
29
+ }
30
+ }
31
+ end
32
+ File.open(File.join(target, 'rss.xml'), 'w'){ |p| p.puts feed.to_xml }
33
+ end
34
+ end #Rss
35
+ end #Compiler
36
+ end #Ruhoh
@@ -0,0 +1,41 @@
1
+ class Ruhoh
2
+ module Compiler
3
+ module Theme
4
+
5
+ def self.run(target, page)
6
+ self.stylesheets(target, page)
7
+ self.javascripts(target, page)
8
+ self.media(target, page)
9
+ end
10
+
11
+ def self.stylesheets(target, page)
12
+ Ruhoh::DB.stylesheets.each do |type, assets|
13
+ assets.each do |asset|
14
+ next unless File.exist?(asset['id'])
15
+ file_path = Ruhoh::Utils.url_to_path(File.dirname(asset['url']), target)
16
+ FileUtils.mkdir_p file_path
17
+ FileUtils.cp(asset['id'], file_path)
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.javascripts(target, page)
23
+ Ruhoh::DB.javascripts.each do |type, assets|
24
+ assets.each do |asset|
25
+ next unless File.exist?(asset['id'])
26
+ file_path = Ruhoh::Utils.url_to_path(File.dirname(asset['url']), target)
27
+ FileUtils.mkdir_p file_path
28
+ FileUtils.cp(asset['id'], file_path)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.media(target, page)
34
+ return unless FileTest.directory? Ruhoh.paths.theme_media
35
+ theme_media = Ruhoh::Utils.url_to_path(Ruhoh.urls.theme_media, target)
36
+ FileUtils.mkdir_p theme_media
37
+ FileUtils.cp_r File.join(Ruhoh.paths.theme_media, '.'), theme_media
38
+ end
39
+ end #Theme
40
+ end #Compiler
41
+ end #Ruhoh
@@ -0,0 +1,49 @@
1
+ class Ruhoh
2
+ # Structured container for global configuration parameters.
3
+ module Config
4
+ Config = Struct.new(
5
+ :env,
6
+ :pages_exclude,
7
+ :pages_permalink,
8
+ :pages_layout,
9
+ :posts_exclude,
10
+ :posts_layout,
11
+ :posts_permalink,
12
+ :theme
13
+ )
14
+
15
+ def self.generate(path_to_config)
16
+ site_config = Ruhoh::Utils.parse_yaml_file(path_to_config)
17
+ unless site_config
18
+ Ruhoh.log.error("Empty site_config.\nEnsure ./#{Ruhoh.names.config_data} exists and contains valid YAML")
19
+ return false
20
+ end
21
+
22
+ theme = site_config['theme'] ? site_config['theme'].to_s.gsub(/\s/, '') : ''
23
+ if theme.empty?
24
+ Ruhoh.log.error("Theme not specified in #{Ruhoh.names.config_data}")
25
+ return false
26
+ end
27
+
28
+ config = Config.new
29
+ config.theme = theme
30
+ config.env = site_config['env'] || nil
31
+
32
+ config.posts_permalink = site_config['posts']['permalink'] rescue nil
33
+ config.posts_layout = site_config['posts']['layout'] rescue nil
34
+ config.posts_layout = 'post' if config.posts_layout.nil?
35
+ excluded_posts = site_config['posts']['exclude'] rescue nil
36
+ config.posts_exclude = Array(excluded_posts)
37
+ config.posts_exclude = config.posts_exclude.map {|node| Regexp.new(node) }
38
+
39
+ config.pages_permalink = site_config['pages']['permalink'] rescue nil
40
+ config.pages_layout = site_config['pages']['layout'] rescue nil
41
+ config.pages_layout = 'page' if config.pages_layout.nil?
42
+ excluded_pages = site_config['pages']['exclude'] rescue nil
43
+ config.pages_exclude = Array(excluded_pages)
44
+ config.pages_exclude = config.pages_exclude.map {|node| Regexp.new(node) }
45
+
46
+ config
47
+ end
48
+ end #Config
49
+ end #Ruhoh
@@ -1,18 +1,31 @@
1
+ require 'ruhoh/converters/markdown'
2
+
1
3
  class Ruhoh
2
4
  module Converter
3
5
 
4
- def self.convert(page)
5
- extension = File.extname(page.data['id']).downcase
6
+ def self.convert(content, id)
7
+ extension = File.extname(id).downcase
6
8
 
7
9
  Ruhoh::Converter.constants.each {|c|
8
10
  converter = Ruhoh::Converter.const_get(c)
9
11
  next unless converter.respond_to?(:convert)
10
12
  next unless converter.respond_to?(:extensions)
11
13
  next unless Array(converter.extensions).include?(extension)
12
- return converter.convert(page)
14
+ return converter.convert(content)
13
15
  }
14
16
 
15
- page.content
17
+ content
18
+ end
19
+
20
+ # Return an Array of all regestered extensions
21
+ def self.extensions
22
+ collection = []
23
+ Ruhoh::Converter.constants.each {|c|
24
+ converter = Ruhoh::Converter.const_get(c)
25
+ next unless converter.respond_to?(:extensions)
26
+ collection += Array(converter.extensions)
27
+ }
28
+ collection
16
29
  end
17
30
 
18
31
  end #Converter
@@ -6,13 +6,13 @@ class Ruhoh
6
6
  ['.md', '.markdown']
7
7
  end
8
8
 
9
- def self.convert(page)
9
+ def self.convert(content)
10
10
  require 'redcarpet'
11
11
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(:with_toc_data => true),
12
12
  :autolink => true,
13
13
  :fenced_code_blocks => true,
14
14
  )
15
- markdown.render(page.content)
15
+ markdown.render(content)
16
16
  end
17
17
  end
18
18
  end
data/lib/ruhoh/db.rb CHANGED
@@ -1,8 +1,20 @@
1
+ require 'ruhoh/parsers/posts'
2
+ require 'ruhoh/parsers/pages'
3
+ require 'ruhoh/parsers/routes'
4
+ require 'ruhoh/parsers/layouts'
5
+ require 'ruhoh/parsers/partials'
6
+ require 'ruhoh/parsers/widgets'
7
+ require 'ruhoh/parsers/stylesheets'
8
+ require 'ruhoh/parsers/javascripts'
9
+ require 'ruhoh/parsers/payload'
10
+ require 'ruhoh/parsers/site'
11
+
1
12
  class Ruhoh
2
13
  # Public: Database class for interacting with "data" in Ruhoh.
3
14
  class DB
15
+ WhiteList = [:site, :posts, :pages, :routes, :layouts, :partials, :widgets, :stylesheets, :javascripts, :payload]
16
+
4
17
  class << self
5
- WhiteList = [:site, :posts, :pages, :routes, :layouts, :partials]
6
18
  self.__send__ :attr_reader, *WhiteList
7
19
 
8
20
  def update(name)
@@ -20,19 +32,34 @@ class Ruhoh
20
32
  Ruhoh::Parsers::Layouts.generate
21
33
  when :partials
22
34
  Ruhoh::Parsers::Partials.generate
35
+ when :widgets
36
+ Ruhoh::Parsers::Widgets.generate
37
+ when :stylesheets
38
+ Ruhoh::Parsers::Stylesheets.generate
39
+ when :javascripts
40
+ Ruhoh::Parsers::Javascripts.generate
41
+ when :payload
42
+ Ruhoh::Parsers::Payload.generate
23
43
  else
24
44
  raise "Data type: '#{name}' is not a valid data type."
25
45
  end
26
46
  )
27
47
  end
28
48
 
49
+ # Always regenerate a fresh payload since it
50
+ # references other generated data.
51
+ def payload
52
+ self.update(:payload)
53
+ @payload
54
+ end
55
+
29
56
  def all_pages
30
57
  self.posts['dictionary'].merge(self.pages)
31
58
  end
32
59
 
33
60
  def update_all
34
61
  WhiteList.each do |var|
35
- self.__send__ :update, var
62
+ self.__send__(:update, var)
36
63
  end
37
64
  end
38
65
 
@@ -9,7 +9,7 @@ class Ruhoh
9
9
  class AmazonS3 < AWS::S3::S3Object
10
10
 
11
11
  def initialize
12
- credentials = Ruhoh::Utils.parse_file_as_yaml(Ruhoh.paths.site_source, "_deploy.yml")['s3']
12
+ credentials = Ruhoh::Utils.parse_yaml_file(Ruhoh.paths.base, "_deploy.yml")['s3']
13
13
  self.connect(credentials)
14
14
  self.ensure_bucket(credentials["bucket"])
15
15
  #set_current_bucket_to(credentials["bucket"])
data/lib/ruhoh/logger.rb CHANGED
@@ -26,7 +26,7 @@ class Ruhoh
26
26
 
27
27
  def to_file
28
28
  return unless self.log_file && @buffer.size > 0
29
- File.open(self.log_file, "a") { |f|
29
+ File.open(self.log_file, 'a:UTF-8') { |f|
30
30
  f.puts '---'
31
31
  f.puts Time.now.utc
32
32
  f.puts @buffer.slice!(0..-1).join
data/lib/ruhoh/page.rb CHANGED
@@ -1,21 +1,20 @@
1
1
  class Ruhoh
2
2
  class Page
3
- attr_reader :id, :data, :content, :sub_layout, :master_layout
4
- attr_accessor :templater, :converter
3
+ attr_reader :id, :data, :sub_layout, :master_layout
4
+ attr_accessor :templater
5
5
 
6
6
  def initialize
7
- @templater = Ruhoh::Templaters::Base
8
- @converter = Ruhoh::Converter
7
+ @templater = Ruhoh::Templaters::RMustache
9
8
  end
10
9
 
11
10
  # Public: Change this page using an id.
12
11
  def change(id)
13
12
  self.reset
14
13
  @path = id
15
- @data = if id =~ Regexp.new("^#{Ruhoh.folders.posts}")
14
+ @data = if id =~ Regexp.new("^#{Ruhoh.names.posts}")
16
15
  Ruhoh::DB.posts['dictionary'][id]
17
16
  else
18
- @path = "#{Ruhoh.folders.pages}/#{id}"
17
+ @path = "#{Ruhoh.names.pages}/#{id}"
19
18
  Ruhoh::DB.pages[id]
20
19
  end
21
20
 
@@ -26,8 +25,7 @@ class Ruhoh
26
25
  def render
27
26
  self.ensure_id
28
27
  self.process_layouts
29
- self.process_content
30
- @templater.render(self)
28
+ @templater.render(self.expand_layouts, self.payload)
31
29
  end
32
30
 
33
31
  def process_layouts
@@ -41,26 +39,44 @@ class Ruhoh
41
39
  @master_layout = Ruhoh::DB.layouts[@sub_layout['data']['layout']]
42
40
  raise "Layout does not exist: #{@sub_layout['data']['layout']}" unless @master_layout
43
41
  end
42
+
43
+ @data['sub_layout'] = @sub_layout['id'] rescue nil
44
+ @data['master_layout'] = @master_layout['id'] rescue nil
45
+ @data
44
46
  end
45
47
 
46
- # We need to pre-process the content data
47
- # in order to invoke converters on the result.
48
- # Converters (markdown) always choke on the templating language.
49
- def process_content
50
- self.ensure_id
51
- data = Ruhoh::Utils.parse_file(Ruhoh.paths.site_source, @path)
52
- raise "Invalid Frontmatter in page: #{@path}" if data.empty?
48
+ # Expand the layout(s).
49
+ # Pages may have a single master_layout, a master_layout + sub_layout, or no layout.
50
+ def expand_layouts
51
+ if @sub_layout
52
+ layout = @sub_layout['content']
53
+
54
+ # If a master_layout is found we need to process the sub_layout
55
+ # into the master_layout using mustache.
56
+ if @master_layout && @master_layout['content']
57
+ payload = self.payload
58
+ payload['content'] = layout
59
+ layout = @templater.render(@master_layout['content'], payload)
60
+ end
61
+ else
62
+ # Minimum layout if no layout defined.
63
+ layout = '{{{content}}}'
64
+ end
53
65
 
54
- @content = @templater.parse(data['content'], self)
55
- @content = @converter.convert(self)
66
+ layout
56
67
  end
57
68
 
58
- # Public: Return page attributes suitable for inclusion in the
59
- # 'payload' of the given templater.
60
- def attributes
69
+ def payload
61
70
  self.ensure_id
62
- @data['content'] = @content
63
- @data
71
+ payload = Ruhoh::DB.payload.dup
72
+ payload['page'] = @data
73
+ payload
74
+ end
75
+
76
+ # Provide access to the page content.
77
+ def content
78
+ self.ensure_id
79
+ Ruhoh::Utils.parse_page_file(Ruhoh.paths.base, @path)['content']
64
80
  end
65
81
 
66
82
  # Public: Formats the path to the compiled file based on the URL.