Permalink
Browse files

init commit

  • Loading branch information...
0 parents commit bb8a44e1cdb46851aaa8f3c7c8131bf1fb524294 @keram keram committed May 4, 2011
Showing with 669 additions and 0 deletions.
  1. +7 −0 app/controllers/admin/snippets_controller.rb
  2. +30 −0 app/controllers/snippets_controller.rb
  3. +17 −0 app/models/snippet.rb
  4. +10 −0 app/models/snippet_page.rb
  5. +12 −0 app/views/admin/pages/tabs/_snippets.html.erb
  6. +9 −0 app/views/admin/pages/tabs/_snippets_bar.html.erb
  7. +3 −0 app/views/admin/pages/tabs/_snippets_field.html.erb
  8. +28 −0 app/views/admin/snippets/_actions.html.erb
  9. +50 −0 app/views/admin/snippets/_form.html.erb
  10. +11 −0 app/views/admin/snippets/_locale_picker.html.erb
  11. +18 −0 app/views/admin/snippets/_records.html.erb
  12. +25 −0 app/views/admin/snippets/_snippet.html.erb
  13. +2 −0 app/views/admin/snippets/_snippets.html.erb
  14. +7 −0 app/views/admin/snippets/_sortable_list.html.erb
  15. +1 −0 app/views/admin/snippets/edit.html.erb
  16. +10 −0 app/views/admin/snippets/index.html.erb
  17. +1 −0 app/views/admin/snippets/new.html.erb
  18. +11 −0 app/views/snippets/index.html.erb
  19. +33 −0 app/views/snippets/show.html.erb
  20. +25 −0 config/locales/en.yml
  21. +25 −0 config/locales/lolcat.yml
  22. +21 −0 config/locales/nb.yml
  23. +21 −0 config/locales/nl.yml
  24. +11 −0 config/routes.rb
  25. +25 −0 db/migrate/1_create_snippets.rb
  26. +18 −0 db/migrate/2_create_page_snippets.rb
  27. +22 −0 db/migrate/3_translate_snippets.rb
  28. +18 −0 db/seeds/snippets.rb
  29. +63 −0 features/manage_snippets.feature
  30. +14 −0 features/step_definitions/snippet_steps.rb
  31. +17 −0 features/support/paths.rb
  32. +6 −0 lib/generators/refinerycms_snippets_generator.rb
  33. +31 −0 lib/refinerycms-snippets.rb
  34. +13 −0 lib/tasks/snippets.rake
  35. +10 −0 readme.md
  36. BIN refinerycms-snippets-0.1.gem
  37. +12 −0 refinerycms-snippets.gemspec
  38. +32 −0 spec/models/snippet_spec.rb
