slices 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/README.md +51 -0
- data/Rakefile +9 -0
- data/app/assets/images/slices/ajax-loader.gif +0 -0
- data/app/assets/images/slices/asset-background.png +0 -0
- data/app/assets/images/slices/asset-spinner.gif +0 -0
- data/app/assets/images/slices/bg_header.gif +0 -0
- data/app/assets/images/slices/black-Linen.png +0 -0
- data/app/assets/images/slices/calendar.svg +68 -0
- data/app/assets/images/slices/chosen-sprite.png +0 -0
- data/app/assets/images/slices/drag-handle.svg +9 -0
- data/app/assets/images/slices/icon_admins.png +0 -0
- data/app/assets/images/slices/icon_app.png +0 -0
- data/app/assets/images/slices/icon_assets.png +0 -0
- data/app/assets/images/slices/icon_collapse.png +0 -0
- data/app/assets/images/slices/icon_drag.png +0 -0
- data/app/assets/images/slices/icon_files.png +0 -0
- data/app/assets/images/slices/icon_generic_file.png +0 -0
- data/app/assets/images/slices/icon_images.png +0 -0
- data/app/assets/images/slices/icon_padlock.png +0 -0
- data/app/assets/images/slices/icon_page.png +0 -0
- data/app/assets/images/slices/icon_search.png +0 -0
- data/app/assets/images/slices/icon_set-link.png +0 -0
- data/app/assets/images/slices/icon_set.png +0 -0
- data/app/assets/images/slices/icon_sitemap.png +0 -0
- data/app/assets/images/slices/icon_snippets.png +0 -0
- data/app/assets/images/slices/icon_template.jpg +0 -0
- data/app/assets/images/slices/icon_upload_happy.png +0 -0
- data/app/assets/images/slices/icon_upload_sad.png +0 -0
- data/app/assets/images/slices/icon_upload_thinking.png +0 -0
- data/app/assets/images/slices/noise.png +0 -0
- data/app/assets/images/slices/sitemap_icon_ghost.png +0 -0
- data/app/assets/images/slices/sitemap_icon_home.png +0 -0
- data/app/assets/images/slices/sitemap_icon_page.png +0 -0
- data/app/assets/images/slices/sitemap_icon_set_page.png +0 -0
- data/app/assets/images/slices/sitemap_icon_virtual_page.png +0 -0
- data/app/assets/images/slices/sitemap_overlay.png +0 -0
- data/app/assets/images/slices/spinner.gif +0 -0
- data/app/assets/images/slices/trash.png +0 -0
- data/app/assets/javascripts/admin.js.erb +18 -0
- data/app/assets/javascripts/slices/app/backbones/admins.js +114 -0
- data/app/assets/javascripts/slices/app/backbones/entries.js +172 -0
- data/app/assets/javascripts/slices/app/backbones/generic.js +101 -0
- data/app/assets/javascripts/slices/app/backbones/snippets.js +113 -0
- data/app/assets/javascripts/slices/app/helpers/assets.js +61 -0
- data/app/assets/javascripts/slices/app/helpers/breadcrumbs.js +30 -0
- data/app/assets/javascripts/slices/app/helpers/composer.js +26 -0
- data/app/assets/javascripts/slices/app/helpers/date_field.js +16 -0
- data/app/assets/javascripts/slices/app/helpers/get_value.js +31 -0
- data/app/assets/javascripts/slices/app/helpers/icon_upload_names.js.erb +5 -0
- data/app/assets/javascripts/slices/app/helpers/layout.js +20 -0
- data/app/assets/javascripts/slices/app/helpers/sitemap.js +150 -0
- data/app/assets/javascripts/slices/app/helpers/slice_preview.js +48 -0
- data/app/assets/javascripts/slices/app/helpers/tagging.js +73 -0
- data/app/assets/javascripts/slices/app/helpers/token_field.js +17 -0
- data/app/assets/javascripts/slices/app/helpers/upload_icons.js.erb +5 -0
- data/app/assets/javascripts/slices/app/helpers/uploader.js +127 -0
- data/app/assets/javascripts/slices/app/models/asset.js +29 -0
- data/app/assets/javascripts/slices/app/models/asset_collection.js +41 -0
- data/app/assets/javascripts/slices/app/models/attachment.js +29 -0
- data/app/assets/javascripts/slices/app/models/attachment_collection.js +7 -0
- data/app/assets/javascripts/slices/app/models/composer_item.js +1 -0
- data/app/assets/javascripts/slices/app/models/composer_item_collection.js +3 -0
- data/app/assets/javascripts/slices/app/models/file.js +103 -0
- data/app/assets/javascripts/slices/app/models/page.js +186 -0
- data/app/assets/javascripts/slices/app/models/s3_file.js +64 -0
- data/app/assets/javascripts/slices/app/slices.js +661 -0
- data/app/assets/javascripts/slices/app/views/asset_editor_view.js.erb +209 -0
- data/app/assets/javascripts/slices/app/views/asset_library_view.js +720 -0
- data/app/assets/javascripts/slices/app/views/asset_thumb_view.js.erb +191 -0
- data/app/assets/javascripts/slices/app/views/attachment_composer_view.js +350 -0
- data/app/assets/javascripts/slices/app/views/attachment_view.js +101 -0
- data/app/assets/javascripts/slices/app/views/calendar_view.js +198 -0
- data/app/assets/javascripts/slices/app/views/composer_item_view.js +54 -0
- data/app/assets/javascripts/slices/app/views/composer_view.js +130 -0
- data/app/assets/javascripts/slices/app/views/date_field_view.js +177 -0
- data/app/assets/javascripts/slices/app/views/file_view.js +142 -0
- data/app/assets/javascripts/slices/app/views/token_field_view.js +253 -0
- data/app/assets/javascripts/slices/lib/freeze.js +14 -0
- data/app/assets/javascripts/slices/lib/human_file_size.js +16 -0
- data/app/assets/javascripts/slices/lib/json_patch.js +9 -0
- data/app/assets/javascripts/slices/lib/moment.js +47 -0
- data/app/assets/javascripts/slices/lib/plugins.js +101 -0
- data/app/assets/javascripts/slices/lib/sortable.js +14 -0
- data/app/assets/javascripts/slices/slices.js +27 -0
- data/app/assets/javascripts/slices/vendor/autoscroll.js +188 -0
- data/app/assets/javascripts/slices/vendor/backbone.js +38 -0
- data/app/assets/javascripts/slices/vendor/handlebars.js +1920 -0
- data/app/assets/javascripts/slices/vendor/jqmodal.js +69 -0
- data/app/assets/javascripts/slices/vendor/jquery-ui.js +274 -0
- data/app/assets/javascripts/slices/vendor/jquery-ui_nested-sortable.js +357 -0
- data/app/assets/javascripts/slices/vendor/jquery.ajaxprogress.js +76 -0
- data/app/assets/javascripts/slices/vendor/jquery.js +2 -0
- data/app/assets/javascripts/slices/vendor/livefield.js +459 -0
- data/app/assets/javascripts/slices/vendor/moment.js +6 -0
- data/app/assets/javascripts/slices/vendor/rails.js +315 -0
- data/app/assets/javascripts/slices/vendor/underscore-string.js +1 -0
- data/app/assets/javascripts/slices/vendor/underscore.js +5 -0
- data/app/assets/stylesheets/admin.css +1 -0
- data/app/assets/stylesheets/slices/admin.css.erb +2237 -0
- data/app/assets/stylesheets/slices/reset_html5.css +106 -0
- data/app/assets/stylesheets/slices/slices.css +7 -0
- data/app/controllers/admin/admin_controller.rb +10 -0
- data/app/controllers/admin/admins_controller.rb +76 -0
- data/app/controllers/admin/assets_controller.rb +53 -0
- data/app/controllers/admin/auth/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/admin/auth/passwords_controller.rb +4 -0
- data/app/controllers/admin/auth/sessions_controller.rb +4 -0
- data/app/controllers/admin/entries_controller.rb +88 -0
- data/app/controllers/admin/page_search_controller.rb +12 -0
- data/app/controllers/admin/pages_controller.rb +103 -0
- data/app/controllers/admin/site_maps_controller.rb +15 -0
- data/app/controllers/admin/snippets_controller.rb +33 -0
- data/app/controllers/application_controller.rb +4 -0
- data/app/controllers/pages_controller.rb +45 -0
- data/app/controllers/slices_controller.rb +63 -0
- data/app/controllers/static_assets_controller.rb +52 -0
- data/app/helpers/admin/admin_helper.rb +63 -0
- data/app/helpers/admin/assets_helper.rb +36 -0
- data/app/helpers/admin/entries_helper.rb +13 -0
- data/app/helpers/admin/site_maps_helper.rb +104 -0
- data/app/helpers/assets_helper.rb +64 -0
- data/app/helpers/navigation_helper.rb +195 -0
- data/app/helpers/pages_helper.rb +119 -0
- data/app/models/admin.rb +34 -0
- data/app/models/asset.rb +211 -0
- data/app/models/attachment.rb +11 -0
- data/app/models/layout.rb +44 -0
- data/app/models/page.rb +214 -0
- data/app/models/placeholder_slice.rb +8 -0
- data/app/models/set_page.rb +12 -0
- data/app/models/set_slice.rb +57 -0
- data/app/models/site_map.rb +24 -0
- data/app/models/slice.rb +80 -0
- data/app/models/snippet.rb +21 -0
- data/app/observers/asset_observer.rb +6 -0
- data/app/observers/page_observer.rb +37 -0
- data/app/presenters/entry_presenter.rb +17 -0
- data/app/presenters/page_presenter.rb +67 -0
- data/app/presenters/presenter.rb +9 -0
- data/app/presenters/set_page_presenter.rb +2 -0
- data/app/views/admin/admins/index.html.erb +26 -0
- data/app/views/admin/admins/show.html.erb +27 -0
- data/app/views/admin/assets/index.html.erb +1 -0
- data/app/views/admin/auth/passwords/edit.html.erb +20 -0
- data/app/views/admin/auth/passwords/new.html.erb +14 -0
- data/app/views/admin/auth/sessions/_form.html.erb +35 -0
- data/app/views/admin/auth/sessions/new.html.erb +14 -0
- data/app/views/admin/entries/index.html.erb +32 -0
- data/app/views/admin/pages/_breadcrumbs.html.erb +32 -0
- data/app/views/admin/pages/_slices.html.erb +27 -0
- data/app/views/admin/pages/new.html.erb +14 -0
- data/app/views/admin/pages/show.html.erb +50 -0
- data/app/views/admin/shared/_asset_storage.html.erb +17 -0
- data/app/views/admin/shared/_custom_links.html.erb +1 -0
- data/app/views/admin/shared/_custom_navigation.html.erb +1 -0
- data/app/views/admin/shared/_navigation.html.erb +5 -0
- data/app/views/admin/site_maps/_page_li.html.erb +20 -0
- data/app/views/admin/site_maps/_set_page_li.html.erb +23 -0
- data/app/views/admin/site_maps/index.html.erb +29 -0
- data/app/views/admin/snippets/form.html.erb +12 -0
- data/app/views/admin/snippets/index.html.erb +20 -0
- data/app/views/admin/snippets/update.html.erb +0 -0
- data/app/views/layouts/admin.html.erb +72 -0
- data/lib/ext/file_store_cache.rb +18 -0
- data/lib/generators/humans/USAGE +8 -0
- data/lib/generators/humans/humans_generator.rb +10 -0
- data/lib/generators/humans/templates/humans.txt +6 -0
- data/lib/generators/slice/USAGE +28 -0
- data/lib/generators/slice/slice_generator.rb +123 -0
- data/lib/generators/slice/templates/main_fields.hbs +11 -0
- data/lib/generators/slice/templates/meta_fields.hbs +11 -0
- data/lib/generators/slice/templates/page.rb +19 -0
- data/lib/generators/slice/templates/presenter.rb +53 -0
- data/lib/generators/slice/templates/set.html.erb +8 -0
- data/lib/generators/slice/templates/set_slice.rb +14 -0
- data/lib/generators/slice/templates/set_slice_fields.hbs +5 -0
- data/lib/generators/slice/templates/show.html.erb +48 -0
- data/lib/generators/slice/templates/show_slice.rb +20 -0
- data/lib/generators/slice/templates/slice.rb +58 -0
- data/lib/generators/slice/templates/slice_fields.hbs +74 -0
- data/lib/generators/templates/slices.rb +211 -0
- data/lib/mongo_search.rb +84 -0
- data/lib/paperclip_validator.rb +5 -0
- data/lib/rack_utf8_fix.rb +10 -0
- data/lib/sRGB.icc +0 -0
- data/lib/set_link_renderer.rb +31 -0
- data/lib/slices.rb +68 -0
- data/lib/slices/asset/maker.rb +55 -0
- data/lib/slices/asset/rename.rb +67 -0
- data/lib/slices/available_slices.rb +43 -0
- data/lib/slices/cms_form_builder.rb +42 -0
- data/lib/slices/config.rb +93 -0
- data/lib/slices/container_parser.rb +70 -0
- data/lib/slices/generator_macros.rb +36 -0
- data/lib/slices/has_attachments.rb +111 -0
- data/lib/slices/has_slices.rb +88 -0
- data/lib/slices/i18n.rb +6 -0
- data/lib/slices/i18n/backend.rb +32 -0
- data/lib/slices/i18n_backend.rb +24 -0
- data/lib/slices/paperclip.rb +13 -0
- data/lib/slices/position_helper.rb +98 -0
- data/lib/slices/renderer.rb +52 -0
- data/lib/slices/slices_engine.rb +51 -0
- data/lib/slices/split_date_time_field.rb +14 -0
- data/lib/slices/tasks/assets.rake +35 -0
- data/lib/slices/tasks/db.rake +50 -0
- data/lib/slices/tasks/seeds.rake +93 -0
- data/lib/slices/tasks/validate.rake +62 -0
- data/lib/slices/tree.rb +306 -0
- data/lib/slices/version.rb +4 -0
- data/lib/slices/will_paginate.rb +12 -0
- data/lib/slices/will_paginate_mongoid.rb +45 -0
- data/lib/standard_tree.rb +193 -0
- metadata +483 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
<script>
|
2
|
+
<% if Slices::Config.s3_storage? %>
|
3
|
+
slices.S3_UPLOADER_DEFAULTS = {
|
4
|
+
AWSAccessKeyId : '<%= Slices::Config.s3_credentials[:access_key_id] %>',
|
5
|
+
acl : 'public-read',
|
6
|
+
policy : '<%= policy %>',
|
7
|
+
signature : '<%= signature %>',
|
8
|
+
success_action_status : '201',
|
9
|
+
};
|
10
|
+
|
11
|
+
slices.S3_URL = 'https://<%= Slices::Config.s3_credentials[:bucket] %>.s3.amazonaws.com/';
|
12
|
+
slices.S3_TEMPFILE_KEY_PREFIX = '<%= Slices::Config::S3_TEMPFILE_KEY_PREFIX %>';
|
13
|
+
slices.fileClass = slices.S3File;
|
14
|
+
<% else %>
|
15
|
+
slices.fileClass = slices.File;
|
16
|
+
<% end %>
|
17
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
<li><%= link_to 'Suggestion Box', 'https://github.com/withassociates/slices/issues' %></li>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= admin_nav_link 'Source', 'https://github.com/withassociates/slices' %>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<%= admin_nav_link("Sitemap", admin_site_maps_path) %>
|
2
|
+
<%= admin_nav_link("Assets", admin_assets_path) %>
|
3
|
+
<%= admin_nav_link("Snippets", admin_snippets_path) if Slices::Config.snippets? %>
|
4
|
+
<%= admin_nav_link("Administrators", admin_admins_path) %>
|
5
|
+
<%= render_custom_navigation %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<li class="page <%= "home" if page.home? %>" rel="<%= page.id %>">
|
2
|
+
<div>
|
3
|
+
<h2><%= link_to(page.name, admin_page_path(page)) %></h2>
|
4
|
+
|
5
|
+
<% unless page.virtual? %>
|
6
|
+
<span class="item-actions primary">
|
7
|
+
<%= link_to_add_child page %>
|
8
|
+
<%= link_to_view_page page %>
|
9
|
+
</span>
|
10
|
+
|
11
|
+
<%= link_to_delete page unless page.home? %>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<% if page.children.any? %>
|
16
|
+
<ol>
|
17
|
+
<%= list_pages(page.children) %>
|
18
|
+
</ol>
|
19
|
+
<% end %>
|
20
|
+
</li>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<li class="set-page" rel="<%= page.id %>">
|
2
|
+
<div>
|
3
|
+
<h2><%= link_to page.name, admin_page_entries_path(page) %></h2>
|
4
|
+
|
5
|
+
<span class="item-actions primary">
|
6
|
+
<%= link_to_add_entry page %>
|
7
|
+
<%= link_to_all_entries page %>
|
8
|
+
<%= link_to_view_page page %>
|
9
|
+
</span>
|
10
|
+
|
11
|
+
<span class="item-actions secondary">
|
12
|
+
<%= link_to_edit_index_template page %>
|
13
|
+
<%= link_to_edit_entry_template page %>
|
14
|
+
</span>
|
15
|
+
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<% if page.page_children.any? %>
|
19
|
+
<ol>
|
20
|
+
<%= list_pages page.page_children %>
|
21
|
+
</ol>
|
22
|
+
<% end %>
|
23
|
+
</li>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<form id="sitemap-form">
|
2
|
+
<div id="container-actions" class="toolbar">
|
3
|
+
<p id="structure-locked">
|
4
|
+
Site structure is currently locked.
|
5
|
+
<%= link_to 'Unlock structure?', '#' %>
|
6
|
+
</p>
|
7
|
+
<div id="structure-unlocked">
|
8
|
+
<ul class="actions">
|
9
|
+
<li>
|
10
|
+
<input type="submit" value="Save" />
|
11
|
+
</li>
|
12
|
+
</ul>
|
13
|
+
<p>
|
14
|
+
Site structure is currently unlocked.
|
15
|
+
<%= link_to 'Cancel', admin_site_maps_path %>
|
16
|
+
</p>
|
17
|
+
</div>
|
18
|
+
<input type="search" id="sitemap-search" placeholder="Filter pages..." />
|
19
|
+
</div>
|
20
|
+
<div id="main">
|
21
|
+
<ol id="sitemap">
|
22
|
+
<%= list_pages(@pages) %>
|
23
|
+
</ol>
|
24
|
+
<hr id="sitemap-divider" />
|
25
|
+
<ol id="virtual-pages">
|
26
|
+
<%= list_pages(@virtuals) %>
|
27
|
+
</ol>
|
28
|
+
</div>
|
29
|
+
</form>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= form_for [:admin, @snippet],
|
2
|
+
html: {multipart: true},
|
3
|
+
remote: true do |form| %>
|
4
|
+
<div class="fields">
|
5
|
+
<label for="snippet_value" class="legend">Value for <em><%= @snippet.key %></em>:</label>
|
6
|
+
<%= form.text_area :value %>
|
7
|
+
</div>
|
8
|
+
<div class="bottom-toolbar">
|
9
|
+
<%= form.submit value: 'Save snippet' %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div id="container-actions" class="toolbar">
|
2
|
+
<ul id="pagination">
|
3
|
+
</ul>
|
4
|
+
</div>
|
5
|
+
<div id="main">
|
6
|
+
<section>
|
7
|
+
<table class="elements-table" id='snippets-list'>
|
8
|
+
<thead>
|
9
|
+
<tr><th>Key</th><th>Value</th><th></th></tr>
|
10
|
+
</thead>
|
11
|
+
<tbody>
|
12
|
+
</tbody>
|
13
|
+
</table>
|
14
|
+
</section>
|
15
|
+
</div>
|
16
|
+
<% content_for :js_head do %>
|
17
|
+
$(function() {
|
18
|
+
SnippetsBackbone.boot();
|
19
|
+
});
|
20
|
+
<% end %>
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<%= csrf_meta_tag %>
|
6
|
+
<title><%= cms_title %></title>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag 'slices/slices' %>
|
9
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
10
|
+
<%= javascript_include_tag 'slices/slices' %>
|
11
|
+
<%= render "admin/shared/asset_storage" %>
|
12
|
+
|
13
|
+
<meta name="robots" content="noindex, nofollow">
|
14
|
+
<script type="text/javascript">
|
15
|
+
$(document).ready(function() {
|
16
|
+
<%= yield :js_head %>
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
</head>
|
20
|
+
<body class="<%= body_class_from_controller %>">
|
21
|
+
<div class="jqmWindow modal" id="general-modal"></div>
|
22
|
+
<div id="server-communication">Loading...</div>
|
23
|
+
|
24
|
+
<div id="container">
|
25
|
+
<header id="layout">
|
26
|
+
<% if admin_signed_in? -%>
|
27
|
+
<ul>
|
28
|
+
<li><%= current_admin.email %></li>
|
29
|
+
<%= render_custom_links %>
|
30
|
+
<li><%= link_to "View Site", root_path, target: "_blank" %></li>
|
31
|
+
<li><%= link_to "Account", admin_admin_path(current_admin) %></li>
|
32
|
+
<li><%= link_to "Log out", destroy_admin_session_path %></li>
|
33
|
+
</ul>
|
34
|
+
<% end -%>
|
35
|
+
<nav>
|
36
|
+
<ul>
|
37
|
+
<% if admin_signed_in? -%>
|
38
|
+
<%= render('admin/shared/navigation') %>
|
39
|
+
<% else -%>
|
40
|
+
<li> </li>
|
41
|
+
<% end -%>
|
42
|
+
</ul>
|
43
|
+
</nav>
|
44
|
+
</header>
|
45
|
+
|
46
|
+
<%= yield %>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<script type="text/html" id="livefield-result-template">
|
50
|
+
<li data-value="{{path}}">
|
51
|
+
<span class="name">{{name}}</span>
|
52
|
+
<span class="path">{{path}}</span>
|
53
|
+
</li>
|
54
|
+
</script>
|
55
|
+
|
56
|
+
<% if Rails.env.production? %>
|
57
|
+
<script type="text/javascript">
|
58
|
+
var _gaq = _gaq || [];
|
59
|
+
_gaq.push(['_setAccount', 'UA-298580-55']);
|
60
|
+
_gaq.push(['_setDomainName', 'none']);
|
61
|
+
_gaq.push(['_setAllowLinker', true]);
|
62
|
+
_gaq.push(['_setCustomVar', 1, 'Slices Version', '<%= Slices::VERSION %>', 3]);
|
63
|
+
_gaq.push(['_trackPageview']);
|
64
|
+
(function() {
|
65
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
66
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
67
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
68
|
+
})();
|
69
|
+
</script>
|
70
|
+
<% end -%>
|
71
|
+
</body>
|
72
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Cache
|
3
|
+
class FileStore < Store
|
4
|
+
|
5
|
+
silence_warnings do
|
6
|
+
UNESCAPE_FILENAME_CHARS = /%([0-9A-F]{2})/
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def file_path_key(path)
|
12
|
+
fname = path[cache_path.size, path.size].split(File::SEPARATOR, 4).last
|
13
|
+
fname.gsub(UNESCAPE_FILENAME_CHARS){|match| $1.hex.chr }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Description:
|
2
|
+
Creates a new slice in app/slices.
|
3
|
+
|
4
|
+
If you want to make a set slice, make sure that the name ends with
|
5
|
+
"set" or "Set" (e.g. photo_set or PhotoSet).
|
6
|
+
|
7
|
+
If you want to make a form slice, the name should end with "form".
|
8
|
+
|
9
|
+
Example:
|
10
|
+
rails generate slice you_tube
|
11
|
+
rails generate slice YouTube
|
12
|
+
|
13
|
+
Either of these commands will create:
|
14
|
+
app/slices/you_tube/you_tube_slice.rb
|
15
|
+
app/slices/you_tube/templates/you_tube.hbs
|
16
|
+
app/slices/you_tube/views/show.html.erb
|
17
|
+
|
18
|
+
You will need to restart your rails app after generating a slice
|
19
|
+
before it will appear in the admin interface.
|
20
|
+
|
21
|
+
You can define fields on a slice like this:
|
22
|
+
|
23
|
+
rails generate slice slideshow title:string slides:attachments
|
24
|
+
rails generate slice countdown text:string ends_at:date_time
|
25
|
+
|
26
|
+
Tips:
|
27
|
+
Note the shorthand version `rails g slice my_slice`
|
28
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
class SliceGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
argument :attributes,
|
5
|
+
type: :array,
|
6
|
+
default: [],
|
7
|
+
banner: "field:type field:type"
|
8
|
+
|
9
|
+
class_option :with_entry_templates, type: :boolean, default: false,
|
10
|
+
desc: "Add templates for editing entry content."
|
11
|
+
|
12
|
+
class_option :with_identical_entries, type: :boolean, default: false,
|
13
|
+
desc: "For sets whose entry pages are all alike."
|
14
|
+
|
15
|
+
FIELD_NORMALIZATIONS = {
|
16
|
+
text: :string,
|
17
|
+
datetime: :date_time
|
18
|
+
}
|
19
|
+
|
20
|
+
def create_slices
|
21
|
+
if set_slice?
|
22
|
+
template "set_slice.rb", "#{slice_path}/#{file_name}_slice.rb"
|
23
|
+
else
|
24
|
+
template "slice.rb", "#{slice_path}/#{file_name}_slice.rb"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_views
|
29
|
+
if set_slice?
|
30
|
+
template "set.html.erb", "#{slice_path}/views/set.html.erb"
|
31
|
+
else
|
32
|
+
template "show.html.erb", "#{slice_path}/views/show.html.erb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_templates
|
37
|
+
if set_slice?
|
38
|
+
template "set_slice_fields.hbs", "#{slice_path}/templates/#{file_name}.hbs"
|
39
|
+
else
|
40
|
+
template "slice_fields.hbs", "#{slice_path}/templates/#{file_name}.hbs"
|
41
|
+
end
|
42
|
+
|
43
|
+
base = set_slice? ? page_name : file_name
|
44
|
+
|
45
|
+
if options.with_entry_templates?
|
46
|
+
template "main_fields.hbs", "#{slice_path}/templates/#{base}_main.hbs"
|
47
|
+
template "meta_fields.hbs", "#{slice_path}/templates/#{base}_meta.hbs"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_set_files
|
52
|
+
if set_slice?
|
53
|
+
template "page.rb", "#{slice_path}/#{page_name}.rb"
|
54
|
+
template "presenter.rb", "#{slice_path}/#{page_name}_presenter.rb"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def slice_path
|
62
|
+
"app/slices/#{file_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def page_name
|
66
|
+
file_name.sub /_set$/, ''
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_slice?
|
70
|
+
file_name.ends_with? '_set'
|
71
|
+
end
|
72
|
+
|
73
|
+
def form_slice?
|
74
|
+
file_name.ends_with? '_form'
|
75
|
+
end
|
76
|
+
|
77
|
+
def field_definitions
|
78
|
+
out = []
|
79
|
+
|
80
|
+
if attributes.any? { |attribute| attribute.type == :attachments }
|
81
|
+
out << " include Slices::HasAttachments\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
attributes.each do |attribute|
|
85
|
+
case attribute.type
|
86
|
+
when :attachments
|
87
|
+
attachment_klass = attribute.name.classify
|
88
|
+
out << [
|
89
|
+
"",
|
90
|
+
" class #{attachment_klass} < Attachment",
|
91
|
+
" # Extend your attachments by adding fields here e.g.",
|
92
|
+
" field :caption",
|
93
|
+
" end",
|
94
|
+
" has_attachments :#{attribute.name}, class_name: '#{class_name}Slice::#{attachment_klass}'",
|
95
|
+
""
|
96
|
+
].join("\n")
|
97
|
+
else
|
98
|
+
out << " field :#{attribute.name}, type: #{class_for_field attribute.type}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
out.join "\n"
|
103
|
+
end
|
104
|
+
|
105
|
+
def slice_input_id name
|
106
|
+
"slices-{{id}}-#{name}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def needs_label? attribute
|
110
|
+
attribute.name.underscore == class_name.underscore
|
111
|
+
end
|
112
|
+
|
113
|
+
def label_if_needed_for attribute
|
114
|
+
unless attribute.name == file_name
|
115
|
+
%{<label for="slices-{{id}}-#{attribute.name}">#{attribute.name.humanize}</label>}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def class_for_field type
|
120
|
+
FIELD_NORMALIZATIONS.fetch(type, type).to_s.classify
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|