ruhoh 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ class Ruhoh
7
7
  # Public: Generate the Pages dictionary.
8
8
  #
9
9
  def self.generate
10
- raise "Ruhoh.config cannot be nil.\n To set config call: Ruhoh.setup" unless Ruhoh.config
10
+ Ruhoh.ensure_setup
11
11
 
12
12
  pages = self.files
13
13
  invalid = []
@@ -15,7 +15,8 @@ class Ruhoh
15
15
 
16
16
  pages.each do |filename|
17
17
  id = self.make_id(filename)
18
- parsed_page = Ruhoh::Utils.parse_file(filename)
18
+ parsed_page = ''
19
+ FileUtils.cd(Ruhoh.paths.site_source) { parsed_page = Ruhoh::Utils.parse_file(filename) }
19
20
  if parsed_page.empty?
20
21
  error = "Invalid Yaml Front Matter.\n Ensure this page has valid YAML, even if it's empty."
21
22
  invalid << [filename, error] ; next
@@ -23,24 +24,12 @@ class Ruhoh
23
24
 
24
25
  parsed_page['data']['id'] = id
25
26
  parsed_page['data']['url'] = self.permalink(parsed_page['data'])
26
- parsed_page['data']['title'] = parsed_page['data']['title'] || self.titleize(filename)
27
+ parsed_page['data']['title'] = parsed_page['data']['title'] || self.to_title(filename)
27
28
 
28
29
  dictionary[id] = parsed_page['data']
29
30
  end
30
31
 
31
- report = "#{pages.count - invalid.count }/#{pages.count} pages processed."
32
-
33
- if pages.count.zero? && invalid.empty?
34
- Ruhoh::Friend.say { plain "0 pages to process." }
35
- elsif invalid.empty?
36
- Ruhoh::Friend.say { green report }
37
- else
38
- Ruhoh::Friend.say {
39
- yellow report
40
- list "Pages not processed:", invalid
41
- }
42
- end
43
-
32
+ Ruhoh::Utils.report('Pages', dictionary, invalid)
44
33
  dictionary
45
34
  end
46
35
 
@@ -65,14 +54,26 @@ class Ruhoh
65
54
  filename.gsub(Regexp.new("^#{Ruhoh.folders.pages}/"), '')
66
55
  end
67
56
 
68
- def self.titleize(filename)
57
+ def self.to_title(filename)
69
58
  name = File.basename( filename, File.extname(filename) )
70
59
  name = filename.split('/')[-2] if name == 'index' && !filename.index('/').nil?
71
60
  name.gsub(/[\W\_]/, ' ').gsub(/\b\w/){$&.upcase}
72
61
  end
73
62
 
63
+ # Build the permalink for the given page.
64
+ # Only recognize 'convertable' extensions for Markdown at the moment.
65
+ # This means 'non-convertable' extensions should pass-through.
66
+ #
67
+ # Returns [String] the permalink for this page.
74
68
  def self.permalink(page)
75
- url = '/' + page['id'].gsub(File.extname(page['id']), '.html')
69
+ ext = File.extname(page['id'])
70
+ url = '/'
71
+ url += if ['.md', '.markdown'].include?(ext)
72
+ page['id'].gsub(Regexp.new("#{ext}$"), '.html')
73
+ else
74
+ page['id']
75
+ end
76
+
76
77
  # sanitize url
77
78
  url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
78
79
  url.gsub!(/\/index.html$/, '')
@@ -2,18 +2,20 @@ class Ruhoh
2
2
  module Parsers
3
3
  module Posts
4
4
 
5
- MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
5
+ DateMatcher = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
6
+ Matcher = /^(.+\/)*(.*)(\.[^.]+)$/
6
7
 
7
8
  # Public: Generate the Posts dictionary.
8
9
  #
9
10
  def self.generate
10
- raise "Ruhoh.config cannot be nil.\n To set config call: Ruhoh.setup" unless Ruhoh.config
11
+ Ruhoh.ensure_setup
11
12
 
12
- dictionary = self.process
13
- ordered_posts = self.ordered_posts(dictionary)
13
+ results = self.process
14
+ ordered_posts = self.ordered_posts(results['posts'])
14
15
 
