refinerycms-snippets 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ module Admin
2
+ class SnippetsPageController < Admin::BaseController
3
+
4
+ def add
5
+ @page = Page.find(params[:id])
6
+ @snippet = Snippet.find(params[:snippet_id])
7
+
8
+ sp = SnippetPage.new(:page => @page, :snippet => @snippet)
9
+
10
+ if sp.save
11
+ flash[:notice] = "Snippet #{@snippet.title} was successfully added to page."
12
+ end
13
+
14
+ render :layout => false if request.xhr?
15
+ end
16
+
17
+ def remove
18
+ @page = Page.find(params[:id])
19
+ @snippet = Snippet.find(params[:snippet_id])
20
+
21
+ sp = SnippetPage.where(:page_id => @page, :snippet_id => @snippet)
22
+
23
+ removed = sp.first.destroy() unless sp.empty?
24
+
25
+ if removed
26
+ flash[:notice] = "Snippet #{@snippet.title} was successfully removed from page."
27
+ end
28
+
29
+ render :layout => false if request.xhr?
30
+ end
31
+ end
32
+ end
@@ -5,8 +5,9 @@ class Snippet < ActiveRecord::Base
5
5
  validates :title, :presence => true, :uniqueness => true
6
6
 
7
7
  translates :body
8
-
9
- # has_many :pages, :through => :snippets_pages
8
+
9
+ has_many :snippet_page, :dependent => :destroy
10
+ has_many :pages, :through => :snippet_page
10
11
 
11
12
  def self.inactive(page)
12
13
  @page = page
@@ -1,9 +1,9 @@
1
1
  class SnippetPage < ActiveRecord::Base
2
2
 
3
- set_table_name 'snippets_pages'
3
+ set_table_name 'snippet_page'
4
4
 
5
- belongs_to :snippet, :foreign_key => :snippet_id, :dependent => :destroy
6
- belongs_to :page, :foreign_key => :page_id, :dependent => :destroy
5
+ belongs_to :snippet, :foreign_key => :snippet_id
6
+ belongs_to :page, :foreign_key => :page_id
7
7
 
8
8
  validates_uniqueness_of(:snippet_id, :scope => :page_id)
9
9
 
@@ -1,7 +1,3 @@
1
- <div class='wym_skin_refinery page_part' id='page_snippet_picker' style="padding: 5px;">
1
+ <div class="wym_skin_refinery page_part" id="page_snippet_picker">
2
2
  <%= render :partial => '/admin/pages/tabs/snippets_content', :locals => {:f => f} %>
3
- </div>
4
-
5
- <% content_for :javascripts do %>
6
- <%= javascript_include_tag 'page-snippet-picker' %>
7
- <% end %>
3
+ </div>
@@ -1,2 +1,8 @@
1
- <%= render :partial => '/admin/pages/tabs/snippets_bar' %>
2
- <%= render :partial => '/admin/pages/tabs/snippets_field' %>
1
+ <%= render :partial => '/admin/pages/tabs/snippets_field' %>
2
+
3
+ <% content_for :stylesheets do %>
4
+ <%= stylesheet_link_tag 'page-snippet-picker' %>
5
+ <% end %>
6
+ <% content_for :javascripts do %>
7
+ <%= javascript_include_tag 'page-snippet-picker' %>
8
+ <% end %>
@@ -1,8 +1,9 @@
1
- <div class="wym_box field snippets_field" id="snippets-holder">
1
+ <div id="active-snippets">
2
2
  <% if @page.snippets.any? %>
3
- <ul style="padding: 10px; background: #fff; margin: 5px 0;">
3
+ <h2><%= t('.active') %></h2>
4
+ <ul>
4
5
  <% @page.snippets.each do |snippet| %>
5
- <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(snippet) -%>">
6
+ <li class='clearfix record <%= cycle('on', 'on-hover') %>' >
6
7
  <span class='title'>
7
8
  <%= snippet.title %>
8
9
  <% if ::Refinery::I18n.frontend_locales.many? and
@@ -15,9 +16,9 @@
15
16
  <% end %>
16
17
  </span>
