Permalink
Browse files

first version - unstable

  • Loading branch information...
1 parent 209b9bb commit 3014b8109cf7a1ec6da16bf63a9b5ea20c94e08a @keram keram committed Oct 19, 2011
Showing with 313 additions and 330 deletions.
  1. +0 −36 app/controllers/admin/snippets_controller.rb
  2. +0 −36 app/controllers/admin/snippets_page_parts_controller.rb
  3. +38 −0 app/controllers/refinery/admin/snippets_controller.rb
  4. +38 −0 app/controllers/refinery/admin/snippets_page_parts_controller.rb
  5. +44 −0 app/models/refinery/snippet.rb
  6. +16 −0 app/models/refinery/snippet_page.rb
  7. +16 −0 app/models/refinery/snippet_page_part.rb
  8. +0 −42 app/models/snippet.rb
  9. +0 −14 app/models/snippet_page.rb
  10. +0 −14 app/models/snippet_page_part.rb
  11. +0 −3 app/views/admin/pages/tabs/_snippets.html.erb
  12. +0 −1 app/views/admin/snippets_page_parts/add.html.erb
  13. +0 −1 app/views/admin/snippets_page_parts/remove.html.erb
  14. +3 −0 app/views/refinery/admin/pages/tabs/_snippets.html.erb
  15. +6 −4 app/views/{ → refinery}/admin/pages/tabs/_snippets_content.html.erb
  16. +5 −5 app/views/{ → refinery}/admin/pages/tabs/_snippets_field.html.erb
  17. +2 −2 app/views/{ → refinery}/admin/pages/tabs/_snippets_list_item.html.erb
  18. +7 −7 app/views/{ → refinery}/admin/snippets/_actions.html.erb
  19. +3 −7 app/views/{ → refinery}/admin/snippets/_form.html.erb
  20. 0 app/views/{ → refinery}/admin/snippets/_form_actions.html.erb
  21. +1 −1 app/views/{ → refinery}/admin/snippets/_locale_picker.html.erb
  22. 0 app/views/{ → refinery}/admin/snippets/_records.html.erb
  23. +2 −2 app/views/{ → refinery}/admin/snippets/_snippet.html.erb
  24. 0 app/views/{ → refinery}/admin/snippets/_snippets.html.erb
  25. +1 −1 app/views/{ → refinery}/admin/snippets/_sortable_list.html.erb
  26. 0 app/views/{ → refinery}/admin/snippets/edit.html.erb
  27. +2 −2 app/views/{ → refinery}/admin/snippets/index.html.erb
  28. 0 app/views/{ → refinery}/admin/snippets/new.html.erb
  29. +1 −0 app/views/refinery/admin/snippets_page_parts/add.html.erb
  30. +1 −0 app/views/refinery/admin/snippets_page_parts/remove.html.erb
  31. +34 −33 config/locales/en.yml
  32. +5 −7 config/routes.rb
  33. +10 −10 db/migrate/1_create_snippets.rb
  34. +0 −18 db/migrate/2_create_snippet_page.rb
  35. +22 −0 db/migrate/2_translate_snippets.rb
  36. +21 −0 db/migrate/3_create_snippets_page_parts.rb
  37. +0 −22 db/migrate/3_translate_snippets.rb
  38. +0 −19 db/migrate/4_create_snippets_page_parts.rb
  39. +0 −20 db/migrate/5_drop_snippet_page.rb
  40. +2 −2 db/seeds/snippets.rb
  41. +2 −2 features/support/paths.rb
  42. +2 −2 lib/extensions/page_extensions.rb
  43. +8 −0 lib/generators/refinery/refinerycms_snippets_generator.rb
  44. +0 −6 lib/generators/refinerycms_snippets_generator.rb
  45. +21 −11 lib/refinerycms-snippets.rb