@@ -0,0 +1,7 @@
+module Admin
+ class SnippetsController < Admin::BaseController
+
+ crudify :snippet, :xhr_paging => true
+
+ end
+end
@@ -0,0 +1,30 @@
+class SnippetsController < ApplicationController
+
+ before_filter :find_all_snippets
+ before_filter :find_page
+
+ def index
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @snippet in the line below:
+ present(@page)
+ end
+
+ def show
+ @snippet = Snippet.find(params[:id])
+
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @snippet in the line below:
+ present(@page)
+ end
+
+protected
+
+ def find_all_snippets
+ @snippets = Snippet.order('position ASC')
+ end
+
+ def find_page
+ @page = Page.where(:link_url => "/snippets").first
+ end
+
+end
@@ -0,0 +1,17 @@
+class Snippet < ActiveRecord::Base
+
+ acts_as_indexed :fields => [:title, :body]
+
+ validates :title, :presence => true, :uniqueness => true
+
+ translates :body
+
+ # rejects any page that has not been translated to the current locale.
+ scope :translated, lambda {
+ pages = Arel::Table.new(Snippet.table_name)
+ translations = Arel::Table.new(Snippet.translations_table_name)
+
+ includes(:translations).where(
+ translations[:locale].eq(Globalize.locale)).where(pages[:id].eq(translations[:snippet_id]))
+ }
+end
@@ -0,0 +1,10 @@
+class SnippetPage < ActiveRecord::Base
+
+ belongs_to :snippet
+ belongs_to :page
+
+ before_save do |snippet_page|
+ snippet_page.position = (SnippetPage.maximum(:position) || -1) + 1
+ end
+
+end
@@ -0,0 +1,12 @@
+<div class='wym_skin_refinery page_part' id='page_image_picker'>
+ <%= render :partial => '/admin/pages/tabs/snippets_bar', :locals => {:f => f} %>
+ <%= render :partial => '/admin/pages/tabs/snippets_field', :locals => {:f => f} %>
+</div>
+
+<%# content_for :stylesheets do %>
+ <%#= stylesheet_link_tag 'page-image-picker' %>
+<%# end %>
+
+<%# content_for :javascripts do %>
+ <%#= javascript_include_tag 'page-image-picker' %>
+<%# end %>
@@ -0,0 +1,9 @@
+<div class='wym_area_top'>
+ <span class='clearfix label_inline_with_link'>-t- todo add snippet link
+ <%#= link_to t('.add'), insert_admin_images_url({
+ :dialog => true, :width => 950, :height => 510,
+ :callback => "image_added"
+ }),
+ :id => "add_image_link" %>
+ </span>
+</div>
@@ -0,0 +1,3 @@
+<div class="wym_box field snippets_field" >
+ -t- todo page snippets body
+</div>
@@ -0,0 +1,28 @@
+<ul>
+ <% if Admin::SnippetsController.searchable? %>
+ <li>
+ <%= render :partial => "/shared/admin/search",
+ :locals => {
+ :url => admin_snippets_url
+ } %>
+ </li>
+ <% end %>
+ <li>
+ <%= link_to t('.create_new'), new_admin_snippet_url,
+ :class => "add_icon" %>
+ </li>
+<% if !searching? and Admin::SnippetsController.sortable? and Snippet.count > 1 %>
+ <li>
+ <%= link_to t('.reorder', :what => "Snippets"),
+ admin_snippets_url,
+ :id => "reorder_action",
+ :class => "reorder_icon" %>
+
+ <%= link_to t('.reorder_done', :what => "Snippets"),
+ admin_snippets_url,
+ :id => "reorder_action_done",
+ :style => "display: none;",
+ :class => "reorder_icon" %>
+ </li>
+<% end %>
+</ul>
@@ -0,0 +1,50 @@
+<%= form_for [:admin, @snippet] do |f| -%>
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
+ :object => @snippet,
+ :include_object_name => true
+ } %>
+
+ <%= render :partial => "locale_picker",
+ :locals => {
+ :current_locale => Thread.current[:globalize_locale]
+ } if defined?(::Refinery::I18n) %>
+
+ <div class='field'>
+ <%= f.label :title -%>
+ <%= f.text_field :title, :class => 'larger widest' -%>
+ </div>
+
+ <div class='field'>
+ <div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>
+ <ul id='page_parts'>
+ <% [:body].each_with_index do |part, part_index| %>
+ <li class='ui-state-default<%= ' ui-state-active' if part_index == 0 %>'>
+ <%= link_to part.to_s.titleize, "##{part}" %>
+ </li>
+ <% end %>
+ </ul>
+
+ <div id='page_part_editors'>
+ <% [:body].each do |part| %>
+ <div class='page_part' id='<%= part %>'>
+ <%= f.text_area part, :rows => 20, :class => 'wymeditor widest' -%>
+ </div>
+ <% end %>
+ </div>
+ </div>
+
+ <%= render :partial => "/shared/admin/form_actions",
+ :locals => {
+ :f => f,
+ :continue_editing => false,
+ :delete_title => t('delete', :scope => 'admin.snippets.snippet'),
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @snippet.title)
+ } %>
+<% end -%>
+<% content_for :javascripts do %>
+ <script>
+ $(document).ready(function(){
+ page_options.init(false, '', '');
+ });
+ </script>
+<% end %>
@@ -0,0 +1,11 @@
+<input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
+<% if (locales ||= ::Refinery::I18n.frontend_locales).present? and locales.many? %>
+ <ul id='switch_locale_picker' class='clearfix'>
+ <% locales.each do |locale| %>
+ <li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
+ <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '48x33'),
+ url_for(:switch_locale => locale) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
@@ -0,0 +1,18 @@
+<% if searching? %>
+ <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
+<% end %>
+<% if @snippets.any? %>
+ <div class='pagination_container'>
+ <%= render :partial => 'snippets' %>
+ </div>
+<% else %>
+ <p>
+ <% unless searching? %>
+ <strong>
+ <%= t('.no_items_yet') %>
+ </strong>
+ <% else %>
+ <%= t('no_results', :scope => 'shared.admin.search') %>
+ <% end %>
+ </p>
+<% end %>
@@ -0,0 +1,25 @@
+<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(snippet) -%>">
+ <span class='title'>
+ <%= snippet.title %>
+ <% if ::Refinery::I18n.frontend_locales.many? and
+ (locales = snippet.translations.collect{|t| t.locale}).present? %>
+ <span class='preview'>
+ <% locales.each do |locale| %>
+ <%= refinery_icon_tag "flags/#{locale}.png", :size => '16x11' %>
+ <% end %>
+ </span>
+ <% end %>
+ </span>
+ <span class='actions'>
+ <%= link_to refinery_icon_tag("application_go.png"), snippet_url(snippet),
+ :title => t('.view_live_html'),
+ :target => "_blank" %>
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_snippet_path(snippet),
+ :title => t('.edit') %>
+ <%= link_to refinery_icon_tag("delete.png"), admin_snippet_path(snippet),
+ :class => "cancel confirm-delete",
+ :title => t('.delete'),
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => snippet.title),
+ :method => :delete %>
+ </span>
+</li>
@@ -0,0 +1,2 @@
+<%= will_paginate @snippets %>
+<%= render :partial => "sortable_list" %>
@@ -0,0 +1,7 @@
+<ul id='sortable_list'>
+ <%= render :partial => 'snippet', :collection => @snippets %>
+</ul>
+<%= render :partial => "/shared/admin/sortable_list",
+ :locals => {
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true
+ } %>
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
@@ -0,0 +1,10 @@
+<section id='records'>
+ <%= render :partial => 'records' %>
+</section>
+<aside id='actions'>
+ <%= render :partial => 'actions' %>
+</aside>
+<%= render :partial => '/shared/admin/make_sortable',
+ :locals => {
+ :tree => false
+ } if !searching? and Admin::SnippetsController.sortable? and Snippet.count > 1 %>
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
@@ -0,0 +1,11 @@
+<% content_for :body_content_left do %>
+ <ul id="snippets">
+ <% @snippets.each do |snippet| %>
+ <li>
+ <%= link_to snippet.title, snippet_url(snippet) %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,33 @@
+<% content_for :body_content_title do %>
+ <%= @snippet.title %>
+<% end %>
+
+<% content_for :body_content_left do %>
+ <section>
+ <h1>Title</h1>
+ <p>
+ <%=raw @snippet.title %>
+ </p>
+ </section>
+ <section>
+ <h1>Body</h1>
+ <p>
+ <%=raw @snippet.body %>
+ </p>
+ </section>
+<% end %>
+
+<% content_for :body_content_right do %>
+ <aside>
+ <h2><%= t('.other') %></h2>
+ <ul id="snippets">
+ <% @snippets.each do |snippet| %>
+ <li>
+ <%= link_to snippet.title, snippet_url(snippet) %>
+ </li>
+ <% end %>
+ </ul>
+ </aside>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,25 @@
+en:
+ shared:
+ admin:
+ image_picker:
+ image: image
+ plugins:
+ snippets:
+ title: Snippets
+ admin:
+ snippets:
+ actions:
+ create_new: Add New Snippet
+ reorder: Reorder Snippets
+ reorder_done: Done Reordering Snippets
+ records:
+ title: Snippets
+ sorry_no_results: Sorry! There are no results found.
+ no_items_yet: There are no Snippets yet. Click "Add New Snippet" to add your first snippet.
+ snippet:
+ view_live_html: View this snippet live <br/><em>(opens in a new window)</em>
+ edit: Edit this snippet
+ delete: Remove this snippet forever
+ snippets:
+ show:
+ other: Other Snippets
@@ -0,0 +1,25 @@
+lolcat:
+ shared:
+ admin:
+ image_picker:
+ image: IMAGE
+ plugins:
+ snippets:
+ title: Snippets
+ admin:
+ snippets:
+ actions:
+ create_new: CREATE NEW Snippet
+ reorder: REORDR Snippets
+ reorder_done: DUN REORDERIN Snippets
+ records:
+ title: Snippets
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
+ no_items_yet: THAR R NO Snippets YET. CLICK "CREATE NEW Snippet" 2 ADD UR FURST snippet.
+ snippet:
+ view_live_html: VIEW DIS snippet LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
+ edit: EDIT DIS snippet
+ delete: REMOOV DIS snippet FOREVR
+ snippets:
+ show:
+ other: OTHR Snippets
@@ -0,0 +1,21 @@
+nb:
+ plugins:
+ snippets:
+ title: Snippets
+ admin:
+ snippets:
+ actions:
+ create_new: Lag en ny Snippet
+ reorder: Endre rekkefølgen på Snippets
+ reorder_done: Ferdig å endre rekkefølgen Snippets
+ records:
+ title: Snippets
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
+ no_items_yet: Det er ingen Snippets enda. Klikk på "Lag en ny Snippet" for å legge til din første snippet.
+ snippet:
+ view_live_html: Vis hvordan denne snippet ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
+ edit: Rediger denne snippet
+ delete: Fjern denne snippet permanent
+ snippets:
+ show:
+ other: Andre Snippets
Oops, something went wrong.

0 comments on commit bb8a44e

Please sign in to comment.