17
18
  <span class='actions'>
18
- <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_snippet_path(snippet),
19
+ <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_snippet_path(snippet),
19
20
  :title => t('.edit') %>
20
- <%= link_to refinery_icon_tag("delete.png"), admin_snippets_pages_path(:page_id => @page.id, 'remove' => snippet.id),
21
+ <%= link_to refinery_icon_tag('delete.png'), url_for({:controller => 'snippets_page', :action => 'remove', :snippet_id => snippet.id, :id => @page.id}),
21
22
  :title => t('.remove'),
22
23
  :class => 'remove-snippet' %>
23
24
  </span>
@@ -25,4 +26,27 @@
25
26
  <% end %>
26
27
  </ul>
27
28
  <% end %>
28
- </div>
29
+ </div>
30
+
31
+ <div id="inactive-snippets">
32
+ <% inactive_snippets = Snippet.inactive(@page) %>
33
+ <% if inactive_snippets.length > 0 %>
34
+ <h2><%= t('.inactive') %></h2>
35
+ <ul>
36
+ <% inactive_snippets.each do |snippet| %>
37
+ <li class='clearfix record <%= cycle('on', 'on-hover') %>' >
38
+ <span class="title"><%= snippet.title %></span>
39
+ <span class="actions">
40
+ <a class="add_icon add-snippet" href="<%= url_for({:controller => 'snippets_page', :action => 'add', :snippet_id => snippet.id, :id => @page.id}) %>">Add</a>
41
+ </span>
42
+ </li>
43
+ <% end %>
44
+ </ul>
45
+ <% end %>
46
+ </div>
47
+
48
+
49
+
50
+
51
+
52
+
@@ -11,9 +11,6 @@
11
11
  <% end %>
12
12
  </span>
13
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
14
  <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_snippet_path(snippet),
18
15
  :title => t('.edit') %>
19
16
  <%= link_to refinery_icon_tag("delete.png"), admin_snippet_path(snippet),
@@ -0,0 +1 @@
1
+ <%= render :partial => '/admin/pages/tabs/snippets_content' %>
@@ -0,0 +1 @@
1
+ <%= render :partial => '/admin/pages/tabs/snippets_content' %>
@@ -1,8 +1,4 @@
1
1
  en:
2
- shared:
3
- admin:
4
- image_picker:
5
- image: image
6
2
  plugins:
7
3
  snippets:
8
4
  title: Snippets
@@ -20,6 +16,14 @@ en:
20
16
  view_live_html: View this snippet live <br/><em>(opens in a new window)</em>
21
17
  edit: Edit this snippet
22
18
  delete: Remove this snippet forever
19
+ pages:
20
+ tabs:
21
+ snippets_field:
22
+ active: Active
23
+ inactive: Inactive
24
+ remove: Remove
25
+ edit: Edit
26
+ add: Add
23
27
  snippets:
24
28
  show:
25
29
  other: Other Snippets
@@ -1,14 +1,19 @@
1
1
  Refinery::Application.routes.draw do
2
- resources :snippets, :only => [:index, :show]
3
2
 
4
3
  scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
5
- resources :snippets, :except => :show do
4
+ resources :snippets do
6
5
  collection do
7
6
  post :update_positions
8
7
  end
8
+
9
+ resources :snippets_page do
10
+ member do
11
+ get 'add'
12
+ get 'remove'
13
+ end
14
+ end
9
15
  end
10
16
 
11
- resources :snippets_pages
12
17
  end
13
18
 
14
19
  end
@@ -8,9 +8,6 @@ class CreateSnippets < ActiveRecord::Migration
8
8
  t.timestamps
9
9
  end
10
10
 
11
- # we have primary key, thus we don't need duplicate index with them
12
- # add_index :snippets, :id
13
-
14
11
  load(Rails.root.join('db', 'seeds', 'snippets.rb'))
15
12
  end
16
13
 
@@ -1,18 +1,18 @@
1
- class CreateSnippetsPages < ActiveRecord::Migration
1
+ class CreateSnippetPage < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
- create_table :snippets_pages do |t|
4
+ create_table :snippet_page do |t|
5
5
  t.integer :snippet_id, :null => false, :references => [:snippets, :id]