@@ -1,36 +0,0 @@
-module Admin
- class SnippetsController < Admin::BaseController
-
- crudify :snippet, :xhr_paging => true
-
- def create
- if (@snippet = Snippet.create(params[:snippet])).valid?
- (request.xhr? ? flash.now : flash).notice = t(
- 'refinery.crudify.created',
- :what => "#{@snippet.title}"
- )
-
- unless request.xhr?
- redirect_to (params[:continue_editing] =~ /1/ ? edit_admin_snippet_path(@snippet) : admin_snippets_url)
- else
- response = Hash.new
- response['redirect'] = edit_admin_snippet_path(@snippet) if params[:continue_editing]
- render :json => response
- end
-
- else
- unless request.xhr?
- render :action => 'new'
- else
- html_snippets = Hash.new
- html_snippets['flash_container'] = render_to_string(:partial => "/shared/admin/error_messages",
- :locals => {
- :object => @snippet,
- :include_object_name => true
- })
- render :json => {'snippets' => html_snippets}
- end
- end
- end
- end
-end
@@ -1,36 +0,0 @@
-module Admin
- class SnippetsPagePartsController < Admin::BaseController
-
- def add
- @page = Page.find(params[:id])
- @part = PagePart.find(params[:part_id])
- @snippet = Snippet.find(params[:snippet_id])
- before_body = params[:before_body] == 'true' ? true : false
-
- sp = SnippetPagePart.new(:page_part => @part, :snippet => @snippet, :before_body => before_body)
-
- if sp.save
- flash[:notice] = "Snippet #{@snippet.title} was successfully added."
- end
-
- render :layout => false if request.xhr?
- end
-
- def remove
- @page = Page.find(params[:id])
- @part = PagePart.find(params[:part_id])
- @snippet = Snippet.find(params[:snippet_id])
- before_body = params[:before_body] == 'true' ? true : false
-
- sp = SnippetPagePart.where(:page_part_id => @part, :snippet_id => @snippet, :before_body => before_body)
-
- removed = sp.first.destroy() unless sp.empty?
-
- if removed
- flash[:notice] = "Snippet #{@snippet.title} was successfully removed."
- end
-
- render :layout => false if request.xhr?
- end
- end
-end
@@ -0,0 +1,38 @@
+module ::Refinery
+ module Admin
+ class SnippetsController < ::Refinery::AdminController
+
+ crudify :'refinery/snippet', :xhr_paging => true
+
+ def create
+ if (@snippet = Refinery::Snippet.create(params[:snippet])).valid?
+ (request.xhr? ? flash.now : flash).notice = t(
+ 'refinery.crudify.created',
+ :what => "#{@snippet.title}"
+ )
+
+ unless request.xhr?
+ redirect_to (params[:continue_editing] =~ /1/ ? main_app.edit_refinery_admin_snippet_path(@snippet) : main_app.refinery_admin_snippets_url)
+ else
+ response = Hash.new
+ response['redirect'] = main_app.edit_refinery_admin_snippet_path(@snippet) if params[:continue_editing]
+ render :json => response
+ end
+
+ else
+ unless request.xhr?
+ render :action => 'new'
+ else
+ html_snippets = Hash.new
+ html_snippets['flash_container'] = render_to_string(:partial => "/shared/admin/error_messages",
+ :locals => {
+ :object => @snippet,
+ :include_object_name => true
+ })
+ render :json => {'snippets' => html_snippets}
+ end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,38 @@
+module ::Refinery
+ module Admin
+ class SnippetsPagePartsController < ::Refinery::AdminController
+
+ def add
+ @page = Refinery::Page.find(params[:id])
+ @part = Refinery::PagePart.find(params[:part_id])
+ @snippet = Refinery::Snippet.find(params[:snippet_id])
+ before_body = params[:before_body] == 'true' ? true : false
+
+ sp = Refinery::SnippetPagePart.new(:page_part => @part, :snippet => @snippet, :before_body => before_body)
+
+ if sp.save
+ flash[:notice] = "Snippet #{@snippet.title} was successfully added."
+ end
+
+ render :layout => false if request.xhr?
+ end
+
+ def remove
+ @page = Refinery::Page.find(params[:id])
+ @part = Refinery::PagePart.find(params[:part_id])
+ @snippet = Refinery::Snippet.find(params[:snippet_id])
+ before_body = params[:before_body] == 'true' ? true : false
+
+ sp = Refinery::SnippetPagePart.where(:page_part_id => @part, :snippet_id => @snippet, :before_body => before_body)
+
+ removed = sp.first.destroy() unless sp.empty?
+
+ if removed
+ flash[:notice] = "Snippet #{@snippet.title} was successfully removed."
+ end
+
+ render :layout => false if request.xhr?
+ end
+ end
+ end
+end
@@ -0,0 +1,44 @@
+module Refinery
+ class Snippet < ActiveRecord::Base
+
+ acts_as_indexed :fields => [:title, :body]
+
+ validates :title, :presence => true, :uniqueness => true
+
+ translates :body
+
+ has_many :snippet_page_parts, :dependent => :destroy
+ has_many :page_parts, :through => :snippet_page_parts
+
+ scope :for_page, lambda{ |page|
+ raise RuntimeError.new("Couldn't find Snippet for a nil Page") if page.blank?
+ joins(:page_parts => :page).where(:pages => {:id => page.id})
+
+ }
+
+ scope :before, where(:snippets_page_parts => {:before_body => true})
+ scope :after, where(:snippets_page_parts => {:before_body => false})
+
+ # rejects any page that has not been translated to the current locale.
+ scope :translated, lambda {
+ pages = Arel::Table.new(Refinery::Snippet.table_name)
+ translations = Arel::Table.new(Refinery::Snippet.translations_table_name)
+
+ includes(:translations).where(
+ translations[:locale].eq(Globalize.locale)).where(pages[:id].eq(translations[:snippet_id]))
+ }
+
+ def pages
+ Refinery::Page.for_snippet(self)
+ end
+
+ def before?(part)
+ part.snippets.before.include? self
+ end
+
+ def after?(part)
+ part.snippets.after.include? self
+ end
+
+ end
+end
@@ -0,0 +1,16 @@
+module Refinery
+ class SnippetPage < ActiveRecord::Base
+
+ set_table_name 'snippet_page'
+
+ belongs_to :snippet, :foreign_key => :snippet_id
+ belongs_to :page, :foreign_key => :page_id
+
+ validates_uniqueness_of(:snippet_id, :scope => :page_id)
+
+ before_save do |snippet_page|
+ snippet_page.position = (Refinery::SnippetPage.where('page_id = ?', snippet_page.page_id).maximum(:position) || -1) + 1
+ end
+
+ end
+end
@@ -0,0 +1,16 @@
+module Refinery
+ class SnippetPagePart < ActiveRecord::Base
+
+ set_table_name 'snippets_page_parts'
+
+ belongs_to :snippet, :foreign_key => :snippet_id
+ belongs_to :page_part, :foreign_key => :page_part_id
+
+ validates_uniqueness_of :snippet_id, :scope => [:page_part_id, :before_body]
+
+ before_save do |snippet_page_part|
+ snippet_page_part.position = (Refinery::SnippetPagePart.where('page_part_id = ?', snippet_page_part.page_part_id).maximum(:position) || -1) + 1
+ end
+
+ end
+end
View
@@ -1,42 +0,0 @@
-class Snippet < ActiveRecord::Base
-
- acts_as_indexed :fields => [:title, :body]
-
- validates :title, :presence => true, :uniqueness => true
-
- translates :body
-
- has_many :snippet_page_parts, :dependent => :destroy
- has_many :page_parts, :through => :snippet_page_parts
-
- named_scope :for_page, lambda{ |page|
- raise RuntimeError.new("Couldn't find Snippet for a nil Page") if page.blank?
- joins(:page_parts => :page).where(:pages => {:id => page.id})
-
- }
-
- scope :before, where(:snippets_page_parts => {:before_body => true})
- scope :after, where(:snippets_page_parts => {:before_body => false})
-
- # 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]))
- }
-
- def pages
- Page.for_snippet(self)
- end
-
- def before?(part)
- part.snippets.before.include? self
- end
-
- def after?(part)
- part.snippets.after.include? self
- end
-
-end
View
@@ -1,14 +0,0 @@
-class SnippetPage < ActiveRecord::Base
-
- set_table_name 'snippet_page'
-
- belongs_to :snippet, :foreign_key => :snippet_id
- belongs_to :page, :foreign_key => :page_id
-
- validates_uniqueness_of(:snippet_id, :scope => :page_id)
-
- before_save do |snippet_page|
- snippet_page.position = (SnippetPage.where('page_id = ?', snippet_page.page_id).maximum(:position) || -1) + 1
- end
-
-end
@@ -1,14 +0,0 @@
-class SnippetPagePart < ActiveRecord::Base
-
- set_table_name 'snippets_page_parts'
-
- belongs_to :snippet, :foreign_key => :snippet_id
- belongs_to :page_part, :foreign_key => :page_part_id
-
- validates_uniqueness_of :snippet_id, :scope => [:page_part_id, :before_body]
-
- before_save do |snippet_page_part|
- snippet_page_part.position = (SnippetPagePart.where('page_part_id = ?', snippet_page_part.page_part_id).maximum(:position) || -1) + 1
- end
-
-end
@@ -1,3 +0,0 @@
-<div class="wym_skin_refinery page_part" id="page_snippet_picker">
- <%= render :partial => '/admin/pages/tabs/snippets_content', :locals => {:f => f} %>
-</div>
@@ -1 +0,0 @@
-<%= render :partial => '/admin/pages/tabs/snippets_content' %>
@@ -1 +0,0 @@
-<%= render :partial => '/admin/pages/tabs/snippets_content' %>
@@ -0,0 +1,3 @@
+<div class="wym_skin_refinery page_part" id="page_snippet_picker">
+ <%= render :partial => '/refinery/admin/pages/tabs/snippets_content', :locals => {:f => f} %>
+</div>
@@ -3,12 +3,14 @@
<% else %>
<div id="part-snippets-menu">
<ul>
- <% @page.parts.each do |part|%>
- <li><%= link_to(part.title, :anchor => "part-#{part.id}") %> |</li>
- <% end %>
+ <% @page.parts.each do |part|%>
+ <li>
+ <%= link_to(part.title, main_app.url_for(:anchor => "part-#{part.id}")) %> |
+ </li>
+ <% end %>
</ul>
</div>
- <%= render :partial => '/admin/pages/tabs/snippets_field', :collection => @page.parts, :as => :part %>
+ <%= render :partial => '/refinery/admin/pages/tabs/snippets_field', :collection => @page.parts, :as => :part %>
<% end %>
<% content_for :stylesheets do %>
@@ -4,19 +4,19 @@
<% if part.snippets.before.any? %>
<h2><%= t('.before_body') %></h2>
<ul>
- <%= render :partial => '/admin/pages/tabs/snippets_list_item', :collection => part.snippets.before, :as => :snippet, :locals => {:part => part, :before_body => true} %>
+ <%= render :partial => '/refinery/admin/pages/tabs/snippets_list_item', :collection => part.snippets.before, :as => :snippet, :locals => {:part => part, :before_body => true} %>
</ul>
<% end %>
<% if part.snippets.after.any? %>
<h2><%= t('.after_body') %></h2>
<ul>
- <%= render :partial => '/admin/pages/tabs/snippets_list_item', :collection => part.snippets.after, :as => :snippet, :locals => {:part => part, :before_body => false} %>
+ <%= render :partial => '/refinery/admin/pages/tabs/snippets_list_item', :collection => part.snippets.after, :as => :snippet, :locals => {:part => part, :before_body => false} %>
</ul>
<% end %>
</div>
<div class="inactive-snippets">
- <% inactive_snippets = Snippet.all %>
+ <% inactive_snippets = Refinery::Snippet.all %>
<% if inactive_snippets.length > 0 %>
<h2><%= t('.inactive') %></h2>
<ul>
@@ -25,12 +25,12 @@
<span class="title"><%= snippet.title %></span>
<div class="actions">
<% unless snippet.after?(part) %>
- <%= link_to t('.add_after_body'), {:controller => 'snippets_page_parts', :action => 'add', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id}, :class => 'add_icon add-snippet' %>
+ <%= link_to t('.add_after_body'), main_app.url_for({:controller => 'snippets_page_parts', :action => 'add', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id}), :class => 'add-snippet' %>
<% else %>
<span class="add_icon add-snippet"><%= t('.add_after_body') %></span>
<% end %>
<% unless snippet.before?(part) %>
- <%= link_to t('.add_before_body'), {:controller => 'snippets_page_parts', :action => 'add', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id, :before_body => 'true'}, :class => 'add_icon add-snippet' %>
+ <%= link_to t('.add_before_body'), main_app.url_for({:controller => 'snippets_page_parts', :action => 'add', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id, :before_body => 'true'}), :class => 'add-snippet' %>
<% else %>
<span class="add_icon add-snippet"><%= t('.add_before_body') %></span>
<% end %>
@@ -11,9 +11,9 @@
<% end %>
</span>
<span class='actions'>
- <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_snippet_path(snippet),
+ <%= link_to refinery_icon_tag('application_edit.png'), main_app.edit_refinery_admin_snippet_path(snippet),
:title => t('.edit') %>
- <%= link_to refinery_icon_tag('delete.png'), url_for({:controller => 'snippets_page_parts', :action => 'remove', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id, :before_body => before_body}),
+ <%= link_to refinery_icon_tag('delete.png'), main_app.url_for({:controller => 'snippets_page_parts', :action => 'remove', :id => @page.id, :snippet_id => snippet.id, :part_id => part.id, :before_body => before_body}),
:title => t('.remove'),
:class => 'remove-snippet' %>
</span>
Oops, something went wrong.

0 comments on commit 3014b81

Please sign in to comment.