ruhoh 1.1 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/README.md +3 -2
- data/Rakefile +1 -22
- data/bin/ruhoh +1 -5
- data/history.json +16 -0
- data/lib/ruhoh.rb +229 -84
- data/lib/ruhoh/base/collection.rb +280 -0
- data/lib/ruhoh/base/compiler.rb +55 -0
- data/lib/ruhoh/base/model.rb +220 -0
- data/lib/ruhoh/base/model_view.rb +152 -0
- data/lib/ruhoh/base/watcher.rb +25 -0
- data/lib/ruhoh/cache.rb +46 -0
- data/lib/ruhoh/client.rb +162 -0
- data/lib/ruhoh/collections.rb +172 -0
- data/lib/ruhoh/console_methods.rb +21 -0
- data/lib/ruhoh/{converters/converter.rb → converter.rb} +4 -1
- data/lib/ruhoh/programs/compile.rb +22 -0
- data/lib/ruhoh/programs/preview.rb +63 -0
- data/lib/ruhoh/programs/watch.rb +45 -0
- data/lib/ruhoh/resources/dash/collection.rb +10 -0
- data/lib/ruhoh/resources/dash/model.rb +5 -0
- data/lib/ruhoh/resources/dash/model_view.rb +5 -0
- data/lib/ruhoh/resources/dash/previewer.rb +13 -0
- data/lib/ruhoh/resources/data/collection.rb +9 -0
- data/lib/ruhoh/resources/data/collection_view.rb +23 -0
- data/lib/ruhoh/resources/javascripts/collection.rb +9 -0
- data/lib/ruhoh/resources/javascripts/collection_view.rb +46 -0
- data/lib/ruhoh/resources/javascripts/compiler.rb +5 -0
- data/lib/ruhoh/resources/layouts/client.rb +45 -0
- data/lib/ruhoh/resources/layouts/model.rb +16 -0
- data/lib/ruhoh/resources/media/collection.rb +9 -0
- data/lib/ruhoh/resources/media/compiler.rb +27 -0
- data/lib/ruhoh/resources/pages/client.rb +124 -0
- data/lib/ruhoh/resources/pages/collection.rb +86 -0
- data/lib/ruhoh/resources/pages/collection_view.rb +73 -0
- data/lib/ruhoh/resources/pages/compiler.rb +101 -0
- data/lib/ruhoh/resources/pages/model.rb +5 -0
- data/lib/ruhoh/resources/pages/model_view.rb +5 -0
- data/lib/ruhoh/resources/pages/previewer.rb +72 -0
- data/lib/ruhoh/resources/partials/model.rb +11 -0
- data/lib/ruhoh/resources/stylesheets/collection.rb +9 -0
- data/lib/ruhoh/resources/stylesheets/collection_view.rb +45 -0
- data/lib/ruhoh/resources/stylesheets/compiler.rb +5 -0
- data/lib/ruhoh/resources/theme/collection.rb +14 -0
- data/lib/ruhoh/resources/theme/compiler.rb +54 -0
- data/lib/ruhoh/resources/widgets/collection.rb +26 -0
- data/lib/ruhoh/resources/widgets/collection_view.rb +34 -0
- data/lib/ruhoh/resources/widgets/compiler.rb +27 -0
- data/lib/ruhoh/resources/widgets/model.rb +16 -0
- data/lib/ruhoh/routes.rb +29 -0
- data/lib/ruhoh/utils.rb +32 -49
- data/lib/ruhoh/version.rb +2 -2
- data/lib/ruhoh/views/helpers/categories.rb +38 -0
- data/lib/ruhoh/views/helpers/paginator.rb +39 -0
- data/lib/ruhoh/views/helpers/tags.rb +37 -0
- data/lib/ruhoh/views/master_view.rb +183 -0
- data/lib/ruhoh/views/rmustache.rb +24 -0
- data/ruhoh.gemspec +6 -82
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_contexts.rb +6 -5
- data/system/{scaffolds/post.html → _scaffold.html} +1 -1
- data/system/{dash.html → dash/index.html} +37 -51
- data/system/{scaffolds/layout.html → layouts/_scaffold.html} +0 -0
- data/system/layouts/paginator.html +28 -0
- data/system/plugins/sprockets/javascripts/compiler.rb +25 -0
- data/system/plugins/sprockets/javascripts/previewer.rb +17 -0
- data/system/plugins/sprockets/stylesheets/compiler.rb +26 -0
- data/system/plugins/sprockets/stylesheets/previewer.rb +17 -0
- data/system/widgets/analytics/{layouts/getclicky.html → getclicky.html} +6 -2
- data/system/widgets/analytics/{layouts/google.html → google.html} +5 -1
- data/system/widgets/comments/{layouts/disqus.html → disqus.html} +6 -2
- data/system/widgets/comments/{layouts/facebook.html → facebook.html} +9 -2
- data/system/widgets/comments/{layouts/intensedebate.html → intensedebate.html} +5 -1
- data/system/widgets/comments/{layouts/livefyre.html → livefyre.html} +5 -1
- data/system/widgets/google_prettify/{layouts/google_prettify.html → default.html} +6 -2
- metadata +69 -66
- data/lib/ruhoh/client/client.rb +0 -306
- data/lib/ruhoh/client/console_methods.rb +0 -9
- data/lib/ruhoh/client/help.yml +0 -56
- data/lib/ruhoh/compiler.rb +0 -72
- data/lib/ruhoh/compilers/rss.rb +0 -39
- data/lib/ruhoh/compilers/theme.rb +0 -46
- data/lib/ruhoh/config.rb +0 -62
- data/lib/ruhoh/db.rb +0 -50
- data/lib/ruhoh/deployers/s3.rb +0 -71
- data/lib/ruhoh/page.rb +0 -106
- data/lib/ruhoh/parsers/javascripts.rb +0 -55
- data/lib/ruhoh/parsers/layouts.rb +0 -32
- data/lib/ruhoh/parsers/pages.rb +0 -79
- data/lib/ruhoh/parsers/partials.rb +0 -42
- data/lib/ruhoh/parsers/payload.rb +0 -49
- data/lib/ruhoh/parsers/posts.rb +0 -259
- data/lib/ruhoh/parsers/routes.rb +0 -20
- data/lib/ruhoh/parsers/scaffolds.rb +0 -35
- data/lib/ruhoh/parsers/site.rb +0 -19
- data/lib/ruhoh/parsers/stylesheets.rb +0 -63
- data/lib/ruhoh/parsers/theme_config.rb +0 -30
- data/lib/ruhoh/parsers/widgets.rb +0 -104
- data/lib/ruhoh/paths.rb +0 -83
- data/lib/ruhoh/previewer.rb +0 -48
- data/lib/ruhoh/program.rb +0 -68
- data/lib/ruhoh/templaters/asset_helpers.rb +0 -66
- data/lib/ruhoh/templaters/base_helpers.rb +0 -147
- data/lib/ruhoh/templaters/helpers.rb +0 -8
- data/lib/ruhoh/templaters/rmustache.rb +0 -70
- data/lib/ruhoh/urls.rb +0 -50
- data/lib/ruhoh/watch.rb +0 -78
- data/spec/config_spec.rb +0 -50
- data/spec/db_spec.rb +0 -91
- data/spec/page_spec.rb +0 -164
- data/spec/parsers/layouts_spec.rb +0 -41
- data/spec/parsers/pages_spec.rb +0 -120
- data/spec/parsers/posts_spec.rb +0 -309
- data/spec/parsers/routes_spec.rb +0 -39
- data/spec/parsers/site_spec.rb +0 -28
- data/spec/setup_spec.rb +0 -12
- data/system/scaffolds/draft.html +0 -9
- data/system/scaffolds/page.html +0 -4
- data/system/widgets/analytics/config.yml +0 -5
- data/system/widgets/comments/config.yml +0 -13
- data/system/widgets/google_prettify/config.yml +0 -1
@@ -1,55 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
# Collect all the javascripts.
|
4
|
-
# Themes explicitly define which javascripts to load via theme.yml.
|
5
|
-
# Additionally, widgets may register javascript dependencies, which are resolved here.
|
6
|
-
module Javascripts
|
7
|
-
|
8
|
-
# Generates mappings to all registered javascripts.
|
9
|
-
# Returns Hash with layout names as keys and Array of asset Objects as values
|
10
|
-
def self.generate
|
11
|
-
assets = self.theme_javascripts
|
12
|
-
assets[Ruhoh.names.widgets] = self.widget_javascripts
|
13
|
-
assets
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.theme_javascripts
|
17
|
-
return {} unless Ruhoh::DB.theme_config[Ruhoh.names.javascripts].is_a? Hash
|
18
|
-
assets = {}
|
19
|
-
Ruhoh::DB.theme_config[Ruhoh.names.javascripts].each do |key, value|
|
20
|
-
next if key == Ruhoh.names.widgets # Widgets are handled separately.
|
21
|
-
assets[key] = Array(value).map { |v|
|
22
|
-
url = (v =~ /^(http:|https:)?\/\//i) ? v : "#{Ruhoh.urls.theme_javascripts}/#{v}"
|
23
|
-
{
|
24
|
-
"url" => url,
|
25
|
-
"id" => File.join(Ruhoh.paths.theme_javascripts, v)
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
assets
|
31
|
-
end
|
32
|
-
|
33
|
-
# Notes:
|
34
|
-
# The automatic script inclusion is currently handled within the widget parser.
|
35
|
-
# This differs from the auto-stylesheet inclusion relative to themes,
|
36
|
-
# which is handled in the stylesheet parser.
|
37
|
-
# Make sure there are some standards with this.
|
38
|
-
def self.widget_javascripts
|
39
|
-
assets = []
|
40
|
-
Ruhoh::DB.widgets.each_value do |widget|
|
41
|
-
next unless widget[Ruhoh.names.javascripts]
|
42
|
-
assets += Array(widget[Ruhoh.names.javascripts]).map {|path|
|
43
|
-
{
|
44
|
-
"url" => [Ruhoh.urls.widgets, widget['name'], Ruhoh.names.javascripts, path].join('/'),
|
45
|
-
"id" => File.join(Ruhoh.paths.widgets, widget['name'], Ruhoh.names.javascripts, path)
|
46
|
-
}
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
assets
|
51
|
-
end
|
52
|
-
|
53
|
-
end #Javascripts
|
54
|
-
end #Parsers
|
55
|
-
end #Ruhoh
|
@@ -1,32 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
module Layouts
|
4
|
-
|
5
|
-
# Generate layouts only from the active theme.
|
6
|
-
def self.generate
|
7
|
-
layouts = {}
|
8
|
-
self.files.each do |filename|
|
9
|
-
id = File.basename(filename, File.extname(filename))
|
10
|
-
data = Ruhoh::Utils.parse_layout_file(Ruhoh.paths.theme_layouts, filename)
|
11
|
-
data['id'] = id
|
12
|
-
layouts[id] = data
|
13
|
-
end
|
14
|
-
|
15
|
-
Ruhoh::Utils.report('Layouts', layouts, [])
|
16
|
-
layouts
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.files
|
20
|
-
return [] unless FileTest.directory?(Ruhoh.paths.theme_layouts)
|
21
|
-
FileUtils.cd(Ruhoh.paths.theme_layouts) {
|
22
|
-
return Dir["**/*.*"].select { |filename|
|
23
|
-
next if FileTest.directory?(filename)
|
24
|
-
next if ['_','.'].include? filename[0]
|
25
|
-
true
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
end #Layouts
|
31
|
-
end #Parsers
|
32
|
-
end #Ruhoh
|
data/lib/ruhoh/parsers/pages.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
module Pages
|
4
|
-
|
5
|
-
# Public: Generate the Pages dictionary.
|
6
|
-
#
|
7
|
-
def self.generate
|
8
|
-
Ruhoh.ensure_setup
|
9
|
-
|
10
|
-
pages = self.files
|
11
|
-
dictionary = {}
|
12
|
-
|
13
|
-
pages.each do |filename|
|
14
|
-
id = self.make_id(filename)
|
15
|
-
parsed_page = ''
|
16
|
-
FileUtils.cd(Ruhoh.paths.base) { parsed_page = Ruhoh::Utils.parse_page_file(filename) }
|
17
|
-
|
18
|
-
parsed_page['data']['id'] = id
|
19
|
-
parsed_page['data']['url'] = self.permalink(parsed_page['data'])
|
20
|
-
parsed_page['data']['title'] = parsed_page['data']['title'] || self.to_title(filename)
|
21
|
-
if parsed_page['data']['layout'].nil?
|
22
|
-
parsed_page['data']['layout'] = Ruhoh.config.pages_layout
|
23
|
-
end
|
24
|
-
|
25
|
-
dictionary[id] = parsed_page['data']
|
26
|
-
end
|
27
|
-
|
28
|
-
Ruhoh::Utils.report('Pages', dictionary, [])
|
29
|
-
dictionary
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.files
|
33
|
-
FileUtils.cd(Ruhoh.paths.base) {
|
34
|
-
return Dir["#{Ruhoh.names.pages}/**/*.*"].select { |filename|
|
35
|
-
next unless self.is_valid_page?(filename)
|
36
|
-
true
|
37
|
-
}
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.is_valid_page?(filepath)
|
42
|
-
return false if FileTest.directory?(filepath)
|
43
|
-
return false if ['.'].include? filepath[0]
|
44
|
-
Ruhoh.config.pages_exclude.each {|regex| return false if filepath =~ regex }
|
45
|
-
true
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.make_id(filename)
|
49
|
-
filename.gsub(Regexp.new("^#{Ruhoh.names.pages}/"), '')
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.to_title(filename)
|
53
|
-
name = File.basename( filename, File.extname(filename) )
|
54
|
-
name = filename.split('/')[-2] if name == 'index' && !filename.index('/').nil?
|
55
|
-
name.gsub(/[^\p{Word}+]/u, ' ').gsub(/\b\w/){$&.upcase}
|
56
|
-
end
|
57
|
-
|
58
|
-
# Build the permalink for the given page.
|
59
|
-
# Only recognize extensions registered from a 'convertable' module.
|
60
|
-
# This means 'non-convertable' extensions should pass-through.
|
61
|
-
#
|
62
|
-
# Returns [String] the permalink for this page.
|
63
|
-
def self.permalink(page)
|
64
|
-
ext = File.extname(page['id'])
|
65
|
-
name = page['id'].gsub(Regexp.new("#{ext}$"), '')
|
66
|
-
ext = '.html' if Ruhoh::Converter.extensions.include?(ext)
|
67
|
-
url = name.split('/').map {|p| Ruhoh::Urls.to_url_slug(p) }.join('/')
|
68
|
-
url = "#{url}#{ext}".gsub(/index.html$/, '')
|
69
|
-
if page['permalink'] == 'pretty' || Ruhoh.config.pages_permalink == 'pretty'
|
70
|
-
url = url.gsub(/\.html$/, '')
|
71
|
-
end
|
72
|
-
|
73
|
-
url = '/' if url.empty?
|
74
|
-
Ruhoh::Urls.to_url(url)
|
75
|
-
end
|
76
|
-
|
77
|
-
end # Pages
|
78
|
-
end #Parsers
|
79
|
-
end #Ruhoh
|
@@ -1,42 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
module Partials
|
4
|
-
|
5
|
-
def self.generate
|
6
|
-
self.system_partials.merge(
|
7
|
-
self.global_partials
|
8
|
-
).merge(
|
9
|
-
self.theme_partials
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.theme_partials
|
14
|
-
self.process(Ruhoh.paths.theme_partials)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.global_partials
|
18
|
-
self.process(Ruhoh.paths.partials)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.system_partials
|
22
|
-
self.process(Ruhoh.paths.system_partials)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.process(path)
|
26
|
-
return {} unless File.exist?(path)
|
27
|
-
|
28
|
-
partials = {}
|
29
|
-
FileUtils.cd(path) {
|
30
|
-
Dir.glob("**/*").each { |filename|
|
31
|
-
next if FileTest.directory?(filename)
|
32
|
-
next if ['.'].include? filename[0]
|
33
|
-
name = filename.chomp(File.extname(filename))
|
34
|
-
File.open(filename, 'r:UTF-8') { |f| partials[name] = f.read }
|
35
|
-
}
|
36
|
-
}
|
37
|
-
partials
|
38
|
-
end
|
39
|
-
|
40
|
-
end #Partials
|
41
|
-
end #Parsers
|
42
|
-
end #Ruhoh
|
@@ -1,49 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
module Payload
|
4
|
-
|
5
|
-
def self.generate
|
6
|
-
{
|
7
|
-
"db" => {
|
8
|
-
"pages" => Ruhoh::DB.pages,
|
9
|
-
"posts" => self.determine_category_and_tag_urls,
|
10
|
-
},
|
11
|
-
"site" => Ruhoh::DB.site,
|
12
|
-
'page' => {},
|
13
|
-
"urls" => {
|
14
|
-
"theme" => Ruhoh.urls.theme,
|
15
|
-
"theme_stylesheets" => Ruhoh.urls.theme_stylesheets,
|
16
|
-
"theme_javascripts" => Ruhoh.urls.theme_javascripts,
|
17
|
-
"theme_media" => Ruhoh.urls.theme_media,
|
18
|
-
"media" => Ruhoh.urls.media,
|
19
|
-
"base_path" => Ruhoh.config.base_path,
|
20
|
-
}
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
# This is an ugly hack to determine the proper category and tag urls.
|
25
|
-
# TODO: Refactor this out.
|
26
|
-
def self.determine_category_and_tag_urls
|
27
|
-
return nil unless Ruhoh::DB.routes && Ruhoh::DB.posts
|
28
|
-
categories_url = nil
|
29
|
-
[Ruhoh::Urls.to_url("categories"), Ruhoh::Urls.to_url("categories.html")].each { |url|
|
30
|
-
categories_url = url and break if Ruhoh::DB.routes.key?(url)
|
31
|
-
}
|
32
|
-
Ruhoh::DB.posts['categories'].each do |key, value|
|
33
|
-
Ruhoh::DB.posts['categories'][key]['url'] = "#{categories_url}##{value['name']}-ref"
|
34
|
-
end
|
35
|
-
|
36
|
-
tags_url = nil
|
37
|
-
[Ruhoh::Urls.to_url("tags"), Ruhoh::Urls.to_url("tags.html")].each { |url|
|
38
|
-
tags_url = url and break if Ruhoh::DB.routes.key?(url)
|
39
|
-
}
|
40
|
-
Ruhoh::DB.posts['tags'].each do |key, value|
|
41
|
-
Ruhoh::DB.posts['tags'][key]['url'] = "#{tags_url}##{value['name']}-ref"
|
42
|
-
end
|
43
|
-
|
44
|
-
Ruhoh::DB.posts
|
45
|
-
end
|
46
|
-
|
47
|
-
end #Payload
|
48
|
-
end #Parsers
|
49
|
-
end #Ruhoh
|
data/lib/ruhoh/parsers/posts.rb
DELETED
@@ -1,259 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Parsers
|
3
|
-
module Posts
|
4
|
-
|
5
|
-
DateMatcher = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
|
6
|
-
Matcher = /^(.+\/)*(.*)(\.[^.]+)$/
|
7
|
-
|
8
|
-
# Public: Generate the Posts dictionary.
|
9
|
-
#
|
10
|
-
def self.generate
|
11
|
-
Ruhoh.ensure_setup
|
12
|
-
|
13
|
-
results = self.process
|
14
|
-
ordered_posts = self.ordered_posts(results['posts'])
|
15
|
-
|
16
|
-
{
|
17
|
-
'dictionary' => results['posts'],
|
18
|
-
'drafts' => results['drafts'],
|
19
|
-
'chronological' => self.build_chronology(ordered_posts),
|
20
|
-
'collated' => self.collate(ordered_posts),
|
21
|
-
'tags' => self.parse_tags(ordered_posts),
|
22
|
-
'categories' => self.parse_categories(ordered_posts)
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.process
|
27
|
-
dictionary = {}
|
28
|
-
drafts = []
|
29
|
-
invalid = []
|
30
|
-
|
31
|
-
self.files.each do |filename|
|
32
|
-
parsed_page = ''
|
33
|
-
FileUtils.cd(Ruhoh.paths.base) { parsed_page = Ruhoh::Utils.parse_page_file(filename) }
|
34
|
-
data = parsed_page['data']
|
35
|
-
|
36
|
-
filename_data = self.parse_page_filename(filename)
|
37
|
-
if filename_data.empty?
|
38
|
-
error = "Invalid Filename Format. Format should be: my-post-title.ext"
|
39
|
-
invalid << [filename, error] ; next
|
40
|
-
end
|
41
|
-
|
42
|
-
data['date'] ||= filename_data['date']
|
43
|
-
|
44
|
-
unless self.formatted_date(data['date'])
|
45
|
-
error = "Invalid Date Format. Date should be: YYYY-MM-DD"
|
46
|
-
invalid << [filename, error] ; next
|
47
|
-
end
|
48
|
-
|
49
|
-
if data['type'] == 'draft'
|
50
|
-
next if Ruhoh.config.env == 'production'
|
51
|
-
drafts << filename
|
52
|
-
end
|
53
|
-
|
54
|
-
data['date'] = data['date'].to_s
|
55
|
-
data['id'] = filename
|
56
|
-
data['title'] = data['title'] || filename_data['title']
|
57
|
-
data['url'] = self.permalink(data)
|
58
|
-
data['layout'] = Ruhoh.config.posts_layout if data['layout'].nil?
|
59
|
-
dictionary[filename] = data
|
60
|
-
end
|
61
|
-
|
62
|
-
Ruhoh::Utils.report('Posts', dictionary, invalid)
|
63
|
-
|
64
|
-
{
|
65
|
-
"posts" => dictionary,
|
66
|
-
"drafts" => drafts
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.formatted_date(date)
|
71
|
-
Time.parse(date.to_s).strftime('%Y-%m-%d')
|
72
|
-
rescue
|
73
|
-
false
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.files
|
77
|
-
FileUtils.cd(Ruhoh.paths.base) {
|
78
|
-
return Dir["#{Ruhoh.names.posts}/**/*.*"].select { |filename|
|
79
|
-
next unless self.is_valid_page?(filename)
|
80
|
-
true
|
81
|
-
}
|
82
|
-
}
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.is_valid_page?(filepath)
|
86
|
-
return false if FileTest.directory?(filepath)
|
87
|
-
return false if ['.'].include? filepath[0]
|
88
|
-
Ruhoh.config.posts_exclude.each {|regex| return false if filepath =~ regex }
|
89
|
-
true
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.ordered_posts(dictionary)
|
93
|
-
ordered_posts = []
|
94
|
-
dictionary.each_value { |val| ordered_posts << val }
|
95
|
-
ordered_posts.sort! {
|
96
|
-
|a,b| Date.parse(b['date']) <=> Date.parse(a['date'])
|
97
|
-
}
|
98
|
-
|
99
|
-
ordered_posts
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.parse_page_filename(filename)
|
103
|
-
data = *filename.match(DateMatcher)
|
104
|
-
data = *filename.match(Matcher) if data.empty?
|
105
|
-
return {} if data.empty?
|
106
|
-
|
107
|
-
if filename =~ DateMatcher
|
108
|
-
{
|
109
|
-
"path" => data[1],
|
110
|
-
"date" => data[2],
|
111
|
-
"slug" => data[3],
|
112
|
-
"title" => self.to_title(data[3]),
|
113
|
-
"extension" => data[4]
|
114
|
-
}
|
115
|
-
else
|
116
|
-
{
|
117
|
-
"path" => data[1],
|
118
|
-
"slug" => data[2],
|
119
|
-
"title" => self.to_title(data[2]),
|
120
|
-
"extension" => data[3]
|
121
|
-
}
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# my-post-title ===> My Post Title
|
126
|
-
def self.to_title(file_slug)
|
127
|
-
file_slug.gsub(/[^\p{Word}+]/u, ' ').gsub(/\b\w/){$&.upcase}
|
128
|
-
end
|
129
|
-
|
130
|
-
# Used in the client implementation to turn a draft into a post.
|
131
|
-
def self.to_filename(data)
|
132
|
-
File.join(Ruhoh.paths.posts, "#{Ruhoh::Urls.to_slug(data['title'])}.#{data['ext']}")
|
133
|
-
end
|
134
|
-
|
135
|
-
# Another blatently stolen method from Jekyll
|
136
|
-
# The category is only the first one if multiple categories exist.
|
137
|
-
def self.permalink(post)
|
138
|
-
date = Date.parse(post['date'])
|
139
|
-
title = Ruhoh::Urls.to_url_slug(post['title'])
|
140
|
-
format = post['permalink'] || Ruhoh.config.posts_permalink
|
141
|
-
|
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.
|
161
|
-
url = format.gsub(/^\//, '').split('/').map {|p| CGI::escape(p) }.join('/')
|
162
|
-
end
|
163
|
-
|
164
|
-
Ruhoh::Urls.to_url(url)
|
165
|
-
end
|
166
|
-
|
167
|
-
def self.build_chronology(ordered_posts)
|
168
|
-
ordered_posts.map { |post| post['id'] }
|
169
|
-
end
|
170
|
-
|
171
|
-
# Internal: Create a collated posts data structure.
|
172
|
-
#
|
173
|
-
# posts - Required [Array]
|
174
|
-
# Must be sorted chronologically beforehand.
|
175
|
-
#
|
176
|
-
# [{ 'year': year,
|
177
|
-
# 'months' : [{ 'month' : month,
|
178
|
-
# 'posts': [{}, {}, ..] }, ..] }, ..]
|
179
|
-
#
|
180
|
-
def self.collate(ordered_posts)
|
181
|
-
collated = []
|
182
|
-
ordered_posts.each_with_index do |post, i|
|
183
|
-
thisYear = Time.parse(post['date']).strftime('%Y')
|
184
|
-
thisMonth = Time.parse(post['date']).strftime('%B')
|
185
|
-
if (i-1 >= 0)
|
186
|
-
prevYear = Time.parse(ordered_posts[i-1]['date']).strftime('%Y')
|
187
|
-
prevMonth = Time.parse(ordered_posts[i-1]['date']).strftime('%B')
|
188
|
-
end
|
189
|
-
|
190
|
-
if(prevYear == thisYear)
|
191
|
-
if(prevMonth == thisMonth)
|
192
|
-
collated.last['months'].last['posts'] << post['id'] # append to last year & month
|
193
|
-
else
|
194
|
-
collated.last['months'] << {
|
195
|
-
'month' => thisMonth,
|
196
|
-
'posts' => [post['id']]
|
197
|
-
} # create new month
|
198
|
-
end
|
199
|
-
else
|
200
|
-
collated << {
|
201
|
-
'year' => thisYear,
|
202
|
-
'months' => [{
|
203
|
-
'month' => thisMonth,
|
204
|
-
'posts' => [post['id']]
|
205
|
-
}]
|
206
|
-
} # create new year & month
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
collated
|
212
|
-
end
|
213
|
-
|
214
|
-
def self.parse_tags(ordered_posts)
|
215
|
-
tags = {}
|
216
|
-
|
217
|
-
ordered_posts.each do |post|
|
218
|
-
Array(post['tags']).each do |tag|
|
219
|
-
if tags[tag]
|
220
|
-
tags[tag]['count'] += 1
|
221
|
-
else
|
222
|
-
tags[tag] = {
|
223
|
-
'count' => 1,
|
224
|
-
'name' => tag,
|
225
|
-
'posts' => []
|
226
|
-
}
|
227
|
-
end
|
228
|
-
|
229
|
-
tags[tag]['posts'] << post['id']
|
230
|
-
end
|
231
|
-
end
|
232
|
-
tags
|
233
|
-
end
|
234
|
-
|
235
|
-
def self.parse_categories(ordered_posts)
|
236
|
-
categories = {}
|
237
|
-
|
238
|
-
ordered_posts.each do |post|
|
239
|
-
Array(post['categories']).each do |cat|
|
240
|
-
cat = Array(cat).join('/')
|
241
|
-
if categories[cat]
|
242
|
-
categories[cat]['count'] += 1
|
243
|
-
else
|
244
|
-
categories[cat] = {
|
245
|
-
'count' => 1,
|
246
|
-
'name' => cat,
|
247
|
-
'posts' => []
|
248
|
-
}
|
249
|
-
end
|
250
|
-
|
251
|
-
categories[cat]['posts'] << post['id']
|
252
|
-
end
|
253
|
-
end
|
254
|
-
categories
|
255
|
-
end
|
256
|
-
|
257
|
-
end # Post
|
258
|
-
end #Parsers
|
259
|
-
end #Ruhoh
|