6
6
  t.integer :page_id, :null => false, :references => [:pages, :id]
7
7
  t.integer :position, :null => false, :default => 0
8
8
  end
9
9
 
10
- # add_index :snippets_pages, :snippet_id
11
- add_index :snippets_pages, :page_id
10
+ add_index :snippet_page, :snippet_id
11
+ add_index :snippet_page, :page_id
12
12
  end
13
13
 
14
14
  def self.down
15
- drop_table :snippets_pages
15
+ drop_table :snippet_page
16
16
  end
17
17
 
18
18
  end
@@ -3,18 +3,4 @@ User.all.each do |user|
3
3
  user.plugins.create(:name => 'snippets',
4
4
  :position => (user.plugins.maximum(:position) || -1) +1)
5
5
  end
6
- end
7
-
8
- # we don't need this on frontend
9
- #page = Page.create(
10
- # :title => 'Snippets',
11
- # :link_url => '/snippets',
12
- # :show_in_menu => false,
13
- # :deletable => false,
14
- # :position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
15
- # :menu_match => '^/snippets(\/|\/.+?|)$'
16
- #)
17
- #
18
- #Page.default_parts.each do |default_page_part|
19
- # page.parts.create(:title => default_page_part, :body => nil)
20
- #end
6
+ end
@@ -9,7 +9,7 @@ module Refinery
9
9
 
10
10
  config.to_prepare do
11
11
  Page.module_eval do
12
- has_many :snippet_page
12
+ has_many :snippet_page, :dependent => :destroy
13
13
  has_many :snippets, :through => :snippet_page, :order => 'position ASC'
14
14
  end
15
15
  end