15
16
  {
16
- 'dictionary' => dictionary,
17
+ 'dictionary' => results['posts'],
18
+ 'drafts' => results['drafts'],
17
19
  'chronological' => self.build_chronology(ordered_posts),
18
20
  'collated' => self.collate(ordered_posts),
19
21
  'tags' => self.parse_tags(ordered_posts),
@@ -23,10 +25,12 @@ class Ruhoh
23
25
 
24
26
  def self.process
25
27
  dictionary = {}
28
+ drafts = []
26
29
  invalid = []
27
-
30
+
28
31
  self.files.each do |filename|
29
- parsed_page = Ruhoh::Utils.parse_file(filename)
32
+ parsed_page = ''
33
+ FileUtils.cd(Ruhoh.paths.site_source) { parsed_page = Ruhoh::Utils.parse_file(filename) }
30
34
  if parsed_page.empty?
31
35
  error = "Invalid YAML Front Matter. Ensure this page has valid YAML, even if it's empty."
32
36
  invalid << [filename, error] ; next
@@ -35,7 +39,7 @@ class Ruhoh
35
39
 
36
40
  filename_data = self.parse_filename(filename)
37
41
  if filename_data.empty?
38
- error = "Invalid Filename Format. Format should be: YYYY-MM-DD-my-post-title.ext"
42
+ error = "Invalid Filename Format. Format should be: my-post-title.ext"
39
43
  invalid << [filename, error] ; next
40
44
  end
41
45
 
@@ -45,7 +49,12 @@ class Ruhoh
45
49
  error = "Invalid Date Format. Date should be: YYYY-MM-DD"
46
50
  invalid << [filename, error] ; next
47
51
  end
48
-
52
+
53
+ if data['type'] == 'draft'
54
+ next if Ruhoh.config.env == 'production'
55
+ drafts << filename
56
+ end
57
+
49
58
  data['date'] = data['date'].to_s
50
59
  data['id'] = filename
51
60
  data['title'] = data['title'] || filename_data['title']
@@ -53,23 +62,12 @@ class Ruhoh
53
62
  dictionary[filename] = data
54
63
  end
55
64
 
56
- self.report(dictionary, invalid)
57
- dictionary
58
- end
59
-
60
-
61
- def self.process_file(filename)
62
- p = Ruhoh::Utils.parse_file(filename)
63
- filename_data = self.parse_filename(filename)
64
-
65
- if p['data']['title'].nil? || p['data']['title'].gsub(/\s/, '').empty?
66
- p['data']['title'] = filename_data['title'] || nil
67
- end
68
-
69
- p['data']['date'] ||= filename_data['date']
70
- p['data']['date'] = self.formatted_date(p['data']['date'] || Time.now)
65
+ Ruhoh::Utils.report('Posts', dictionary, invalid)
71
66
 
72
- p
67
+ {
68
+ "posts" => dictionary,
69
+ "drafts" => drafts
70
+ }
73
71
  end
74
72
 
75
73
  def self.formatted_date(date)
@@ -78,20 +76,6 @@ class Ruhoh
78
76
  false
79
77
  end
80
78
 
81
- def self.report(dictionary, invalid)
82
- output = "#{dictionary.count}/#{dictionary.count + invalid.count} posts processed."
83
- if dictionary.empty? && invalid.empty?
84
- Ruhoh::Friend.say { plain "0 posts to process." }
85
- elsif invalid.empty?
86
- Ruhoh::Friend.say { green output }
87
- else
88
- Ruhoh::Friend.say {
89
- yellow output
90
- list "Posts not processed:", invalid
91
- }
92
- end
93
- end
94
-
95
79
  def self.files
96
80
  FileUtils.cd(Ruhoh.paths.site_source) {
97
81
  return Dir["#{Ruhoh.folders.posts}/**/*.*"].select { |filename|
@@ -113,19 +97,30 @@ class Ruhoh
113
97
  end
114
98
 
115
99
  def self.parse_filename(filename)
116
- data = *filename.match(MATCHER)
100
+ data = *filename.match(DateMatcher)
101
+ data = *filename.match(Matcher) if data.empty?
117
102
  return {} if data.empty?
118
- {
119
- "path" => data[1],
120
- "date" => data[2],
121
- "slug" => data[3],
122
- "title" => self.titleize(data[3]),
123
- "extension" => data[4]
124
- }
103
+
104
+ if filename =~ DateMatcher
105
+ {
106
+ "path" => data[1],
107
+ "date" => data[2],
108
+ "slug" => data[3],
109
+ "title" => self.to_title(data[3]),
110
+ "extension" => data[4]
111
+ }
112
+ else
113
+ {
114
+ "path" => data[1],
115
+ "slug" => data[2],
116
+ "title" => self.to_title(data[2]),
117
+ "extension" => data[3]
118
+ }
119
+ end
125
120
  end
126
121
 
127
122
  # my-post-title ===> My Post Title
128
- def self.titleize(file_slug)
123
+ def self.to_title(file_slug)
129
124
  file_slug.gsub(/[\W\_]/, ' ').gsub(/\b\w/){$&.upcase}
130
125
  end
131
126
 
@@ -134,8 +129,9 @@ class Ruhoh
134
129
  title.downcase.strip.gsub(/\s/, '-').gsub(/[^\w-]/, '')
135
130
  end
136
131
 
132
+ # Used in the client implementation to turn a draft into a post.
137
133
  def self.to_filename(data)
138
- File.join(Ruhoh.paths.posts, "#{self.formatted_date(data['date'])}-#{self.to_slug(data['title'])}.#{data['ext']}")
134
+ File.join(Ruhoh.paths.posts, "#{self.to_slug(data['title'])}.#{data['ext']}")
139
135
  end
140
136
 
141
137
  # Another blatently stolen method from Jekyll
@@ -1,30 +1,26 @@
1
1
  class Ruhoh
2
-
3
2
  # Public: Rack application used to render singular pages via their URL.
4
3
  #
5
- # Examples
6
- #
7
- # In config.ru:
8
- #
9
- # require 'ruhoh'
10
- #
11
- # Ruhoh.setup
12
- # use Rack::Static, {:urls => ["/#{Ruhoh.folders.media}", "/#{Ruhoh.folders.templates}"]}
13
- # run Ruhoh::Previewer.new
4
+ # This class depends on a correctly loaded Ruhoh environment;
5
+ # it should only be used as part of a Ruhoh 'program' routine.
6
+ # See Ruhoh::Program for usage.
14
7
  #
15
8
  class Previewer
16
9
 
17
- def initialize
18
- Ruhoh::DB.update!
19
- @page = Ruhoh::Page.new
20
- Ruhoh::Watch.start
10
+ def initialize(page)
11
+ Ruhoh.config.env ||= 'development'
12
+ @page = page
21
13
  end
22
14
 
23
15
  def call(env)
24
16
  return favicon if env['PATH_INFO'] == '/favicon.ico'
25
- return drafts if ["/#{Ruhoh.folders.drafts}", "/#{Ruhoh.folders.drafts}/"].include?(env['PATH_INFO'])
17
+ dash = File.basename(Ruhoh.files.dashboard, File.extname(Ruhoh.files.dashboard))
18
+ return admin if ["/#{dash}", "/#{dash}/"].include?(env['PATH_INFO'])
26
19
 
27
- @page.change_with_url(env['PATH_INFO'])
20
+ id = Ruhoh::DB.routes[env['PATH_INFO']]
21
+ raise "Page id not found for url: #{env['PATH_INFO']}" unless id
22
+ @page.change(id)
23
+
28
24
  [200, {'Content-Type' => 'text/html'}, [@page.render]]
29
25
  end
30
26
 
@@ -32,30 +28,13 @@ class Ruhoh
32
28
  [200, {'Content-Type' => 'image/x-icon'}, ['']]
33
29
  end
34
30
 
35
- def drafts
36
- #tmpl = File.open(File.join(Ruhoh::Root, 'dashboard.html'))
37
- tmpl = File.open(File.join(Ruhoh.paths.site_source, 'dashboard.html'))
38
- template = tmpl.read
39
- tmpl.close
31
+ def admin
32
+ system_dash = File.join(Ruhoh::Root, Ruhoh.files.dashboard)
33
+ template = File.open(File.exist?(Ruhoh.paths.dashboard) ? Ruhoh.paths.dashboard : system_dash) {|f| f.read }
34
+ output = Ruhoh::Templaters::Base.parse(template, nil)
40
35
 
41
- drafts = []
42
- posts = []
43
- pages = []
44
- Ruhoh::DB.pages.each_value { |p| pages << p }
45
- Ruhoh::DB.drafts.each_value { |draft| drafts << draft }
46
- Ruhoh::DB.posts['dictionary'].each_value { |p| posts << p }
47
-
48
- #Ruhoh::Templaters::Base.parse(template)
49
- payload = {
50
- "drafts" => drafts,
51
- "posts" => posts,
52
- "pages" => pages,
53
- }
54
- output = Mustache.render(template, payload)
55
-
56
36
  [200, {'Content-Type' => 'text/html'}, [output]]
57
37
  end
58
-
38
+
59
39
  end #Previewer
60
-
61
40
  end #Ruhoh
@@ -0,0 +1,28 @@
1
+ class Ruhoh
2
+ module Program
3
+
4
+ # Public: A program for running ruhoh as a rack application
5
+ # which renders singular pages via their URL.
6
+ #
7
+ # Examples
8
+ #
9
+ # In config.ru:
10
+ #
11
+ # require 'ruhoh'
12
+ # run Ruhoh::Program.preview
13
+ #
14
+ # Returns: A new Rack builder object which should work inside config.ru
15
+ def self.preview(watch=true)
16
+ Ruhoh.setup
17
+ Ruhoh::DB.update_all
18
+ Ruhoh::Watch.start if watch
19
+ Rack::Builder.new {
20
+ use Rack::Lint
21
+ use Rack::ShowExceptions
22
+ use Rack::Static, {:urls => ["/#{Ruhoh.folders.media}", "/#{Ruhoh.folders.templates}"]}
23
+ run Ruhoh::Previewer.new(Ruhoh::Page.new)
24
+ }
25
+ end
26
+
27
+ end #Program
28
+ end #Ruhoh
data/lib/ruhoh/utils.rb CHANGED
@@ -9,9 +9,8 @@ class Ruhoh
9
9
  filepath = File.__send__ :join, args
10
10
  return nil unless File.exist? filepath
11
11
 
12
- file = File.open(filepath)
12
+ file = File.open(filepath, 'r:UTF-8') {|f| f.read }
13
13
  yaml = YAML.load(file) || {}
14
- file.close
15
14
  yaml
16
15
  rescue Psych::SyntaxError => e
17
16
  Ruhoh.log.error("ERROR in #{filepath}: #{e.message}")
@@ -23,7 +22,7 @@ class Ruhoh
23
22
 
24
23
  raise "File not found: #{path}" unless File.exist?(path)
25
24
 
26
- page = File.open(path).read
25
+ page = File.open(path, 'r:UTF-8') {|f| f.read }
27
26
  front_matter = page.match(FMregex)
28
27
 
29
28
  return {} unless front_matter
@@ -45,6 +44,21 @@ class Ruhoh
45
44
  data
46
45
  end
47
46
 
47
+
48
+ def self.report(name, collection, invalid)
49
+ output = "#{collection.count}/#{collection.count + invalid.count} #{name} processed."
50
+ if collection.empty? && invalid.empty?
51
+ Ruhoh::Friend.say { plain "0 #{name} to process." }
52
+ elsif invalid.empty?
53
+ Ruhoh::Friend.say { green output }
54
+ else
55
+ Ruhoh::Friend.say {
56
+ yellow output
57
+ list "#{name} not processed:", invalid
58
+ }
59
+ end
60
+ end
61
+
48
62
  end
49
63
 
50
64
  end #Ruhoh
data/lib/ruhoh/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class Ruhoh
2
- Version = VERSION = '0.1.3'
3
- RuhohSpec = '0.1'
2
+ Version = VERSION = '0.2.0'
3
+ RuhohSpec = '0.2'
4
4
  end
data/lib/ruhoh/watch.rb CHANGED
@@ -9,7 +9,7 @@ class Ruhoh
9
9
  #
10
10
  # Returns: Nothing
11
11
  def self.start
12
- raise "Ruhoh.config cannot be nil.\n To set config call: Ruhoh.setup" unless Ruhoh.config
12
+ Ruhoh.ensure_setup
13
13
  Ruhoh::Friend.say {
14
14
  plain "=> Start watching: #{Ruhoh.paths.site_source}"
15
15
  }
@@ -43,10 +43,6 @@ class Ruhoh
43
43
  type = "Posts"
44
44
  Ruhoh::DB.update(:posts)
45
45
  Ruhoh::DB.update(:routes)
46
- elsif path =~ Regexp.new("^\/?#{Ruhoh.folders.drafts}")
47
- type = "Drafts"
48
- Ruhoh::DB.update(:drafts)
49
- Ruhoh::DB.update(:routes)
50
46
  elsif path =~ Regexp.new("^\/?#{Ruhoh.folders.templates}")
51
47
  type = "Themes"
52
48
  Ruhoh::DB.update(:layouts)
data/lib/ruhoh.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+ Encoding.default_internal = 'UTF-8'
1
3
  require 'yaml'
2
4
  require 'psych'
3
5
  YAML::ENGINE.yamler = 'psych'
@@ -12,7 +14,6 @@ require 'mustache'
12
14
  require 'ruhoh/logger'
13
15
  require 'ruhoh/utils'
14
16
  require 'ruhoh/friend'
15
- require 'ruhoh/parsers/drafts'
16
17
  require 'ruhoh/parsers/posts'
17
18
  require 'ruhoh/parsers/pages'
18
19
  require 'ruhoh/parsers/routes'
@@ -27,6 +28,7 @@ require 'ruhoh/converters/converter'
27
28
  require 'ruhoh/page'
28
29
  require 'ruhoh/previewer'
29
30
  require 'ruhoh/watch'
31
+ require 'ruhoh/program'
30
32
 
31
33
  class Ruhoh
32
34
 
@@ -36,27 +38,15 @@ class Ruhoh
36
38
  end
37
39
 
38
40
  @log = Ruhoh::Logger.new
39
-
40
- Root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
41
- DefaultExclude = ['Gemfile', 'Gemfile.lock', 'config.ru', 'README.md']
42
- Folders = Struct.new(:database, :pages, :posts, :drafts, :templates, :themes, :layouts, :partials, :media, :syntax, :compiled)
43
- Files = Struct.new(:site, :config)
44
- Filters = Struct.new(:posts, :pages, :static)
45
- Config = Struct.new(:permalink, :theme, :theme_path, :media_path, :syntax_path, :exclude)
46
- Paths = Struct.new(
47
- :site_source,
48
- :database,
49
- :pages,
50
- :posts,
51
- :drafts,
52
- :theme,
53
- :layouts,
54
- :partials,
55
- :global_partials,
56
- :media,
57
- :syntax,
58
- :compiled
59
- )
41
+
42
+ Root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
43
+ Folders = Struct.new(:database, :pages, :posts, :templates, :themes, :layouts, :partials, :media, :syntax, :compiled)
44
+ Files = Struct.new(:site, :config, :dashboard)
45
+ Filters = Struct.new(:posts, :pages, :static)
46
+ Config = Struct.new(:permalink, :theme, :theme_path, :media_path, :syntax_path, :exclude, :env)
47
+ Paths = Struct.new(
48
+ :site_source, :database, :pages, :posts, :theme, :layouts, :partials, :global_partials, :media, :syntax,
49
+ :compiled, :dashboard)
60
50
 
61
51
 
62
52
  # Public: Setup Ruhoh utilities relative to the current application directory.
@@ -70,8 +60,8 @@ class Ruhoh
70
60
  end
71
61
 
72
62
  def self.reset
73
- @folders = Folders.new('_database', '_pages', '_posts', '_drafts', '_templates', 'themes', 'layouts', 'partials', "_media", "syntax", '_compiled')
74
- @files = Files.new('_site.yml', '_config.yml')
63
+ @folders = Folders.new('_database', '_pages', '_posts', '_templates', 'themes', 'layouts', 'partials', "_media", "syntax", '_compiled')
64
+ @files = Files.new('_site.yml', '_config.yml', 'dash.html')
75
65
  @filters = Filters.new
76
66
  @config = Config.new
77
67
  @paths = Paths.new
@@ -98,6 +88,8 @@ class Ruhoh
98
88
  @config.syntax_path = File.join('/', @folders.templates, @folders.syntax)
99
89
  @config.permalink = site_config['permalink']
100
90
  @config.exclude = Array(site_config['exclude'] || nil)
91
+ @config.env = site_config['env'] || nil
92
+ @config
101
93
  end
102
94
 
103
95
  def self.setup_paths
@@ -105,7 +97,6 @@ class Ruhoh
105
97
  @paths.database = self.absolute_path(@folders.database)
106
98
  @paths.pages = self.absolute_path(@folders.pages)
107
99
  @paths.posts = self.absolute_path(@folders.posts)
108
- @paths.drafts = self.absolute_path(@folders.drafts)
109
100
 
110
101
  @paths.theme = self.absolute_path(@folders.templates, @folders.themes, @config.theme)
111
102
  @paths.layouts = self.absolute_path(@folders.templates, @folders.themes, @config.theme, @folders.layouts)
@@ -114,12 +105,13 @@ class Ruhoh
114
105
  @paths.media = self.absolute_path(@folders.media)
115
106
  @paths.syntax = self.absolute_path(@folders.templates, @folders.syntax)
116
107
  @paths.compiled = self.absolute_path(@folders.compiled)
108
+ @paths.dashboard = self.absolute_path(@files.dashboard)
117
109
  @paths
118
110
  end
119
111
 
120
112
  # filename filters
121
113
  def self.setup_filters
122
- exclude = @config.exclude + DefaultExclude
114
+ exclude = @config.exclude
123
115
  exclude.uniq!
124
116
 
125
117
  @filters.pages = { 'names' => [], 'regexes' => [] }
@@ -138,4 +130,8 @@ class Ruhoh
138
130
  filename.gsub( Regexp.new("^#{self.paths.site_source}/"), '' )
139
131
  end
140
132
 
141
- end # Ruhoh
133
+ def self.ensure_setup
134
+ raise 'Ruhoh has not been setup. Please call: Ruhoh.setup' unless Ruhoh.config && Ruhoh.paths
135
+ end
136
+
137
+ end # Ruhoh
data/ruhoh.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency 'mustache', "~> 0.99"
19
19
  s.add_dependency 'directory_watcher', "~> 1.4"
20
20
  s.add_dependency 'maruku', "~> 0.6"
21
+ s.add_dependency 'psych', "~> 1.3"
21
22
 
22
23
  # = MANIFEST =
23
24
  s.files = %w[
@@ -25,6 +26,7 @@ Gem::Specification.new do |s|
25
26
  README.md
26
27
  Rakefile
27
28
  bin/ruhoh
29
+ dash.html
28
30
  history.txt
29
31
  lib/ruhoh.rb
30
32
  lib/ruhoh/client/client.rb
@@ -36,7 +38,6 @@ Gem::Specification.new do |s|
36
38
  lib/ruhoh/friend.rb
37
39
  lib/ruhoh/logger.rb
38
40
  lib/ruhoh/page.rb
39
- lib/ruhoh/parsers/drafts.rb
40
41
  lib/ruhoh/parsers/layouts.rb
41
42
  lib/ruhoh/parsers/pages.rb
42
43
  lib/ruhoh/parsers/partials.rb
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
44
45
  lib/ruhoh/parsers/routes.rb
45
46
  lib/ruhoh/parsers/site.rb
46
47
  lib/ruhoh/previewer.rb
48
+ lib/ruhoh/program.rb
47
49
  lib/ruhoh/templaters/base.rb
48
50
  lib/ruhoh/templaters/helpers.rb
49
51
  lib/ruhoh/templaters/rmustache.rb
data/scaffolds/post.html CHANGED
@@ -1,8 +1,10 @@
1
1
  ---
2
2
  title:
3
+ date: '{{DATE}}'
3
4
  description:
4
5
  categories:
5
6
  tags: []
6
7
 
7
8
  layout: post
9
+ type: draft
8
10
  ---
data/spec/db_spec.rb CHANGED
@@ -45,12 +45,6 @@ module DB
45
45
  Ruhoh::DB.posts.should == {'test' => 'hi'}
46
46
  end
47
47
 
48
- it "should run the drafts parser when updating :drafts" do
49
- Ruhoh::Parsers::Drafts.should_receive(:generate).and_return({'test' => 'hi'})
50
- Ruhoh::DB.update(:drafts)
51
- Ruhoh::DB.drafts.should == {'test' => 'hi'}
52
- end
53
-
54
48
  it "should run the pages parser when updating :pages" do
55
49
  Ruhoh::Parsers::Pages.should_receive(:generate).and_return({'test' => 'hi'})
56
50
  Ruhoh::DB.update(:pages)
@@ -70,16 +64,15 @@ module DB
70
64
  end
71
65
  end
72
66
 
73
- describe "#update!" do
67
+ describe "#update_all" do
74
68
  it "should call update for all WhiteListed variables." do
75
69
  Ruhoh::DB.should_receive(:update).with(:site).ordered
76
70
  Ruhoh::DB.should_receive(:update).with(:posts).ordered
77
- Ruhoh::DB.should_receive(:update).with(:drafts).ordered
78
71
  Ruhoh::DB.should_receive(:update).with(:pages).ordered
79
72
  Ruhoh::DB.should_receive(:update).with(:routes).ordered
80
73
  Ruhoh::DB.should_receive(:update).with(:layouts).ordered
81
74
  Ruhoh::DB.should_receive(:update).with(:partials).ordered
82
- Ruhoh::DB.update!
75
+ Ruhoh::DB.update_all
83
76
  end
84
77
  end
85
78
 
data/spec/page_spec.rb CHANGED
@@ -72,31 +72,6 @@ module Page
72
72
 
73
73
  end
74
74
 
75
- describe "#change_with_url" do
76
- let(:page){ Ruhoh::Page.new }
77
-
78
- context "An invalid URL" do
79
- it "should raise error" do
80
- lambda { page.change_with_url('/cool-url') }.should raise_error
81
- end
82
- end
83
-
84
- context "A valid URL" do
85
- let(:routes){
86
- { "/super/cool/page-id.html" => "page-id.md" }
87
- }
88
- before(:all) do
89
- Ruhoh::Parsers::Routes.stub(:generate).and_return(routes)
90
- Ruhoh::DB.update(:routes)
91
- end
92
-
93
- it "should call self.change with the proper id from the routes hash" do
94
- page.should_receive(:change).with("page-id.md")
95
- page.change_with_url("/super/cool/page-id.html")
96
- end
97
- end
98
- end
99
-
100
75
  describe "#render" do
101
76
  let(:page){ Ruhoh::Page.new }
102
77
  it "should raise error if id not set" do
@@ -5,9 +5,30 @@ module Layouts
5
5
  describe Ruhoh::Parsers::Layouts do
6
6
 
7
7
  before(:each) do
8
- Ruhoh::Utils.should_receive(:parse_file_as_yaml).and_return({'theme' => "twitter"})
8
+ expected_theme = "twitter"
9
+
10
+ Ruhoh::Utils.should_receive(:parse_file_as_yaml).and_return({'theme' => expected_theme})
9
11
  Ruhoh.setup(:source => SampleSitePath)
12
+
13
+ the_layouts_dir = File.join SampleSitePath, "_templates", "themes", expected_theme, "layouts"
14
+
15
+ FileUtils.remove_dir(the_layouts_dir, 1) if Dir.exists? the_layouts_dir
16
+ FileUtils.makedirs the_layouts_dir
17
+
18
+ expected_layouts.each do |layout_name|
19
+ full_file_name = File.join(the_layouts_dir, layout_name)
20
+
21
+ File.open full_file_name, "w+" do |file|
22
+ file.puts <<-TEXT
23
+ ---
24
+ title: #{layout_name} (test)
25
+ ---
26
+ TEXT
27
+ end
28
+ end
10
29
  end
30
+
31
+ let(:expected_layouts) { %w{default.html page.html post.html} }
11
32
 
12
33
  describe "#generate" do
13
34
  let(:layouts){
@@ -29,4 +50,4 @@ module Layouts
29
50
 
30
51
  end
31
52
 
32
- end
53
+ end