aura 0.0.1.pre10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/HISTORY.md +95 -0
- data/README.md +53 -0
- data/Rakefile +27 -0
- data/Scribefile +8 -0
- data/app/css/_utilities.scss +88 -0
- data/app/css/admin.scss +21 -0
- data/app/css/admin/_settings.scss +136 -0
- data/app/css/admin/chrome.scss +208 -0
- data/app/css/admin/common.scss +78 -0
- data/app/css/admin/forms.scss +342 -0
- data/app/css/admin/jquery_wysiwyg.scss +96 -0
- data/app/css/admin/loading.scss +18 -0
- data/app/css/admin/meta.scss +42 -0
- data/app/css/admin/reset.scss +46 -0
- data/app/css/admin/sections.scss +79 -0
- data/app/css/admin/setup.scss +22 -0
- data/app/css/admin/sidebar.scss +136 -0
- data/app/css/admin/slug.scss +78 -0
- data/app/css/admin/uiscreen.scss +22 -0
- data/app/css/admin/wysiwyg_field.scss +11 -0
- data/app/css/admin_watermark.scss +23 -0
- data/app/css/default_home_page.scss +13 -0
- data/app/css/login.scss +47 -0
- data/app/helpers/admin_helpers.rb +59 -0
- data/app/helpers/flash_helpers.rb +86 -0
- data/app/helpers/form_builder_helpers.rb +9 -0
- data/app/helpers/html_helpers.rb +27 -0
- data/app/helpers/jquery_helpers.rb +26 -0
- data/app/helpers/main_helpers.rb +67 -0
- data/app/helpers/page_helpers.rb +92 -0
- data/app/helpers/template_helpers.rb +94 -0
- data/app/helpers/user_helpers.rb +45 -0
- data/app/init/admin.rb +34 -0
- data/app/init/extensions.rb +18 -0
- data/app/init/pistol.rb +11 -0
- data/app/init/sequel.rb +11 -0
- data/app/main.rb +106 -0
- data/app/migrations/page.rb +29 -0
- data/app/migrations/settings.rb +11 -0
- data/app/migrations/user.rb +13 -0
- data/app/models/page.rb +116 -0
- data/app/models/page_seed.rb +47 -0
- data/app/models/settings.rb +59 -0
- data/app/models/user.rb +60 -0
- data/app/routes/admin.rb +44 -0
- data/app/routes/css_js.rb +53 -0
- data/app/routes/design_tests.rb +15 -0
- data/app/routes/editor.rb +152 -0
- data/app/routes/site.rb +33 -0
- data/app/routes/user.rb +48 -0
- data/app/views/admin/_back_to_dashboard.haml +3 -0
- data/app/views/admin/dashboard.haml +46 -0
- data/app/views/admin/layout.haml +73 -0
- data/app/views/admin/settings.haml +40 -0
- data/app/views/admin/settings/database.haml +42 -0
- data/app/views/base/crumbs.haml +50 -0
- data/app/views/base/delete.haml +19 -0
- data/app/views/base/edit.haml +61 -0
- data/app/views/base/errors.haml +10 -0
- data/app/views/base/form.haml +11 -0
- data/app/views/base/list.haml +14 -0
- data/app/views/base/list_actions.haml +4 -0
- data/app/views/base/list_item.haml +7 -0
- data/app/views/base/nav.haml +36 -0
- data/app/views/base/new.haml +36 -0
- data/app/views/base/preview.haml +28 -0
- data/app/views/base/tabs.haml +12 -0
- data/app/views/default_home_page.haml +15 -0
- data/app/views/design_tests/admin_styles.haml +58 -0
- data/app/views/form_builder/builder.haml +29 -0
- data/app/views/page/edit.haml +29 -0
- data/app/views/page/form.haml +22 -0
- data/app/views/page/meta_form.haml +22 -0
- data/app/views/page/new.haml +26 -0
- data/app/views/user/edit.haml +52 -0
- data/app/views/user/form.haml +43 -0
- data/app/views/user/list.haml +11 -0
- data/app/views/user/login.haml +33 -0
- data/app/views/user/new.haml +25 -0
- data/app/views/user/welcome.haml +29 -0
- data/app/views/watermark/watermark.haml +16 -0
- data/aura.gemspec +36 -0
- data/bin/aura +8 -0
- data/config/database.rb +12 -0
- data/config/extensions.rb +5 -0
- data/config/scss.rb +14 -0
- data/config/user.rb +10 -0
- data/default/.gitignore +6 -0
- data/default/Gemfile +11 -0
- data/default/README.md +24 -0
- data/default/Rakefile +8 -0
- data/default/app/README +3 -0
- data/default/app/css/.gitignore +0 -0
- data/default/app/helpers/helpers.rb.example +9 -0
- data/default/app/js/.gitignore +0 -0
- data/default/app/migrations/model.rb.example +20 -0
- data/default/app/models/model.rb.example +11 -0
- data/default/app/models/page-ext.rb.example +17 -0
- data/default/app/routes/site.rb.example +5 -0
- data/default/app/views/hello.haml.example +1 -0
- data/default/config.ru +3 -0
- data/default/config/.gitignore +0 -0
- data/default/config/database.rb.example +30 -0
- data/default/config/extensions.rb +5 -0
- data/default/config/user.rb.example +10 -0
- data/default/db/.gitignore +0 -0
- data/default/init.rb +15 -0
- data/default/public/.gitignore +0 -0
- data/extensions/contact_form/migrations/contact_form.rb +13 -0
- data/extensions/contact_form/models/contact_form.rb +13 -0
- data/extensions/contact_form/routes/contact_form.rb +11 -0
- data/extensions/contact_form/views/contact_form/edit.haml +8 -0
- data/extensions/contact_form/views/contact_form/form.haml +3 -0
- data/extensions/contact_form/views/contact_form/nav.haml +42 -0
- data/extensions/contact_form/views/contact_form/responses.haml +20 -0
- data/extensions/contact_form/views/contact_form/tabs.haml +8 -0
- data/extensions/default_theme/css/theme/_settings.scss +3 -0
- data/extensions/default_theme/css/theme/chrome.scss +66 -0
- data/extensions/default_theme/css/theme/reset.scss +34 -0
- data/extensions/default_theme/css/theme/style.scss +3 -0
- data/extensions/default_theme/info.yml +2 -0
- data/extensions/default_theme/public/browse.png +0 -0
- data/extensions/default_theme/views/base/id_portfolio.haml +32 -0
- data/extensions/default_theme/views/base/show.haml +31 -0
- data/extensions/default_theme/views/errors/error.haml +9 -0
- data/extensions/default_theme/views/errors/not_found.haml +11 -0
- data/extensions/default_theme/views/layout.haml +33 -0
- data/lib/aura.rb +315 -0
- data/lib/aura/admin.rb +41 -0
- data/lib/aura/app.rb +4 -0
- data/lib/aura/cli.rb +19 -0
- data/lib/aura/cli/base.rb +89 -0
- data/lib/aura/cli/helpers.rb +32 -0
- data/lib/aura/editor.rb +30 -0
- data/lib/aura/extension.rb +189 -0
- data/lib/aura/files.rb +38 -0
- data/lib/aura/menu.rb +142 -0
- data/lib/aura/models.rb +80 -0
- data/lib/aura/public.rb +68 -0
- data/lib/aura/rendering.rb +134 -0
- data/lib/aura/seeder.rb +38 -0
- data/lib/aura/slugs.rb +87 -0
- data/lib/aura/subtype.rb +48 -0
- data/lib/aura/tasks.rb +24 -0
- data/lib/aura/tasks/common.rb +17 -0
- data/lib/aura/tasks/db.rake +54 -0
- data/lib/aura/utils.rb +81 -0
- data/lib/aura/version.rb +25 -0
- data/lib/core/hasharray.rb +65 -0
- data/lib/core/object_ext.rb +9 -0
- data/lib/sequel/plugins/aura_custom.rb +16 -0
- data/lib/sequel/plugins/aura_editable.rb +39 -0
- data/lib/sequel/plugins/aura_hierarchy.rb +82 -0
- data/lib/sequel/plugins/aura_model.rb +271 -0
- data/lib/sequel/plugins/aura_renderable.rb +42 -0
- data/lib/sequel/plugins/aura_sluggable.rb +103 -0
- data/lib/sequel/plugins/aura_subtyped.rb +83 -0
- data/lib/terra.rb +185 -0
- data/lib/terra/ext.rb +16 -0
- data/lib/terra/field.rb +98 -0
- data/lib/terra/fields.rb +122 -0
- data/lib/terra/fieldset.rb +93 -0
- data/lib/terra/form.rb +111 -0
- data/manual/configuration.md +42 -0
- data/manual/extensions.md +45 -0
- data/manual/files.md +70 -0
- data/manual/helpers.md +39 -0
- data/manual/index.md +65 -0
- data/manual/models.md +58 -0
- data/manual/recipes.md +38 -0
- data/manual/recipes/bundling_sample_data.md +30 -0
- data/manual/recipes/creating_themes.md +10 -0
- data/manual/recipes/using_markdown_or_textile.md +24 -0
- data/manual/routes.md +39 -0
- data/manual/theming.md +55 -0
- data/manual/views.md +128 -0
- data/public/hi.html +0 -0
- data/public/images/admin/back.png +0 -0
- data/public/images/admin/browse.png +0 -0
- data/public/images/admin/mock-bg.png +0 -0
- data/public/images/admin/top-loader.gif +0 -0
- data/public/images/admin/uiscreen-loader.gif +0 -0
- data/public/images/admin_icons/add.png +0 -0
- data/public/images/admin_icons/contact.png +0 -0
- data/public/images/admin_icons/dashboard.png +0 -0
- data/public/images/admin_icons/generic.png +0 -0
- data/public/images/admin_icons/home-12.png +0 -0
- data/public/images/admin_icons/page.png +0 -0
- data/public/images/admin_icons/settings.png +0 -0
- data/public/images/jquery.wysiwyg.gif +0 -0
- data/public/js/admin.form_builder.js +15 -0
- data/public/js/admin.js +62 -0
- data/public/js/admin.layout.js +53 -0
- data/public/js/admin.nav.js +241 -0
- data/public/js/admin.slug.js +46 -0
- data/public/js/admin.subpage.js +15 -0
- data/public/js/jquery.hashlisten.js +85 -0
- data/public/js/jquery.js +166 -0
- data/public/js/jquery.livenavigate.js +58 -0
- data/public/js/jquery.livequery.js +226 -0
- data/public/js/jquery.quickvalidate.js +164 -0
- data/public/js/jquery.tmpl.js +486 -0
- data/public/js/jquery.uiscreen.js +150 -0
- data/public/js/jquery.wysiwyg.js +2339 -0
- data/public/js/jqueryui.js +766 -0
- data/public/js/lib.dirty.js +11 -0
- data/public/js/lib.loading.js +23 -0
- data/public/js/lib.wysiwyg.js +155 -0
- data/public/js/underscore-1.1.7.js +27 -0
- data/test/app/app/css/test_raw.css +1 -0
- data/test/app/app/css/test_sass.sass +3 -0
- data/test/app/app/damogram.txt +1 -0
- data/test/app/app/js/test_coffee.coffee +4 -0
- data/test/app/app/js/test_javascript.js +4 -0
- data/test/app/init.rb +5 -0
- data/test/stories/admin_css_story.rb +18 -0
- data/test/stories/css_js_story.rb +29 -0
- data/test/stories/first_login_story.rb +29 -0
- data/test/stories/visit_story.rb +39 -0
- data/test/stories_helper.rb +58 -0
- data/test/test_cli_helper.rb +31 -0
- data/test/test_helper.rb +111 -0
- data/test/test_temp_helper.rb +9 -0
- data/test/unit/cli_test.rb +38 -0
- data/test/unit/dump_test.rb +14 -0
- data/test/unit/extensions_test.rb +18 -0
- data/test/unit/files_test.rb +14 -0
- data/test/unit/flash_helper_test.rb +36 -0
- data/test/unit/html_helper_test.rb +29 -0
- data/test/unit/jquery_helper_test.rb +18 -0
- data/test/unit/model_test.rb +34 -0
- data/test/unit/page_helpers_test.rb +36 -0
- data/test/unit/seeder_test.rb +15 -0
- data/test/unit/settings_test.rb +29 -0
- data/test/unit/slug_test.rb +39 -0
- data/test/unit/ss_migration_test.rb +14 -0
- data/test/unit/terra_test.rb +125 -0
- data/test/unit/utils_test.rb +11 -0
- data/vendor/sinatra-sequel/.gitignore +3 -0
- data/vendor/sinatra-sequel/COPYING +18 -0
- data/vendor/sinatra-sequel/README.md +84 -0
- data/vendor/sinatra-sequel/Rakefile +67 -0
- data/vendor/sinatra-sequel/lib/sinatra/sequel.rb +73 -0
- data/vendor/sinatra-sequel/sinatra-sequel.gemspec +39 -0
- data/vendor/sinatra-sequel/spec/spec_sinatra_sequel.rb +70 -0
- metadata +536 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
class Main
|
2
|
+
module TemplateHelpers
|
3
|
+
# Makes a template extend upon another template.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
#
|
7
|
+
# -# Should be the first line.
|
8
|
+
# != extends :'base/edit', options
|
9
|
+
#
|
10
|
+
# - content_for! :body do
|
11
|
+
# This will override the body of the base/edit template
|
12
|
+
#
|
13
|
+
def extends(name, locals={})
|
14
|
+
partial name, locals
|
15
|
+
end
|
16
|
+
|
17
|
+
# Template helper: partial (Helpers)
|
18
|
+
# Renders a partial.
|
19
|
+
#
|
20
|
+
def partial(template, *args) #locals={}, options={}
|
21
|
+
if template.respond_to?(:templates_for)
|
22
|
+
template = template.templates_for(args.shift || 'index')
|
23
|
+
end
|
24
|
+
|
25
|
+
locals = args.shift || {}
|
26
|
+
options = args.shift || {}
|
27
|
+
|
28
|
+
layout, @layout = @layout, nil
|
29
|
+
out = show template, {:layout => false}.merge(options), locals
|
30
|
+
@layout = layout
|
31
|
+
out
|
32
|
+
end
|
33
|
+
|
34
|
+
# Template helper: has_content? (Helpers)
|
35
|
+
# Checks if a given content block is defined.
|
36
|
+
#
|
37
|
+
def has_content?(key)
|
38
|
+
return false unless content_blocks.keys.include?(key.to_sym)
|
39
|
+
content_blocks[key.to_sym].any?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Template helper: content_for! (Helpers)
|
43
|
+
# Like content_for, but overwrites any blocks.
|
44
|
+
#
|
45
|
+
def content_for!(key, &blk)
|
46
|
+
content_blocks[key.to_sym] = Array.new
|
47
|
+
content_for key, &blk
|
48
|
+
end
|
49
|
+
|
50
|
+
# Template helper: content_for? (Helpers)
|
51
|
+
# Synonym of has_content?
|
52
|
+
#
|
53
|
+
def content_for?(key)
|
54
|
+
(content_blocks[key.to_sym] || Array.new).any?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Template helper: yield_content_of (Helpers)
|
58
|
+
# Loads a given template and yields a certain content block of it.
|
59
|
+
#
|
60
|
+
# ## Usage
|
61
|
+
# yield_content_of(template, section[, locals])
|
62
|
+
# yield_content_of(model, template, section[, locals])
|
63
|
+
#
|
64
|
+
def yield_content_of(template, *args) #section, locals={}
|
65
|
+
if template.respond_to?(:templates_for)
|
66
|
+
template = template.templates_for(args.shift || :index)
|
67
|
+
end
|
68
|
+
|
69
|
+
section = args.shift || :content
|
70
|
+
locals = args.shift || {}
|
71
|
+
|
72
|
+
custom_activate!
|
73
|
+
|
74
|
+
show template, { :layout => false }, locals
|
75
|
+
ret = yield_content(section)
|
76
|
+
|
77
|
+
custom_deactivate!
|
78
|
+
ret
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
def custom_activate!
|
83
|
+
@old_content_blocks ||= Array.new
|
84
|
+
@old_content_blocks << @content_blocks
|
85
|
+
@content_blocks = Hash.new { |h, k| h[k] = [] }
|
86
|
+
end
|
87
|
+
|
88
|
+
def custom_deactivate!
|
89
|
+
@content_blocks = @old_content_blocks.pop
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
helpers TemplateHelpers
|
94
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Main
|
2
|
+
module UserHelpers
|
3
|
+
# User helper: logged_in? (Helpers)
|
4
|
+
# Checks if there is a user logged in or not.
|
5
|
+
#
|
6
|
+
def logged_in?
|
7
|
+
!! current_user
|
8
|
+
end
|
9
|
+
|
10
|
+
# User helper: current_user (Helpers)
|
11
|
+
# Returns the current user as an instance of {Aura::Models::User}.
|
12
|
+
#
|
13
|
+
def current_user
|
14
|
+
authenticated(User)
|
15
|
+
end
|
16
|
+
|
17
|
+
# User helper: require_login (Helpers)
|
18
|
+
# Ensures that a route is only accessible to logged in users.
|
19
|
+
#
|
20
|
+
def require_login
|
21
|
+
redirect R(:login) unless logged_in?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Overridden in aura to track last login time.
|
25
|
+
# This is called when a user logs in.
|
26
|
+
#
|
27
|
+
def redirect_to_return_url(session_key = :return_to, default = '/admin')
|
28
|
+
u = current_user
|
29
|
+
first_login = u.last_login.nil?
|
30
|
+
|
31
|
+
u.last_login = Time.now
|
32
|
+
u.save
|
33
|
+
|
34
|
+
# On a user's first login, go to a admin welcome page
|
35
|
+
# where they can change their password.
|
36
|
+
if first_login
|
37
|
+
redirect R(:admin, :welcome)
|
38
|
+
end
|
39
|
+
|
40
|
+
redirect session.delete(:return_to) || default
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
helpers UserHelpers
|
45
|
+
end
|
data/app/init/admin.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Aura.admin.menu.tap { |m|
|
2
|
+
m.add "settings",
|
3
|
+
:name => "Settings",
|
4
|
+
:href => Rtopia.R(:admin, :settings),
|
5
|
+
:icon => 'settings'
|
6
|
+
|
7
|
+
m.add "settings.database",
|
8
|
+
:name => "Database",
|
9
|
+
:href => Rtopia.R(:admin, :settings, :database)
|
10
|
+
|
11
|
+
m.add "settings.your_account",
|
12
|
+
:name => "Your account",
|
13
|
+
:href => Rtopia.R(:user, :me, :edit)
|
14
|
+
|
15
|
+
m.add "settings.users",
|
16
|
+
:name => "Users",
|
17
|
+
:href => Rtopia.R(:user, :list)
|
18
|
+
}
|
19
|
+
|
20
|
+
Main.register Sinatra::CompressedJS
|
21
|
+
|
22
|
+
path = Main.root_path(%w(public js))
|
23
|
+
|
24
|
+
Main.serve_compressed_js :admin_js,
|
25
|
+
:prefix => '/js',
|
26
|
+
:root => path,
|
27
|
+
:path => '/admin/script.js',
|
28
|
+
:files =>
|
29
|
+
Dir["#{path}/jquery.*.js"].sort +
|
30
|
+
Dir["#{path}/lib.*.js"].sort +
|
31
|
+
Dir["#{path}/admin.js"].sort +
|
32
|
+
Dir["#{path}/admin.*.js"].sort
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Load extensions
|
2
|
+
Aura::Extension.active.each { |ext| ext.load! }
|
3
|
+
|
4
|
+
seed_file = Main.approot('config/seed.yml')
|
5
|
+
|
6
|
+
# If the file config/seed.yml is present, use that to initialize the DB.
|
7
|
+
# Only if the DB is pristine, though!
|
8
|
+
if File.exists?(seed_file) and Main.database.tables.empty?
|
9
|
+
puts "Note: Restoring sample data from config/seed.yml."
|
10
|
+
Aura.db_restore YAML::load_file(seed_file)
|
11
|
+
|
12
|
+
# ..otherwise, setup the database: do migrations and put in fresh data.
|
13
|
+
else
|
14
|
+
Aura.run_migrations!
|
15
|
+
Main.seed
|
16
|
+
end
|
17
|
+
|
18
|
+
Aura::Extension.active.each { |ext| ext.init }
|
data/app/init/pistol.rb
ADDED
data/app/init/sequel.rb
ADDED
data/app/main.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
root = Aura.method(:gem_root)
|
2
|
+
approot = Aura.method(:root)
|
3
|
+
|
4
|
+
$:.unshift *Dir[root["/vendor/*/lib"]]
|
5
|
+
require "sinatra/base"
|
6
|
+
require "sinatra/support"
|
7
|
+
require "rtopia"
|
8
|
+
require "sequel"
|
9
|
+
require "sinatra/content_for"
|
10
|
+
require "sinatra/sequel"
|
11
|
+
require "pistol"
|
12
|
+
require "json"
|
13
|
+
require "yaml"
|
14
|
+
require "shield"
|
15
|
+
require "ostruct"
|
16
|
+
require "fileutils"
|
17
|
+
|
18
|
+
# Helpers
|
19
|
+
require root['lib/core/hasharray']
|
20
|
+
require root['lib/core/object_ext']
|
21
|
+
|
22
|
+
# Aura proper
|
23
|
+
require root['lib/aura']
|
24
|
+
require root['lib/terra']
|
25
|
+
require root['lib/terra/ext']
|
26
|
+
|
27
|
+
if defined?(::Encoding)
|
28
|
+
Encoding.default_external = 'utf-8'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Class: Main
|
32
|
+
# The main Sinatra application.
|
33
|
+
#
|
34
|
+
# ## Description
|
35
|
+
# This is the main application. It is also accessible as `Aura::App`.
|
36
|
+
#
|
37
|
+
class Main < Sinatra::Base
|
38
|
+
set :root, lambda { |*args| File.join(ENV['AURA_ROOT'], *args) }
|
39
|
+
set :root_path, lambda { |*args| root *args }
|
40
|
+
set :approot, lambda { |*args| File.join(ENV['APP_ROOT'] || root, *args) }
|
41
|
+
|
42
|
+
set :haml, :escape_html => true
|
43
|
+
set :haml, :escape_html => true, :ugly => true if production?
|
44
|
+
|
45
|
+
enable :raise_errors
|
46
|
+
|
47
|
+
use Rack::Session::Cookie
|
48
|
+
use Rack::Deflater if production?
|
49
|
+
|
50
|
+
register Aura::Public
|
51
|
+
register Aura::Rendering
|
52
|
+
register Aura::Seeder
|
53
|
+
register Sinatra::SequelExtension
|
54
|
+
|
55
|
+
helpers Rtopia
|
56
|
+
helpers Sinatra::ContentFor
|
57
|
+
helpers Sinatra::UserAgentHelpers
|
58
|
+
helpers Shield::Helpers
|
59
|
+
|
60
|
+
# Load all, but load defaults first
|
61
|
+
( Dir[root('config/*.rb')].sort +
|
62
|
+
Dir[approot('config/*.rb')].sort
|
63
|
+
).uniq.each { |f| load f }
|
64
|
+
|
65
|
+
register Sinatra::CompassSupport
|
66
|
+
|
67
|
+
set :login_success_message, nil
|
68
|
+
|
69
|
+
set :multi_views, [root('app/views')]
|
70
|
+
set :app_files, [ENV['APP_FILE']] + Dir[root('**/*.rb')] + Dir[approot('**/*.rb')]
|
71
|
+
set :extensions_path, [root('extensions'), approot('extensions')]
|
72
|
+
|
73
|
+
# Heroku - override the DB config with this env var.
|
74
|
+
set :database_url, ENV['DATABASE_URL'] unless ENV['DATABASE_URL'].nil?
|
75
|
+
|
76
|
+
add_public approot('public')
|
77
|
+
|
78
|
+
def self.restart!
|
79
|
+
require 'fileutils'
|
80
|
+
FileUtils.touch approot('tmp', 'restart.txt')
|
81
|
+
end
|
82
|
+
|
83
|
+
# Connect to db
|
84
|
+
database
|
85
|
+
end
|
86
|
+
|
87
|
+
# Initializers
|
88
|
+
require root['app/init/pistol.rb']
|
89
|
+
require root['app/init/admin.rb']
|
90
|
+
require root['app/init/sequel.rb']
|
91
|
+
|
92
|
+
# Bootstrap Aura
|
93
|
+
Dir[root['app/{models,helpers,routes}/**/*.rb']].each { |f| require f }
|
94
|
+
|
95
|
+
# Extensions
|
96
|
+
require root['app/init/extensions.rb']
|
97
|
+
|
98
|
+
# Load app/
|
99
|
+
if File.directory?(Main.approot('app'))
|
100
|
+
Aura::Extension.new(Main.approot('app')).load!
|
101
|
+
end
|
102
|
+
|
103
|
+
Aura::App = Main
|
104
|
+
|
105
|
+
Main.set :port, ENV['PORT'].to_i unless ENV['PORT'].nil?
|
106
|
+
Main.run! if ENV['APP_FILE'] == $0
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Main
|
2
|
+
migration "Aura v0.0.1 - page" do
|
3
|
+
database.create_table :pages do
|
4
|
+
# aura_hierarchy
|
5
|
+
primary_key :id
|
6
|
+
foreign_key :parent_id, :pages
|
7
|
+
|
8
|
+
String :title
|
9
|
+
String :body, :text => true
|
10
|
+
String :custom, :text => true
|
11
|
+
|
12
|
+
# aura_sluggable
|
13
|
+
String :slug
|
14
|
+
|
15
|
+
# aura_subtyped
|
16
|
+
String :subtype
|
17
|
+
|
18
|
+
String :author_name #unused
|
19
|
+
|
20
|
+
String :meta_keywords
|
21
|
+
String :meta_description
|
22
|
+
|
23
|
+
Boolean :shown_in_menu
|
24
|
+
|
25
|
+
Time :created_at
|
26
|
+
Time :modified_at
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/app/models/page.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# Model: Page
|
2
|
+
# Inherits: {AuraModel} {AuraSluggable} {AuraRenderable} {AuraEditable} {AuraHierarchy} {AuraSubtyped}
|
3
|
+
# The page model.
|
4
|
+
#
|
5
|
+
# ## Inherits from
|
6
|
+
# * {AuraModel}
|
7
|
+
# * {AuraSluggable}
|
8
|
+
# * {AuraRenderable}
|
9
|
+
# * {AuraEditable}
|
10
|
+
# * {AuraHierarchy}
|
11
|
+
# * {AuraSubtyped}
|
12
|
+
#
|
13
|
+
class Page < Sequel::Model
|
14
|
+
plugin :aura_sluggable # Accessible via slug: /about-us/services
|
15
|
+
plugin :aura_renderable # Can show a page when accessed by that URL
|
16
|
+
plugin :aura_editable # Editable in the admin area
|
17
|
+
plugin :aura_hierarchy # Can have children
|
18
|
+
plugin :aura_subtyped # Has subtypes
|
19
|
+
|
20
|
+
plugin :timestamps
|
21
|
+
plugin :serialization, :yaml, :custom
|
22
|
+
|
23
|
+
form do
|
24
|
+
# title (show it big), main-title (use it on the page heading)
|
25
|
+
text :title, "Page title", :class => 'title main-title no-label assert required'
|
26
|
+
html :body, "Body text", :class => 'long no-label'
|
27
|
+
text :slug, "Slug", :class => 'compact hide'
|
28
|
+
|
29
|
+
# fieldset(:meta, "Metadata") do
|
30
|
+
# text :meta_keywords, "Keywords", :class => 'compact-top'
|
31
|
+
# text :meta_description, "Description", :class => 'compact-bottom'
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(*a)
|
36
|
+
super
|
37
|
+
self.shown_in_menu = true if self.shown_in_menu.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def shown_in_menu?
|
41
|
+
!! self.shown_in_menu
|
42
|
+
end
|
43
|
+
|
44
|
+
# Method: child_subtypes (Page)
|
45
|
+
# Returns an array of Subtypes allowed for its children.
|
46
|
+
def child_subtypes
|
47
|
+
types = self.class.subtypes
|
48
|
+
types.select! { |t| self.subtype.allowed_subtypes.include? t.id.to_sym } if self.try(:subtype).try(:allowed_subtypes).is_a?(Array)
|
49
|
+
types
|
50
|
+
end
|
51
|
+
|
52
|
+
# Method: subtypes (Page)
|
53
|
+
# Returns an array of Subtypes allowed for this page.
|
54
|
+
def subtypes
|
55
|
+
parent? ? parent.child_subtypes : self.class.subtypes
|
56
|
+
end
|
57
|
+
|
58
|
+
# Method: parentable? (Page)
|
59
|
+
# Checks if a given page can have children from the admin interface.
|
60
|
+
def parentable?
|
61
|
+
return false if self.subtype && self.subtype.parentable? == false
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Method: deletable? (Page)
|
66
|
+
# Checks if a given page can be deleted from the admin interface.
|
67
|
+
def deletable?
|
68
|
+
return false if self.subtype && self.subtype.deletable? == false
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate
|
73
|
+
super
|
74
|
+
validates_presence :title
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the *other* form that depends on the subtype.
|
78
|
+
def subform
|
79
|
+
return nil if subtype.nil?
|
80
|
+
self.class.form subtype._id
|
81
|
+
end
|
82
|
+
|
83
|
+
# Class method: custom_field (Page)
|
84
|
+
# Creates a custom field and adds getters/setters for it.
|
85
|
+
#
|
86
|
+
# ## Example
|
87
|
+
#
|
88
|
+
# #### Creating custom fields
|
89
|
+
#
|
90
|
+
# [app/models/page-ext.rb (rb)]
|
91
|
+
# class Page
|
92
|
+
# custom_field :recipe
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# p = Page.new
|
96
|
+
# p.recipe = "Chili Con Carne"
|
97
|
+
#
|
98
|
+
def self.custom_field(name)
|
99
|
+
name = name.to_sym
|
100
|
+
self.send(:define_method, name) do
|
101
|
+
self.custom[name] if self.custom.is_a? Hash
|
102
|
+
end
|
103
|
+
|
104
|
+
self.send(:define_method, :"#{name}=") do |v|
|
105
|
+
self.custom ||= Hash.new
|
106
|
+
self.custom[name] = v
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.content?; true; end
|
111
|
+
def self.show_on_sidebar?; true; end
|
112
|
+
|
113
|
+
# Class method: root_creatable? (Page)
|
114
|
+
# Returns 'true' if the "Add new page" should be shown.
|
115
|
+
def self.root_creatable?; true; end
|
116
|
+
end
|