@@ -1,24 +1,23 @@
1
- $(document).ready(function(){
1
+ $(document).ready(function (cms) {
2
+ cms = cms || {};
3
+ cms.plugin = cms.plugin || {};
2
4
 
3
5
  /**
4
6
  * Class for handling everything between page and snippets
5
7
  */
6
- var PageSnippet = {
8
+ cms.plugin.PageSnippet = {
7
9
  processing: false,
8
10
  content_holder: [], // html wrapper for all stuff
9
11
  add_snippet: [], // add snippet anchor
10
- inactive_snippets: [], // select box with inactive snippets on page
11
-
12
+ remove_snippet: [],
12
13
 
13
14
  spinner_on: function () {
14
15
  this.processing = true;
15
- this.inactive_snippets.attr('disabled', 'disabled');
16
16
  this.content_holder.css({opacity: 0.5});
17
17
  },
18
18
 
19
19
  spinner_off: function () {
20
20
  this.content_holder.css({opacity: 1});
21
- this.inactive_snippets.removeAttr('disabled');
22
21
  this.processing = false;
23
22
  },
24
23
 
@@ -29,36 +28,25 @@ $(document).ready(function(){
29
28
  this.spinner_off();
30
29
  },
31
30
 
32
- add: function () {
33
- var that = this;
31
+ add: function (elm) {
32
+ var that = this,
33
+ add_url = $(elm).attr('href');
34
34
 
35
35
  if (!this.processing) {
36
- var selected_item = this.inactive_snippets.find('option:selected'),
37
- selected_id = null,
38
- values = [],
39
- add_url = this.add_snippet.attr('href');
40
-
41
- if (selected_item.length > 0 && selected_item.val() !== '') {
42
- this.spinner_on();
43
-
44
- add_url += '&add=' + selected_item.val();
45
-
46
- $.ajax({
47
- url: add_url,
48
- type: 'GET',
49
- dataType: 'html',
50
- error: function (response) { alert(response); },
51
- complete: function (e) {
52
- // console.log(e);
53
- },
54
- success: function (response) {
36
+ this.spinner_on();
55
37
 
56
- that.update(response);
57
- }
58
- });
59
- } else {
60
- this.processing = false;
61
- }
38
+ $.ajax({
39
+ url: add_url,
40
+ type: 'GET',
41
+ dataType: 'html',
42
+ error: function (response) { alert(response); },
43
+ complete: function (e) {
44
+ // console.log(e);
45
+ },
46
+ success: function (response) {
47
+ that.update(response);
48
+ }
49
+ });
62
50
  }
63
51
  },
64
52
 
@@ -67,7 +55,6 @@ $(document).ready(function(){
67
55
  remove_url = $(elm).attr('href');
68
56
 
69
57
  if (!this.processing) {
70
- var values = [];
71
58
  this.spinner_on();
72
59
 
73
60
  // console.log('remove start');
@@ -81,7 +68,6 @@ $(document).ready(function(){
81
68
  // console.log(e);
82
69
  },
83
70
  success: function (response) {
84
- // console.log('pleas');
85
71
  that.update(response);
86
72
  }
87
73
  });
@@ -94,7 +80,8 @@ $(document).ready(function(){
94
80
  clear: function () {
95
81
  // console.log('start clear');
96
82
  this.content_holder.find('a').unbind('click');
97
- this.add_snippet.unbind('click');
83
+ this.content_holder.find('a').unbind('mouseout');
84
+ this.content_holder.find('a').unbind('mouseover');
98
85
  },
99
86
 
100
87
  /**
@@ -102,15 +89,16 @@ $(document).ready(function(){
102
89
  */
103
90
  bind: function () {
104
91
  var that = this;
105
- this.add_snippet = $('#add-snippet');
106
- this.inactive_snippets = $('#inactive_snippets');
92
+ this.add_snippet = this.content_holder.find('a.add-snippet');
93
+ this.remove_snippet = this.content_holder.find('a.remove-snippet');
94
+
107
95
  this.add_snippet.click(function (e) {
108
96
  e.preventDefault();
109
- that.add();
97
+ that.add(this);
110
98
  return false;
111
99
  });
112
100
 
113
- $('a.remove-snippet').click(function (e) {
101
+ this.remove_snippet.click(function (e) {
114
102
  e.preventDefault();
115
103
  that.remove(this);
116
104
  return false;
@@ -118,12 +106,12 @@ $(document).ready(function(){
118
106
  },
119
107
 
120
108
  init: function () {
121
- this.content_holder = $('#page_snippet_picker ');
109
+ this.content_holder = $('#page_snippet_picker');
122
110
  if (this.content_holder.length > 0) {
123
111
  this.bind();
124
112
  }
125
113
  }
126
114
  }
127
115
 
128
- PageSnippet.init();
116
+ cms.plugin.PageSnippet.init();
129
117
  });
@@ -0,0 +1,29 @@
1
+ /*
2
+ Document : page-snippet-picker.css
3
+ Created on : May 16, 2011, 4:41:03 AM
4
+ Author : keram
5
+ Description:
6
+ Styles for snippets administrations
7
+ */
8
+
9
+ a.add-snippet {
10
+ background-repeat: no-repeat;
11
+ background-position: left center;
12
+ border: none;
13
+ padding-left: 20px;
14
+ }
15
+
16
+ #page_snippet_picker ul {
17
+ background: #fff;
18
+ padding: 10px;
19
+ padding-bottom: 0px;
20
+ margin-bottom: 5px;
21
+ }
22
+
23
+ #active-snippets ul {
24
+ margin-bottom: 15px;
25
+ }
26
+
27
+ #inactive-snippets ul {
28
+ background: #fcfcfc;
29
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-snippets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek L.
@@ -15,10 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-09 00:00:00 +02:00
18
+ date: 2011-05-17 00:00:00 +02:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: refinerycms-pages
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 33
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 9
34
+ - 1
35
+ version: 0.9.9.1
36
+ type: :runtime
37
+ version_requirements: *id001
22
38
  description: Ruby on Rails Snippets engine for Refinery CMS
23
39
  email: nospam.keram@gmail.com
24
40
  executables: []
@@ -32,13 +48,10 @@ files:
32
48
  - lib/refinerycms-snippets.rb
33
49
  - lib/tasks/snippets.rake
34
50
  - config/routes.rb
35
- - config/locales/lolcat.yml
36
51
  - config/locales/en.yml
37
- - config/locales/nb.yml
38
52
  - config/locales/nl.yml
39
- - app/controllers/snippets_controller.rb
40
53
  - app/controllers/admin/snippets_controller.rb
41
- - app/controllers/admin/snippets_pages_controller.rb
54
+ - app/controllers/admin/snippets_page_controller.rb
42
55
  - app/models/snippet_page.rb
43
56
  - app/models/snippet.rb
44
57
  - app/views/snippets/show.html.erb
@@ -53,16 +66,17 @@ files:
53
66
  - app/views/admin/snippets/_locale_picker.html.erb
54
67
  - app/views/admin/snippets/_actions.html.erb
55
68
  - app/views/admin/snippets/_snippet.html.erb
69
+ - app/views/admin/snippets_page/remove.html.erb
70
+ - app/views/admin/snippets_page/add.html.erb
56
71
  - app/views/admin/pages/tabs/_snippets.html.erb
57
- - app/views/admin/pages/tabs/_snippets_bar.html.erb
58
72
  - app/views/admin/pages/tabs/_snippets_content.html.erb
59
73
  - app/views/admin/pages/tabs/_snippets_field.html.erb
60
- - app/views/admin/snippets_pages/index.html.erb
61
- - db/migrate/2_create_snippets_pages.rb
74
+ - db/migrate/2_create_snippet_page.rb
62
75
  - db/migrate/1_create_snippets.rb
63
76
  - db/migrate/3_translate_snippets.rb
64
77
  - db/seeds/snippets.rb
65
78
  - public/javascripts/page-snippet-picker.js
79
+ - public/stylesheets/page-snippet-picker.css
66
80
  has_rdoc: true
67
81
  homepage:
68
82
  licenses: []
@@ -93,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
107
  requirements: []
94
108
 
95
109
  rubyforge_project:
96
- rubygems_version: 1.3.7
110
+ rubygems_version: 1.6.2
97
111
  signing_key:
98
112
  specification_version: 3
99
113
  summary: Html snippets for Refinery CMS page
@@ -1,31 +0,0 @@
1
- module Admin
2
- class SnippetsPagesController < Admin::BaseController
3
- def index
4
-
5
- @page = Page.find(params[:page_id])
6
- @do = 'nothing'
7
-
8
- if params[:add].to_i > 0
9
- @do = 'add'
10
- sp = SnippetPage.new(:page => @page, :snippet => Snippet.find(params[:add].to_i))
11
-
12
- if sp.save
13
- flash[:notice] = 'Snippet was successfully added to page.'
14
- end
15
- else
16
- if params[:remove].to_i > 0
17
- @do = 'remove'
18
- sp = SnippetPage.where(:page_id => @page.id, :snippet_id => params[:remove].to_i)
19
- removed = sp.first.delete() unless sp.empty?
20
-
21
- if removed
22
- flash[:notice] = 'Snippet was successfully removed from page.'
23
- end
24
- end
25
- end
26
-
27
- render :layout => false if request.xhr?
28
-
29
- end
30
- end
31
- end
@@ -1,30 +0,0 @@
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
@@ -1,12 +0,0 @@
1
- <div class='wym_area_top'>
2
- <div style="padding: 5px 0;">
3
- <%
4
-
5
- inactive_snippets = Snippet.inactive(@page).map { |snippet| [snippet.title, snippet.id] }
6
- inactive_snippets.unshift(['Select snippet', ''])
7
-
8
- %>
9
- <%= select_tag(:inactive_snippets, options_for_select(inactive_snippets)) %>
10
- <a href="<%= admin_snippets_pages_path(:page_id => @page.id.to_s) %>" id="add-snippet" class="add_icon" style="background-repeat: no-repeat; background-position: left center;border: none; padding: 2px 12px 2px 20px">Add</a>
11
- </div>
12
- </div>
@@ -1,2 +0,0 @@
1
- <%= render :partial => '/admin/pages/tabs/snippets_content' %>
2
- <%#= debug @do %>
@@ -1,25 +0,0 @@
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
@@ -1,21 +0,0 @@
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