ruhoh 1.1 → 2.1
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.
- 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
data/lib/ruhoh/client/help.yml
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: |
|
3
|
-
|
4
|
-
Ruhoh is a nifty, modular static blog generator.
|
5
|
-
It is the Universal Static Blog API.
|
6
|
-
Visit http://www.ruhoh.com for complete usage and documentation.
|
7
|
-
|
8
|
-
commands:
|
9
|
-
-
|
10
|
-
"command" : "new <directory_path>"
|
11
|
-
"desc" : |
|
12
|
-
Create a new blog directory based on the Ruhoh specification.
|
13
|
-
-
|
14
|
-
"command" : "compile"
|
15
|
-
"desc" : |
|
16
|
-
Compile to static website.
|
17
|
-
-
|
18
|
-
"command" : "draft <title>"
|
19
|
-
"desc" : |
|
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.
|
25
|
-
-
|
26
|
-
"command" : "page <path>"
|
27
|
-
"desc" : |
|
28
|
-
Create a new page at the given path.
|
29
|
-
-
|
30
|
-
"command" : "titleize"
|
31
|
-
"desc" : |
|
32
|
-
Update draft filenames to their corresponding titles. Drafts without titles are ignored.
|
33
|
-
-
|
34
|
-
"command" : "drafts"
|
35
|
-
"desc" : |
|
36
|
-
List all drafts.
|
37
|
-
-
|
38
|
-
"command" : "posts"
|
39
|
-
"desc" : |
|
40
|
-
List all posts.
|
41
|
-
-
|
42
|
-
"command" : "pages"
|
43
|
-
"desc" : |
|
44
|
-
List all pages.
|
45
|
-
-
|
46
|
-
"command" : "payload"
|
47
|
-
"desc" : |
|
48
|
-
List the full payload hash as given to the templater. Note page is blank for example purposes.
|
49
|
-
-
|
50
|
-
"command" : "layout <name>"
|
51
|
-
"desc" : |
|
52
|
-
Create a new layout for the currently active theme.
|
53
|
-
-
|
54
|
-
"command" : "help"
|
55
|
-
"desc" : |
|
56
|
-
Show this menu.
|
data/lib/ruhoh/compiler.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'ruhoh/compilers/theme'
|
2
|
-
require 'ruhoh/compilers/rss'
|
3
|
-
|
4
|
-
class Ruhoh
|
5
|
-
module Compiler
|
6
|
-
|
7
|
-
# TODO: seems rather dangerous to delete the incoming target directory?
|
8
|
-
def self.compile(target_directory = nil, page = nil)
|
9
|
-
Ruhoh::Friend.say { plain "Compiling for environment: '#{Ruhoh.config.env}'" }
|
10
|
-
target = target_directory || "./#{Ruhoh.names.compiled}"
|
11
|
-
page = page || Ruhoh::Page.new
|
12
|
-
|
13
|
-
FileUtils.rm_r target if File.exist?(target)
|
14
|
-
FileUtils.mkdir_p target
|
15
|
-
|
16
|
-
self.constants.each {|c|
|
17
|
-
task = self.const_get(c)
|
18
|
-
next unless task.respond_to?(:run)
|
19
|
-
task.run(target, page)
|
20
|
-
}
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
module Defaults
|
25
|
-
|
26
|
-
def self.run(target, page)
|
27
|
-
self.pages(target, page)
|
28
|
-
self.media(target, page)
|
29
|
-
self.javascripts(target, page)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.pages(target, page)
|
33
|
-
FileUtils.cd(target) {
|
34
|
-
Ruhoh::DB.all_pages.each_value do |p|
|
35
|
-
page.change(p['id'])
|
36
|
-
|
37
|
-
FileUtils.mkdir_p File.dirname(page.compiled_path)
|
38
|
-
File.open(page.compiled_path, 'w:UTF-8') { |p| p.puts page.render }
|
39
|
-
|
40
|
-
Ruhoh::Friend.say { green "processed: #{p['id']}" }
|
41
|
-
end
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.media(target, page)
|
46
|
-
return unless FileTest.directory? Ruhoh.paths.media
|
47
|
-
url = Ruhoh.urls.media.gsub(/^\//, '')
|
48
|
-
media = Ruhoh::Utils.url_to_path(url, target)
|
49
|
-
FileUtils.mkdir_p media
|
50
|
-
FileUtils.cp_r File.join(Ruhoh.paths.media, '.'), media
|
51
|
-
end
|
52
|
-
|
53
|
-
# Create all the javascripts.
|
54
|
-
# Javascripts may be registered from either a theme or a widget.
|
55
|
-
# Technically the theme compiler may create javascripts relative to the theme.
|
56
|
-
# This ensures the widget javascripts are created as well.
|
57
|
-
def self.javascripts(target, page)
|
58
|
-
Ruhoh::DB.javascripts.each do |type, assets|
|
59
|
-
assets.each do |asset|
|
60
|
-
url = asset['url'].gsub(/^\//, '')
|
61
|
-
next unless File.exist?(asset['id'])
|
62
|
-
file_path = Ruhoh::Utils.url_to_path(File.dirname(url), target)
|
63
|
-
FileUtils.mkdir_p file_path
|
64
|
-
FileUtils.cp(asset['id'], file_path)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end #Defaults
|
70
|
-
|
71
|
-
end #Compiler
|
72
|
-
end #Ruhoh
|
data/lib/ruhoh/compilers/rss.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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
|
-
num_posts = Ruhoh.config.rss_limit
|
14
|
-
posts = Ruhoh::DB.posts['chronological'].first(num_posts)
|
15
|
-
|
16
|
-
feed = Nokogiri::XML::Builder.new do |xml|
|
17
|
-
xml.rss(:version => '2.0') {
|
18
|
-
xml.channel {
|
19
|
-
xml.title_ Ruhoh::DB.site['title']
|
20
|
-
xml.link_ Ruhoh::DB.site['config']['production_url']
|
21
|
-
xml.pubDate_ Time.now
|
22
|
-
posts.each do |post_id|
|
23
|
-
post = Ruhoh::DB.posts['dictionary'][post_id]
|
24
|
-
page.change(post_id)
|
25
|
-
xml.item {
|
26
|
-
xml.title_ post['title']
|
27
|
-
xml.link "#{Ruhoh::DB.site['config']['production_url']}#{post['url']}"
|
28
|
-
xml.pubDate_ post['date']
|
29
|
-
xml.description_ (post['description'] ? post['description'] : page.render)
|
30
|
-
}
|
31
|
-
end
|
32
|
-
}
|
33
|
-
}
|
34
|
-
end
|
35
|
-
File.open(File.join(target, 'rss.xml'), 'w'){ |p| p.puts feed.to_xml }
|
36
|
-
end
|
37
|
-
end #Rss
|
38
|
-
end #Compiler
|
39
|
-
end #Ruhoh
|
@@ -1,46 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
module Compiler
|
3
|
-
module Theme
|
4
|
-
|
5
|
-
def self.run(target, page)
|
6
|
-
self.copy(target, page)
|
7
|
-
end
|
8
|
-
|
9
|
-
# Copies all theme assets over to the compiled site.
|
10
|
-
# Note the compiled assets are namespaced at /assets/<theme-name>/
|
11
|
-
# theme.yml may specify exclusion rules for excluding assets.
|
12
|
-
def self.copy(target, page)
|
13
|
-
url = Ruhoh.urls.theme.gsub(/^\//, '')
|
14
|
-
theme = Ruhoh::Utils.url_to_path(url, target)
|
15
|
-
FileUtils.mkdir_p theme
|
16
|
-
|
17
|
-
self.files.each do |file|
|
18
|
-
original_file = File.join(Ruhoh.paths.theme, file)
|
19
|
-
compiled_file = File.join(theme, file)
|
20
|
-
FileUtils.mkdir_p File.dirname(compiled_file)
|
21
|
-
FileUtils.cp_r original_file, compiled_file
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns list of all files from the theme that need to be
|
26
|
-
# compiled to the production environment.
|
27
|
-
# Returns Array of relative filepaths
|
28
|
-
def self.files
|
29
|
-
FileUtils.cd(Ruhoh.paths.theme) {
|
30
|
-
return Dir["**/*"].select { |filepath|
|
31
|
-
next unless self.is_valid_asset?(filepath)
|
32
|
-
true
|
33
|
-
}
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
# Checks a given asset filepath against any user-defined exclusion rules in theme.yml
|
38
|
-
def self.is_valid_asset?(filepath)
|
39
|
-
return false if FileTest.directory?(filepath)
|
40
|
-
Ruhoh::DB.theme_config["exclude"].each {|regex| return false if filepath =~ regex }
|
41
|
-
true
|
42
|
-
end
|
43
|
-
|
44
|
-
end #Theme
|
45
|
-
end #Compiler
|
46
|
-
end #Ruhoh
|
data/lib/ruhoh/config.rb
DELETED
@@ -1,62 +0,0 @@
|
|
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
|
-
:rss_limit,
|
13
|
-
:theme,
|
14
|
-
:base_path
|
15
|
-
)
|
16
|
-
|
17
|
-
def self.generate
|
18
|
-
site_config = Ruhoh::Utils.parse_yaml_file(Ruhoh.base, Ruhoh.names.config_data)
|
19
|
-
unless site_config
|
20
|
-
Ruhoh.log.error("Empty site_config.\nEnsure ./#{Ruhoh.names.config_data} exists and contains valid YAML")
|
21
|
-
return false
|
22
|
-
end
|
23
|
-
|
24
|
-
theme = site_config['theme'] ? site_config['theme'].to_s.gsub(/\s/, '') : ''
|
25
|
-
if theme.empty?
|
26
|
-
Ruhoh.log.error("Theme not specified in #{Ruhoh.names.config_data}")
|
27
|
-
return false
|
28
|
-
end
|
29
|
-
|
30
|
-
config = Config.new
|
31
|
-
config.theme = theme
|
32
|
-
|
33
|
-
config.env = site_config['env'] || nil
|
34
|
-
|
35
|
-
config.base_path = '/'
|
36
|
-
if site_config['base_path']
|
37
|
-
config.base_path = site_config['base_path'].to_s
|
38
|
-
config.base_path += "/" unless config.base_path[-1] == '/'
|
39
|
-
end
|
40
|
-
|
41
|
-
config.rss_limit = site_config['rss']['limit'] rescue nil
|
42
|
-
config.rss_limit = 20 if config.rss_limit.nil?
|
43
|
-
|
44
|
-
config.posts_permalink = site_config['posts']['permalink'] rescue nil
|
45
|
-
config.posts_permalink ||= "/:categories/:year/:month/:day/:title.html"
|
46
|
-
config.posts_layout = site_config['posts']['layout'] rescue nil
|
47
|
-
config.posts_layout = 'post' if config.posts_layout.nil?
|
48
|
-
excluded_posts = site_config['posts']['exclude'] rescue nil
|
49
|
-
config.posts_exclude = Array(excluded_posts)
|
50
|
-
config.posts_exclude = config.posts_exclude.map {|node| Regexp.new(node) }
|
51
|
-
|
52
|
-
config.pages_permalink = site_config['pages']['permalink'] rescue nil
|
53
|
-
config.pages_layout = site_config['pages']['layout'] rescue nil
|
54
|
-
config.pages_layout = 'page' if config.pages_layout.nil?
|
55
|
-
excluded_pages = site_config['pages']['exclude'] rescue nil
|
56
|
-
config.pages_exclude = Array(excluded_pages)
|
57
|
-
config.pages_exclude = config.pages_exclude.map {|node| Regexp.new(node) }
|
58
|
-
|
59
|
-
config
|
60
|
-
end
|
61
|
-
end #Config
|
62
|
-
end #Ruhoh
|
data/lib/ruhoh/db.rb
DELETED
@@ -1,50 +0,0 @@
|
|
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/theme_config'
|
8
|
-
require 'ruhoh/parsers/stylesheets'
|
9
|
-
require 'ruhoh/parsers/javascripts'
|
10
|
-
require 'ruhoh/parsers/payload'
|
11
|
-
require 'ruhoh/parsers/site'
|
12
|
-
require 'ruhoh/parsers/scaffolds'
|
13
|
-
|
14
|
-
class Ruhoh
|
15
|
-
# Public: Database class for interacting with "data" in Ruhoh.
|
16
|
-
class DB
|
17
|
-
WhiteList = [:site, :posts, :pages, :routes, :layouts, :partials, :widgets, :theme_config, :stylesheets, :javascripts, :payload, :scaffolds]
|
18
|
-
|
19
|
-
class << self
|
20
|
-
self.__send__ :attr_reader, *WhiteList
|
21
|
-
|
22
|
-
def update(name)
|
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
|
26
|
-
)
|
27
|
-
rescue NameError
|
28
|
-
raise NameError, "Data type: '#{name}' is not a valid data type."
|
29
|
-
end
|
30
|
-
|
31
|
-
# Always regenerate a fresh payload since it
|
32
|
-
# references other generated data.
|
33
|
-
def payload
|
34
|
-
self.update(:payload)
|
35
|
-
@payload
|
36
|
-
end
|
37
|
-
|
38
|
-
def all_pages
|
39
|
-
self.posts['dictionary'].merge(self.pages)
|
40
|
-
end
|
41
|
-
|
42
|
-
def update_all
|
43
|
-
WhiteList.each do |var|
|
44
|
-
self.__send__(:update, var)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end #self
|
49
|
-
end #DB
|
50
|
-
end #Ruhoh
|
data/lib/ruhoh/deployers/s3.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'aws/s3'
|
2
|
-
|
3
|
-
class Ruhoh
|
4
|
-
|
5
|
-
module Deployers
|
6
|
-
|
7
|
-
# Deploy to Amazon S3
|
8
|
-
# See http://amazon.rubyforge.org/ for usage.
|
9
|
-
class AmazonS3 < AWS::S3::S3Object
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
credentials = Ruhoh::Utils.parse_yaml_file(Ruhoh.paths.base, "_deploy.yml")['s3']
|
13
|
-
self.connect(credentials)
|
14
|
-
self.ensure_bucket(credentials["bucket"])
|
15
|
-
#set_current_bucket_to(credentials["bucket"])
|
16
|
-
@bucket = credentials["bucket"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def connect(credentials)
|
20
|
-
AWS::S3::Base.establish_connection!({
|
21
|
-
:access_key_id => credentials["access_key_id"],
|
22
|
-
:secret_access_key => credentials["secret_access_key"]
|
23
|
-
})
|
24
|
-
end
|
25
|
-
|
26
|
-
def deploy(compiled_directory)
|
27
|
-
FileUtils.cd(compiled_directory) {
|
28
|
-
Dir.glob("**/**") do |filepath|
|
29
|
-
next if FileTest.directory?(file)
|
30
|
-
self.store(filepath)
|
31
|
-
end
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def ensure_bucket(bucket)
|
36
|
-
AWS::S3::Bucket.find(bucket)
|
37
|
-
rescue
|
38
|
-
Ruhoh::Friend.say {
|
39
|
-
yellow "'#{@bucket}' bucket not found, trying to create..."
|
40
|
-
}
|
41
|
-
AWS::S3::Bucket.create(bucket, :access => :public_read)
|
42
|
-
|
43
|
-
if AWS::S3::Service.response.success?
|
44
|
-
Ruhoh::Friend.say { green "Bucket created!" }
|
45
|
-
else
|
46
|
-
Ruhoh::Friend.say {
|
47
|
-
red "Bucket creation failed!"
|
48
|
-
plain "Perhaps you will need to manually create the bucket."
|
49
|
-
}
|
50
|
-
exit
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# save/update a file to s3
|
55
|
-
def store(filepath)
|
56
|
-
File.open(filepath) do |file|
|
57
|
-
AWS::S3::S3Object.store(filepath, file, @bucket, :access => :public_read)
|
58
|
-
end
|
59
|
-
|
60
|
-
if AWS::S3::Service.response.success?
|
61
|
-
Ruhoh::Friend.say { green "#{filepath}: success!" }
|
62
|
-
else
|
63
|
-
Ruhoh::Friend.say { green "#{filepath}: failure!" }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end #S3
|
68
|
-
|
69
|
-
end #Deployers
|
70
|
-
|
71
|
-
end #Ruhoh
|
data/lib/ruhoh/page.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
class Ruhoh
|
2
|
-
class Page
|
3
|
-
attr_reader :id, :data, :sub_layout, :master_layout
|
4
|
-
attr_accessor :templater
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@templater = Ruhoh::Templaters::RMustache
|
8
|
-
end
|
9
|
-
|
10
|
-
# Public: Change this page using an id.
|
11
|
-
def change(id)
|
12
|
-
self.reset
|
13
|
-
@path = id
|
14
|
-
@data = if id =~ Regexp.new("^#{Ruhoh.names.posts}")
|
15
|
-
Ruhoh::DB.posts['dictionary'][id]
|
16
|
-
else
|
17
|
-
@path = "#{Ruhoh.names.pages}/#{id}"
|
18
|
-
Ruhoh::DB.pages[id]
|
19
|
-
end
|
20
|
-
|
21
|
-
raise "Page #{id} not found in database" unless @data
|
22
|
-
@id = id
|
23
|
-
end
|
24
|
-
|
25
|
-
def render
|
26
|
-
self.ensure_id
|
27
|
-
self.process_layouts
|
28
|
-
@templater.render(self.expand_layouts, self.payload)
|
29
|
-
end
|
30
|
-
|
31
|
-
def process_layouts
|
32
|
-
self.ensure_id
|
33
|
-
if @data['layout']
|
34
|
-
@sub_layout = Ruhoh::DB.layouts[@data['layout']]
|
35
|
-
raise "Layout does not exist: #{@data['layout']}" unless @sub_layout
|
36
|
-
end
|
37
|
-
|
38
|
-
if @sub_layout && @sub_layout['data']['layout']
|
39
|
-
@master_layout = Ruhoh::DB.layouts[@sub_layout['data']['layout']]
|
40
|
-
raise "Layout does not exist: #{@sub_layout['data']['layout']}" unless @master_layout
|
41
|
-
end
|
42
|
-
|
43
|
-
@data['sub_layout'] = @sub_layout['id'] rescue nil
|
44
|
-
@data['master_layout'] = @master_layout['id'] rescue nil
|
45
|
-
@data
|
46
|
-
end
|
47
|
-
|
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
|
65
|
-
|
66
|
-
layout
|
67
|
-
end
|
68
|
-
|
69
|
-
def payload
|
70
|
-
self.ensure_id
|
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']
|
80
|
-
end
|
81
|
-
|
82
|
-
# Public: Formats the path to the compiled file based on the URL.
|
83
|
-
#
|
84
|
-
# Returns: [String] The relative path to the compiled file for this page.
|
85
|
-
def compiled_path
|
86
|
-
self.ensure_id
|
87
|
-
path = CGI.unescape(@data['url']).gsub(/^\//, '') #strip leading slash.
|
88
|
-
path = "index.html" if path.empty?
|
89
|
-
path += '/index.html' unless path =~ /\.\w+$/
|
90
|
-
path
|
91
|
-
end
|
92
|
-
|
93
|
-
def reset
|
94
|
-
@id = nil
|
95
|
-
@data = nil
|
96
|
-
@content = nil
|
97
|
-
@sub_layout = nil
|
98
|
-
@master_layout = nil
|
99
|
-
end
|
100
|
-
|
101
|
-
def ensure_id
|
102
|
-
raise '@page ID is null: ID must be set via page.change(id) or page.change_with_url(url)' if @id.nil?
|
103
|
-
end
|
104
|
-
|
105
|
-
end #Page
|
106
|
-
end #Ruhoh
|