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,22 @@
|
|
1
|
+
html { background-image: url(/images/admin/uiscreen-loader.gif); }
|
2
|
+
html { background-image: none; }
|
3
|
+
|
4
|
+
/* UIscreen */
|
5
|
+
.uiscreen {
|
6
|
+
position: relative; background: transparent;
|
7
|
+
cursor: wait;
|
8
|
+
}
|
9
|
+
|
10
|
+
$height: 60px;
|
11
|
+
|
12
|
+
.uiscreen#uiscreen-for-area {
|
13
|
+
background: fade-out(white, 0.5);
|
14
|
+
.uiscreen-spinner {
|
15
|
+
@include border-radius($height / 2);
|
16
|
+
@include shadow(0 0 10px $blue-glow-70, inset 0 0 2px $blue);
|
17
|
+
width: $height; height: $height;
|
18
|
+
background: #111 url(/images/admin/uiscreen-loader.gif) center center no-repeat;
|
19
|
+
position: absolute; top: 45%; left: 45%;
|
20
|
+
text-decoration: none;
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
@import "compass/css3";
|
2
|
+
@import "utilities";
|
3
|
+
|
4
|
+
#admin_watermark {
|
5
|
+
@include border-top-radius(4px);
|
6
|
+
|
7
|
+
background: rgba(0,0,0,0.8); padding: 0; position: fixed; bottom: 0; left: 20px;
|
8
|
+
color: #aaa;
|
9
|
+
font-size: 8pt; line-height: 22pt; margin: 0;
|
10
|
+
strong { font-weight: normal; }
|
11
|
+
ul, ul li { list-style-type: none; margin: 0; padding: 0; }
|
12
|
+
li { display: block; float: left; border-right: solid 1px $hilite10; }
|
13
|
+
li:last-child { border-right: 0; }
|
14
|
+
li a {
|
15
|
+
padding: 0; margin: 0; color: #7bd; font-weight: bold; display: block;
|
16
|
+
&:hover { background: $hilite10; }
|
17
|
+
text-decoration: none;
|
18
|
+
}
|
19
|
+
li>span, li>a { padding-left: 8px; padding-right: 8px; }
|
20
|
+
|
21
|
+
opacity: 0.95;
|
22
|
+
&:hover { opacity: 1; }
|
23
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
@import "compass/css3";
|
2
|
+
@import "admin/settings";
|
3
|
+
|
4
|
+
body { font: 11pt/1.6 arial, sans-serif; background: white; color: #888; }
|
5
|
+
#message { padding: 20px; width: 400px; margin: 80px auto 40px auto; text-align: center; }
|
6
|
+
h1 { color: #333; text-align: center; line-height: 1.3; }
|
7
|
+
h1, p { margin: 20px 0; }
|
8
|
+
a.button {
|
9
|
+
@include button;
|
10
|
+
@include button-black;
|
11
|
+
}
|
12
|
+
p.action { margin: 30px 0; }
|
13
|
+
|
data/app/css/login.scss
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
@import "compass/css3";
|
2
|
+
@import "admin/settings";
|
3
|
+
@import "admin/reset";
|
4
|
+
|
5
|
+
$reset-font: helvetica, sans-serif;
|
6
|
+
$reset-heading-font: $reset-font;
|
7
|
+
|
8
|
+
@include ae-reset;
|
9
|
+
|
10
|
+
body { background: $charcoal; color: #aab; }
|
11
|
+
form { width: 300px; margin: 0 auto; background: white; padding: 10px; }
|
12
|
+
|
13
|
+
form {
|
14
|
+
text-align: center;
|
15
|
+
padding: 10px 20px;
|
16
|
+
text-shadow: 1px 1px 0 $hilite30;
|
17
|
+
@include gradient(#fff, #f0f0f0);
|
18
|
+
@include border-radius(4px);
|
19
|
+
@include shadow(0 0 5px $shadow10,
|
20
|
+
1px 1px 0 $shadow10,
|
21
|
+
inset -1px -1px 0 $hilite50);
|
22
|
+
|
23
|
+
label {
|
24
|
+
display: block;
|
25
|
+
margin-bottom: 5px; font-weight: bold;
|
26
|
+
text-align: left; color: $slate;
|
27
|
+
}
|
28
|
+
|
29
|
+
input {
|
30
|
+
@include box-sizing(border-box);
|
31
|
+
@include input-base;
|
32
|
+
padding: 10px;
|
33
|
+
font-size: 12pt;
|
34
|
+
@include input-focus;
|
35
|
+
width: 100%;
|
36
|
+
}
|
37
|
+
p.submit { padding-top: 10px; }
|
38
|
+
button { @include button; @include button-black; font-weight: bold; }
|
39
|
+
}
|
40
|
+
|
41
|
+
form .flash {
|
42
|
+
ul { list-style-type: none; border-bottom: dotted 1px #ddd; padding-bottom: 10px; }
|
43
|
+
}
|
44
|
+
|
45
|
+
form .flash.errors { color: #c8a; }
|
46
|
+
|
47
|
+
h1 { text-align: center; margin: 50px 0; padding: 0; line-height: 1; }
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Main
|
2
|
+
module AdminHelpers
|
3
|
+
# Admin helper: show_admin (Helpers)
|
4
|
+
# Renders an admin page with the admin template.
|
5
|
+
#
|
6
|
+
def show_admin(template, *args) #template, locals={})
|
7
|
+
if template.respond_to?(:templates_for)
|
8
|
+
template = template.templates_for(args.shift || 'index')
|
9
|
+
end
|
10
|
+
|
11
|
+
locals = args.shift || {}
|
12
|
+
|
13
|
+
show template, { :layout => :'admin/layout' }, locals
|
14
|
+
end
|
15
|
+
|
16
|
+
def area_class(str=nil)
|
17
|
+
@area_class = str unless str.nil?
|
18
|
+
@area_class
|
19
|
+
end
|
20
|
+
|
21
|
+
# Admin helper: admin_icon (Helpers)
|
22
|
+
# Draws an img tag of the given icon.
|
23
|
+
#
|
24
|
+
# ## Example
|
25
|
+
#
|
26
|
+
# != admin_icon('add')
|
27
|
+
# #=> <img src='/images/admin_icons/add.png' class='icon'>
|
28
|
+
#
|
29
|
+
def admin_icon(icon)
|
30
|
+
icon = "#{icon}.png" unless icon.to_s.include?('.')
|
31
|
+
tag(:img, nil, { :src => "/images/admin_icons/#{icon}", :class => 'icon' })
|
32
|
+
end
|
33
|
+
|
34
|
+
# Admin helper: admin_back_to_dashboard (Helpers)
|
35
|
+
# Renders a 'back to dashboard' link in the sidebar.
|
36
|
+
#
|
37
|
+
# ## Example
|
38
|
+
#
|
39
|
+
# - content_for :nav do
|
40
|
+
# != admin_back_to_dashboard
|
41
|
+
# %nav
|
42
|
+
# %ul
|
43
|
+
# ...
|
44
|
+
#
|
45
|
+
def admin_back_to_dashboard
|
46
|
+
partial :'admin/_back_to_dashboard'
|
47
|
+
end
|
48
|
+
|
49
|
+
# Admin helper: admin_watermark (Helpers)
|
50
|
+
# Shows the link to the admin page from the public site.
|
51
|
+
#
|
52
|
+
def admin_watermark
|
53
|
+
return if current_user.nil?
|
54
|
+
partial 'watermark/watermark'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
helpers AdminHelpers
|
59
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class Main
|
2
|
+
module FlashHelpers
|
3
|
+
# Flash helper: flash_messages? (Helpers)
|
4
|
+
# Checks if there are messages to flash.
|
5
|
+
#
|
6
|
+
# ## Description
|
7
|
+
# See {Helpers:flash_message} for an example.
|
8
|
+
#
|
9
|
+
def flash_messages?(key=:success)
|
10
|
+
!(session[key].nil?)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Flash helper: flash_messages (Helpers)
|
14
|
+
# Returns a list of messages to flash.
|
15
|
+
#
|
16
|
+
# ## Description
|
17
|
+
# See {Helpers:flash_message} for an example.
|
18
|
+
#
|
19
|
+
def flash_messages(key=:success)
|
20
|
+
ret = session[key]
|
21
|
+
session.delete key
|
22
|
+
[ret].flatten.compact
|
23
|
+
end
|
24
|
+
|
25
|
+
# Flash helper: flash_message (Helpers)
|
26
|
+
# Flashes a message.
|
27
|
+
#
|
28
|
+
# #### Flash a message
|
29
|
+
# Use `flash_message` in your routes to flash a message.
|
30
|
+
#
|
31
|
+
# flash_message "Your changes have been saved."
|
32
|
+
#
|
33
|
+
# #### Showing messages
|
34
|
+
# In your layouts, use `flash_messages` to show it.
|
35
|
+
#
|
36
|
+
# [app/views/layout.haml (haml)]
|
37
|
+
#
|
38
|
+
# - if flash_messages?
|
39
|
+
# #messages
|
40
|
+
# - flash_messages.each do |msg|
|
41
|
+
# %li= msg
|
42
|
+
#
|
43
|
+
# - if flash_errors?
|
44
|
+
# #errors
|
45
|
+
# - flash_errors.each do |msg|
|
46
|
+
# %li= msg
|
47
|
+
#
|
48
|
+
def flash_message(msg, key=:success)
|
49
|
+
session[key] ||= []
|
50
|
+
session[key] = [session[key]] unless session[key].is_a?(Array)
|
51
|
+
session[key] << msg
|
52
|
+
end
|
53
|
+
|
54
|
+
# Flash helper: flash_errors? (Helpers)
|
55
|
+
# Checks if there are errors to flash.
|
56
|
+
#
|
57
|
+
# ## Description
|
58
|
+
# See {Helpers:flash_message} for an example.
|
59
|
+
#
|
60
|
+
def flash_errors?
|
61
|
+
flash_messages?(:error)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Flash helper: flash_errors (Helpers)
|
65
|
+
# Returns a list of errors to flash.
|
66
|
+
#
|
67
|
+
# ## Description
|
68
|
+
# See {Helpers:flash_message} for an example.
|
69
|
+
#
|
70
|
+
def flash_errors
|
71
|
+
flash_messages(:error)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Flash helper: flash_error (Helpers)
|
75
|
+
# Flashes an error.
|
76
|
+
#
|
77
|
+
# ## Description
|
78
|
+
# See {Helpers:flash_message} for an example.
|
79
|
+
#
|
80
|
+
def flash_error(msg)
|
81
|
+
flash_message msg, :error
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
helpers FlashHelpers
|
86
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Main
|
2
|
+
module HtmlHelpers
|
3
|
+
# Helper: html (Helpers)
|
4
|
+
# Sanitizes HTML with Markdown and Textile support.
|
5
|
+
#
|
6
|
+
def html(string)
|
7
|
+
require 'nokogiri'
|
8
|
+
|
9
|
+
doc = Nokogiri.HTML(string)
|
10
|
+
|
11
|
+
# Convert textile/markdown
|
12
|
+
%w(textile markdown).each do |type|
|
13
|
+
doc.css("[format='#{type}'], #{type}").each do |el|
|
14
|
+
el.after(Tilt.new(type) { el.inner_html }.render)
|
15
|
+
el.remove
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Stupidity
|
20
|
+
doc.css('p:empty').each { |el| el.remove }
|
21
|
+
|
22
|
+
doc.at_css('body').inner_html.strip
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
helpers HtmlHelpers
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Main
|
2
|
+
module JqueryHelpers
|
3
|
+
def jquery(path='/js/jquery.js', version='1.4.3')
|
4
|
+
if settings.production?
|
5
|
+
# Grab Google CDN's jQuery; fallback to local if necessary
|
6
|
+
url = "http://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"
|
7
|
+
"<script type='text/javascript' src=\"#{url}\"></script>"+
|
8
|
+
"<script>!window.jQuery && document.write('<script src=\"#{path}\"><\\/script>')</script>"
|
9
|
+
else
|
10
|
+
"<script type='text/javascript' src='#{path}'></script>"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def jquery_ui(path='/js/jqueryui.js', version='1.8.5')
|
15
|
+
if settings.production?
|
16
|
+
url = "http://ajax.googleapis.com/ajax/libs/jqueryui/#{version}/jquery-ui.min.js"
|
17
|
+
"<script type='text/javascript' src=\"#{url}\"></script>"+
|
18
|
+
"<script>!window.jQuery.ui && document.write('<script src=\"#{path}\"><\\/script>')</script>"
|
19
|
+
else
|
20
|
+
"<script type='text/javascript' src='#{path}'></script>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
helpers JqueryHelpers
|
26
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Main
|
2
|
+
module MainHelpers
|
3
|
+
# Helper: h (Helpers)
|
4
|
+
# Escapes an HTML string.
|
5
|
+
#
|
6
|
+
def h(str)
|
7
|
+
Rack::Utils.escape_html(str)
|
8
|
+
end
|
9
|
+
|
10
|
+
def settings
|
11
|
+
self.class
|
12
|
+
end
|
13
|
+
|
14
|
+
# Helper: labeled_checkbox (Helpers)
|
15
|
+
# Draws a checkbox with a label.
|
16
|
+
#
|
17
|
+
# ## Usage
|
18
|
+
# labeled_checkbox(label, name, value[, attributes]])
|
19
|
+
#
|
20
|
+
# ## Example
|
21
|
+
# != labeled_checkbox "I accept", :accept, true
|
22
|
+
#
|
23
|
+
def labeled_checkbox(label, name, value, options={})
|
24
|
+
id = options.delete(:id) || name
|
25
|
+
|
26
|
+
attrs = options.map { |(k, v)| " #{h k}='#{h v}'" }.join('')
|
27
|
+
|
28
|
+
[ "<label#{attrs} class='checkbox' for='#{id}'>",
|
29
|
+
checkbox(name, value, :id => id),
|
30
|
+
"<span>#{h label}</span>",
|
31
|
+
"</label>"
|
32
|
+
].join("\n")
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Helper: checkbox (Helpers)
|
37
|
+
# Draws a checkbox with a hidden field.
|
38
|
+
#
|
39
|
+
# ## Usage
|
40
|
+
# checkbox(name[, value[, attributes]])
|
41
|
+
#
|
42
|
+
# ## Example
|
43
|
+
# != checkbox :accept, true
|
44
|
+
#
|
45
|
+
def checkbox(name, value=nil, options={})
|
46
|
+
selected = ''
|
47
|
+
selected = " checked='1'" if value
|
48
|
+
attrs = options.map { |(k, v)| " #{h k}='#{h v}'" }.join('')
|
49
|
+
|
50
|
+
[ "<input type='hidden' name='#{name}' value='0'>" +
|
51
|
+
"<input#{attrs} type='checkbox' name='#{name}' value='1'#{selected}>"
|
52
|
+
].join("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
def select_options(items, active='', value_field=:id, name_field=:to_s)
|
56
|
+
items.map do |item|
|
57
|
+
selected = ''
|
58
|
+
selected = " selected='1'" if item == active
|
59
|
+
[ "<option value='#{h item.try(value_field)}'#{selected}>",
|
60
|
+
h(item.try(name_field)),
|
61
|
+
"</option>" ].join('')
|
62
|
+
end.join("\n")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
helpers MainHelpers
|
67
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class Main
|
2
|
+
module PageHelpers
|
3
|
+
# Page helper: body_class (Helpers)
|
4
|
+
# Sets or gets the class for the body.
|
5
|
+
#
|
6
|
+
def body_class(v = nil)
|
7
|
+
@body_classes ||= []
|
8
|
+
@body_classes << v if v
|
9
|
+
|
10
|
+
@body_classes.join(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Page helper: title (Helpers)
|
14
|
+
# Sets or gets the title for the page.
|
15
|
+
#
|
16
|
+
def title(title=nil)
|
17
|
+
@page_title = title if title
|
18
|
+
@page_title
|
19
|
+
end
|
20
|
+
|
21
|
+
# Page helper: link_to (Helpers)
|
22
|
+
# Builds a link.
|
23
|
+
#
|
24
|
+
def link_to(url, *a, &b)
|
25
|
+
attrs = Hash.new
|
26
|
+
attrs[:href] = url
|
27
|
+
|
28
|
+
attrs[:class] = 'active' if request.fullpath == url
|
29
|
+
|
30
|
+
attrs = attr_merge(attrs, a.shift) if a.first.is_a?(Hash)
|
31
|
+
|
32
|
+
content = ''
|
33
|
+
if block_given?
|
34
|
+
content = capture_haml(&b)
|
35
|
+
elsif a.first.is_a?(String)
|
36
|
+
content = a.shift
|
37
|
+
elsif a.first.is_a?(Proc)
|
38
|
+
content = a.shift.call
|
39
|
+
else
|
40
|
+
content = a.shift.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
raw_tag(:a, content, attrs)
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
def attr_merge(ret, other)
|
48
|
+
if ret.keys.include?(:class) and other.keys.include?(:class)
|
49
|
+
ret[:class] += " " + other.delete(:class)
|
50
|
+
end
|
51
|
+
|
52
|
+
ret.merge(other)
|
53
|
+
ret
|
54
|
+
end
|
55
|
+
|
56
|
+
def raw_tag(tag, content, atts = {})
|
57
|
+
if self_closing?(tag)
|
58
|
+
%(<#{ tag }#{ tag_attributes(atts) } />)
|
59
|
+
else
|
60
|
+
%(<#{ tag }#{ tag_attributes(atts) }>#{content}</#{ tag }>)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def tag(tag, content, atts = {})
|
65
|
+
if self_closing?(tag)
|
66
|
+
%(<#{ tag }#{ tag_attributes(atts) } />)
|
67
|
+
else
|
68
|
+
%(<#{ tag }#{ tag_attributes(atts) }>#{h content}</#{ tag }>)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def tag_attributes(atts = {})
|
73
|
+
atts.inject([]) { |a, (k, v)|
|
74
|
+
a << (' %s="%s"' % [k, escape_attr(v)]) if v
|
75
|
+
a
|
76
|
+
}.join('')
|
77
|
+
end
|
78
|
+
|
79
|
+
def escape_attr(str)
|
80
|
+
str.to_s.gsub("'", "'").gsub('"', """)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self_closing?(tag)
|
84
|
+
@self_closing ||= [:area, :base, :basefont, :br, :hr,
|
85
|
+
:input, :img, :link, :meta]
|
86
|
+
|
87
|
+
@self_closing.include?(tag.to_sym)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
helpers PageHelpers
|
92
|
+
end
|