refinerycms-snippets 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ module Admin
2
+ class SnippetsController < Admin::BaseController
3
+
4
+ crudify :snippet, :xhr_paging => true
5
+
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ class SnippetsController < ApplicationController
2
+
3
+ before_filter :find_all_snippets
4
+ before_filter :find_page
5
+
6
+ def index
7
+ # you can use meta fields from your model instead (e.g. browser_title)
8
+ # by swapping @page for @snippet in the line below:
9
+ present(@page)
10
+ end
11
+
12
+ def show
13
+ @snippet = Snippet.find(params[:id])
14
+
15
+ # you can use meta fields from your model instead (e.g. browser_title)
16
+ # by swapping @page for @snippet in the line below:
17
+ present(@page)
18
+ end
19
+
20
+ protected
21
+
22
+ def find_all_snippets
23
+ @snippets = Snippet.order('position ASC')
24
+ end
25
+
26
+ def find_page
27
+ @page = Page.where(:link_url => "/snippets").first
28
+ end
29
+
30
+ end
@@ -0,0 +1,17 @@
1
+ class Snippet < ActiveRecord::Base
2
+
3
+ acts_as_indexed :fields => [:title, :body]
4
+
5
+ validates :title, :presence => true, :uniqueness => true
6
+
7
+ translates :body
8
+
9
+ # rejects any page that has not been translated to the current locale.
10
+ scope :translated, lambda {
11
+ pages = Arel::Table.new(Snippet.table_name)
12
+ translations = Arel::Table.new(Snippet.translations_table_name)
13
+
14
+ includes(:translations).where(
15
+ translations[:locale].eq(Globalize.locale)).where(pages[:id].eq(translations[:snippet_id]))
16
+ }
17
+ end
@@ -0,0 +1,10 @@
1
+ class SnippetPage < ActiveRecord::Base
2
+
3
+ belongs_to :snippet
4
+ belongs_to :page
5
+
6
+ before_save do |snippet_page|
7
+ snippet_page.position = (SnippetPage.maximum(:position) || -1) + 1
8
+ end
9
+
10
+ end
@@ -0,0 +1,12 @@
1
+ <div class='wym_skin_refinery page_part' id='page_image_picker'>
2
+ <%= render :partial => '/admin/pages/tabs/snippets_bar', :locals => {:f => f} %>
3
+ <%= render :partial => '/admin/pages/tabs/snippets_field', :locals => {:f => f} %>
4
+ </div>
5
+
6
+ <%# content_for :stylesheets do %>
7
+ <%#= stylesheet_link_tag 'page-image-picker' %>
8
+ <%# end %>
9
+
10
+ <%# content_for :javascripts do %>
11
+ <%#= javascript_include_tag 'page-image-picker' %>
12
+ <%# end %>
@@ -0,0 +1,9 @@
1
+ <div class='wym_area_top'>
2
+ <span class='clearfix label_inline_with_link'>-t- todo add snippet link
3
+ <%#= link_to t('.add'), insert_admin_images_url({
4
+ :dialog => true, :width => 950, :height => 510,
5
+ :callback => "image_added"
6
+ }),
7
+ :id => "add_image_link" %>
8
+ </span>
9
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="wym_box field snippets_field" >
2
+ -t- todo page snippets body
3
+ </div>
@@ -0,0 +1,28 @@
1
+ <ul>
2
+ <% if Admin::SnippetsController.searchable? %>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search",
5
+ :locals => {
6
+ :url => admin_snippets_url
7
+ } %>
8
+ </li>
9
+ <% end %>
10
+ <li>
11
+ <%= link_to t('.create_new'), new_admin_snippet_url,
12
+ :class => "add_icon" %>
13
+ </li>
14
+ <% if !searching? and Admin::SnippetsController.sortable? and Snippet.count > 1 %>
15
+ <li>
16
+ <%= link_to t('.reorder', :what => "Snippets"),
17
+ admin_snippets_url,
18
+ :id => "reorder_action",
19
+ :class => "reorder_icon" %>
20
+
21
+ <%= link_to t('.reorder_done', :what => "Snippets"),
22
+ admin_snippets_url,
23
+ :id => "reorder_action_done",
24
+ :style => "display: none;",
25
+ :class => "reorder_icon" %>
26
+ </li>
27
+ <% end %>
28
+ </ul>
@@ -0,0 +1,50 @@
1
+ <%= form_for [:admin, @snippet] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @snippet,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <%= render :partial => "locale_picker",
8
+ :locals => {
9
+ :current_locale => Thread.current[:globalize_locale]
10
+ } if defined?(::Refinery::I18n) %>
11
+
12
+ <div class='field'>
13
+ <%= f.label :title -%>
14
+ <%= f.text_field :title, :class => 'larger widest' -%>
15
+ </div>
16
+
17
+ <div class='field'>
18
+ <div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>
19
+ <ul id='page_parts'>
20
+ <% [:body].each_with_index do |part, part_index| %>
21
+ <li class='ui-state-default<%= ' ui-state-active' if part_index == 0 %>'>
22
+ <%= link_to part.to_s.titleize, "##{part}" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
26
+
27
+ <div id='page_part_editors'>
28
+ <% [:body].each do |part| %>
29
+ <div class='page_part' id='<%= part %>'>
30
+ <%= f.text_area part, :rows => 20, :class => 'wymeditor widest' -%>
31
+ </div>
32
+ <% end %>
33
+ </div>
34
+ </div>
35
+
36
+ <%= render :partial => "/shared/admin/form_actions",
37
+ :locals => {
38
+ :f => f,
39
+ :continue_editing => false,
40
+ :delete_title => t('delete', :scope => 'admin.snippets.snippet'),
41
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @snippet.title)
42
+ } %>
43
+ <% end -%>
44
+ <% content_for :javascripts do %>
45
+ <script>
46
+ $(document).ready(function(){
47
+ page_options.init(false, '', '');
48
+ });
49
+ </script>
50
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
2
+ <% if (locales ||= ::Refinery::I18n.frontend_locales).present? and locales.many? %>
3
+ <ul id='switch_locale_picker' class='clearfix'>
4
+ <% locales.each do |locale| %>
5
+ <li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
6
+ <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '48x33'),
7
+ url_for(:switch_locale => locale) %>
8
+ </li>
9
+ <% end %>
10
+ </ul>
11
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <% if @snippets.any? %>
5
+ <div class='pagination_container'>
6
+ <%= render :partial => 'snippets' %>
7
+ </div>
8
+ <% else %>
9
+ <p>
10
+ <% unless searching? %>
11
+ <strong>
12
+ <%= t('.no_items_yet') %>
13
+ </strong>
14
+ <% else %>
15
+ <%= t('no_results', :scope => 'shared.admin.search') %>
16
+ <% end %>
17
+ </p>
18
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(snippet) -%>">
2
+ <span class='title'>
3
+ <%= snippet.title %>
4
+ <% if ::Refinery::I18n.frontend_locales.many? and
5
+ (locales = snippet.translations.collect{|t| t.locale}).present? %>
6
+ <span class='preview'>
7
+ <% locales.each do |locale| %>
8
+ <%= refinery_icon_tag "flags/#{locale}.png", :size => '16x11' %>
9
+ <% end %>
10
+ </span>
11
+ <% end %>
12
+ </span>
13
+ <span class='actions'>
14
+ <%= link_to refinery_icon_tag("application_go.png"), snippet_url(snippet),
15
+ :title => t('.view_live_html'),
16
+ :target => "_blank" %>
17
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_snippet_path(snippet),
18
+ :title => t('.edit') %>
19
+ <%= link_to refinery_icon_tag("delete.png"), admin_snippet_path(snippet),
20
+ :class => "cancel confirm-delete",
21
+ :title => t('.delete'),
22
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => snippet.title),
23
+ :method => :delete %>
24
+ </span>
25
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @snippets %>
2
+ <%= render :partial => "sortable_list" %>
@@ -0,0 +1,7 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'snippet', :collection => @snippets %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list",
5
+ :locals => {
6
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true
7
+ } %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,10 @@
1
+ <section id='records'>
2
+ <%= render :partial => 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render :partial => 'actions' %>
6
+ </aside>
7
+ <%= render :partial => '/shared/admin/make_sortable',
8
+ :locals => {
9
+ :tree => false
10
+ } if !searching? and Admin::SnippetsController.sortable? and Snippet.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,11 @@
1
+ <% content_for :body_content_left do %>
2
+ <ul id="snippets">
3
+ <% @snippets.each do |snippet| %>
4
+ <li>
5
+ <%= link_to snippet.title, snippet_url(snippet) %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
9
+ <% end %>
10
+
11
+ <%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,33 @@
1
+ <% content_for :body_content_title do %>
2
+ <%= @snippet.title %>
3
+ <% end %>
4
+
5
+ <% content_for :body_content_left do %>
6
+ <section>
7
+ <h1>Title</h1>
8
+ <p>
9
+ <%=raw @snippet.title %>
10
+ </p>
11
+ </section>
12
+ <section>
13
+ <h1>Body</h1>
14
+ <p>
15
+ <%=raw @snippet.body %>
16
+ </p>
17
+ </section>
18
+ <% end %>
19
+
20
+ <% content_for :body_content_right do %>
21
+ <aside>
22
+ <h2><%= t('.other') %></h2>
23
+ <ul id="snippets">
24
+ <% @snippets.each do |snippet| %>
25
+ <li>
26
+ <%= link_to snippet.title, snippet_url(snippet) %>
27
+ </li>
28
+ <% end %>
29
+ </ul>
30
+ </aside>
31
+ <% end %>
32
+
33
+ <%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,25 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ snippets:
8
+ title: Snippets
9
+ admin:
10
+ snippets:
11
+ actions:
12
+ create_new: Add New Snippet
13
+ reorder: Reorder Snippets
14
+ reorder_done: Done Reordering Snippets
15
+ records:
16
+ title: Snippets
17
+ sorry_no_results: Sorry! There are no results found.
18
+ no_items_yet: There are no Snippets yet. Click "Add New Snippet" to add your first snippet.
19
+ snippet:
20
+ view_live_html: View this snippet live <br/><em>(opens in a new window)</em>
21
+ edit: Edit this snippet
22
+ delete: Remove this snippet forever
23
+ snippets:
24
+ show:
25
+ other: Other Snippets
@@ -0,0 +1,25 @@
1
+ lolcat:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: IMAGE
6
+ plugins:
7
+ snippets:
8
+ title: Snippets
9
+ admin:
10
+ snippets:
11
+ actions:
12
+ create_new: CREATE NEW Snippet
13
+ reorder: REORDR Snippets
14
+ reorder_done: DUN REORDERIN Snippets
15
+ records:
16
+ title: Snippets
17
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
18
+ no_items_yet: THAR R NO Snippets YET. CLICK "CREATE NEW Snippet" 2 ADD UR FURST snippet.
19
+ snippet:
20
+ view_live_html: VIEW DIS snippet LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
21
+ edit: EDIT DIS snippet
22
+ delete: REMOOV DIS snippet FOREVR
23
+ snippets:
24
+ show:
25
+ other: OTHR Snippets
@@ -0,0 +1,21 @@
1
+ nb:
2
+ plugins:
3
+ snippets:
4
+ title: Snippets
5
+ admin:
6
+ snippets:
7
+ actions:
8
+ create_new: Lag en ny Snippet
9
+ reorder: Endre rekkefølgen på Snippets
10
+ reorder_done: Ferdig å endre rekkefølgen Snippets
11
+ records:
12
+ title: Snippets
13
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
14
+ no_items_yet: Det er ingen Snippets enda. Klikk på "Lag en ny Snippet" for å legge til din første snippet.
15
+ snippet:
16
+ view_live_html: Vis hvordan denne snippet ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
17
+ edit: Rediger denne snippet
18
+ delete: Fjern denne snippet permanent
19
+ snippets:
20
+ show:
21
+ other: Andre Snippets
@@ -0,0 +1,21 @@
1
+ nl:
2
+ plugins:
3
+ snippets:
4
+ title: Snippets
5
+ admin:
6
+ snippets:
7
+ actions:
8
+ create_new: Maak een nieuwe Snippet
9
+ reorder: Wijzig de volgorde van de Snippets
10
+ reorder_done: Klaar met het wijzingen van de volgorde van de Snippets
11
+ records:
12
+ title: Snippets
13
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
14
+ no_items_yet: Er zijn nog geen Snippets. Druk op 'Maak een nieuwe Snippet' om de eerste aan te maken.
15
+ snippet:
16
+ view_live_html: Bekijk deze snippet op de website <br/><em>(opent een nieuw venster)</em>
17
+ edit: Bewerk deze snippet
18
+ delete: Verwijder deze snippet voor eeuwig
19
+ snippets:
20
+ show:
21
+ other: Andere Snippets
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Refinery::Application.routes.draw do
2
+ resources :snippets, :only => [:index, :show]
3
+
4
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
5
+ resources :snippets, :except => :show do
6
+ collection do
7
+ post :update_positions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class RefinerycmsSnippets < Refinery::Generators::EngineInstaller
2
+
3
+ source_root File.expand_path('../../../', __FILE__)
4
+ engine_name "snippets"
5
+
6
+ end
@@ -0,0 +1,31 @@
1
+ require 'refinerycms-base'
2
+
3
+ module Refinery
4
+ module Snippets
5
+ class Engine < Rails::Engine
6
+ initializer "static assets" do |app|
7
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
8
+ end
9
+
10
+ config.to_prepare do
11
+ Page.module_eval do
12
+ has_many :snippet_pages
13
+ has_many :snippets, :through => :snippet_pages, :order => 'position ASC'
14
+ end
15
+ end
16
+
17
+ config.after_initialize do
18
+ ::Refinery::Pages::Tab.register do |tab|
19
+ tab.name = "snippets"
20
+ tab.partial = "/admin/pages/tabs/snippets"
21
+ end
22
+ Refinery::Plugin.register do |plugin|
23
+ plugin.name = "snippets"
24
+ plugin.activity = {
25
+ :class => Snippet
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :snippets do
4
+
5
+ # call this task my running: rake refinery:snippets:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-snippets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Marek L.
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-04 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby on Rails Snippets engine for Refinery CMS
22
+ email: nospam.keram@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/generators/refinerycms_snippets_generator.rb
31
+ - lib/refinerycms-snippets.rb
32
+ - lib/tasks/snippets.rake
33
+ - config/routes.rb
34
+ - config/locales/lolcat.yml
35
+ - config/locales/en.yml
36
+ - config/locales/nb.yml
37
+ - config/locales/nl.yml
38
+ - app/controllers/snippets_controller.rb
39
+ - app/controllers/admin/snippets_controller.rb
40
+ - app/models/snippet_page.rb
41
+ - app/models/snippet.rb
42
+ - app/views/snippets/show.html.erb
43
+ - app/views/snippets/index.html.erb
44
+ - app/views/admin/snippets/_snippets.html.erb
45
+ - app/views/admin/snippets/edit.html.erb
46
+ - app/views/admin/snippets/_sortable_list.html.erb
47
+ - app/views/admin/snippets/index.html.erb
48
+ - app/views/admin/snippets/_form.html.erb
49
+ - app/views/admin/snippets/new.html.erb
50
+ - app/views/admin/snippets/_records.html.erb
51
+ - app/views/admin/snippets/_locale_picker.html.erb
52
+ - app/views/admin/snippets/_actions.html.erb
53
+ - app/views/admin/snippets/_snippet.html.erb
54
+ - app/views/admin/pages/tabs/_snippets.html.erb
55
+ - app/views/admin/pages/tabs/_snippets_bar.html.erb
56
+ - app/views/admin/pages/tabs/_snippets_field.html.erb
57
+ has_rdoc: true
58
+ homepage:
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Html snippets for Refinery CMS page
91
+ test_files: []
92
+