spree_snippets 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,25 @@
1
+ class Admin::SnippetsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ def create_draft
5
+ @snippet = Snippet.create!
6
+ redirect_to edit_admin_snippet_url(@snippet.id)
7
+ end
8
+
9
+ update.response do |wants|
10
+ wants.html { redirect_to collection_url }
11
+ end
12
+
13
+ update.after do
14
+ Rails.cache.delete('snippets')
15
+ end
16
+
17
+ create.response do |wants|
18
+ wants.html { redirect_to collection_url }
19
+ end
20
+
21
+ create.after do
22
+ Rails.cache.delete('snippets')
23
+ end
24
+
25
+ end
@@ -0,0 +1,45 @@
1
+ ActionController::Base.class_eval do
2
+ include ActionView::Helpers::RawOutputHelper
3
+
4
+ helper_method :render_snippet
5
+
6
+ # snippet can be something that responds to "slug" and "content",
7
+ # or a slug, or an id
8
+ def render_snippet(snippet)
9
+ if snippet.respond_to?('content')
10
+ @snippet = snippet
11
+ elsif snippet.kind_of?(Fixnum)
12
+ @snippet = Snippet.find(snippet)
13
+ elsif snippet.kind_of?(String)
14
+ @snippet = Snippet.find_by_slug(snippet)
15
+ else
16
+ raise "Unable to handle snippet '#{snippet}'"
17
+ end
18
+
19
+ if Spree::Config[:spree_snippets_raise_on_missing] == "t" && @snippet.nil?
20
+ raise "Snippet '#{snippet}' not found"
21
+ end
22
+ return nil unless @snippet
23
+
24
+ template = ERB.new File.read(File.expand_path(snippet_wrapper_absolute_path))
25
+ raw template.result(binding)
26
+ end
27
+
28
+ private
29
+
30
+ # Returns the location of the snippet wrapper, which is dependent on how spree is installed.
31
+ def snippet_wrapper_absolute_path
32
+ engine_path = File.join(File.dirname(__FILE__), '..', '..', '..')
33
+
34
+ [Rails.root, engine_path].each do |root|
35
+ absolute_path = File.join(root, snippet_wrapper_path)
36
+ return absolute_path if File.exists?(absolute_path)
37
+ end
38
+ raise "Unable to find snippet wrapper using path '#{snippet_wrapper_path}'"
39
+ end
40
+
41
+ # Override the location returned by this method if you want your own snippet wrapper template
42
+ def snippet_wrapper_path
43
+ 'app/views/snippets/_snippet.html.erb'
44
+ end
45
+ end
@@ -0,0 +1,2 @@
1
+ module Admin::SnippetsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module SnippetHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Snippet < ActiveRecord::Base
2
+ validates_uniqueness_of :slug, :allow_blank => true
3
+ end
@@ -0,0 +1,28 @@
1
+ <style type="text/css" media="screen">
2
+ .snippet-form-bottom-buttons {
3
+ margin-left: 5px;
4
+ margin-bottom: 20px;
5
+ }
6
+ </style>
7
+
8
+ <table class="admin-report" width="545">
9
+ <tr>
10
+ <td valign="top"><%=t("snippets_slug")%>:</td>
11
+ <td><%= f.text_field :slug, {"style" => "width: 745px"} %></td>
12
+ </tr>
13
+ <tr>
14
+ <td colspan="2">
15
+ <%= f.text_area :content, {"style" => "width:100%", "id" => "snippet_content"} %>
16
+ </td>
17
+ </tr>
18
+ </table>
19
+
20
+ <div class="snippet-form snippet-form-bottom-buttons">
21
+ <div class="button" id="snippet_content_switch_simple">
22
+ <a href="#"><%= t("editor.switch_simple") %></a>
23
+ </div>
24
+ <div class="button" id="snippet_content_switch_rich" style="display: none;">
25
+ <a href="#"><%= t("editor.switch_rich") %></a>
26
+ </div>
27
+ </div>
28
+
@@ -0,0 +1,13 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("editing_snippet") %></h1>
4
+
5
+ <%= render "shared/error_messages", :target => @snippet %>
6
+
7
+ <% form_for(:snippet, :url => object_url, :html => { :method => :put }) do |f| %>
8
+ <%= render :partial => "form", :locals => { :f => f } %>
9
+ <p class="form-buttons">
10
+ <%= button t("actions.update"), nil, 'submit' %>
11
+ <%= t("or") %> <%= link_to t("actions.cancel"), collection_url %>
12
+ </p>
13
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <div class='toolbar'>
4
+ <ul class='actions'>
5
+ <li id="new_product_link">
6
+ <%= button_link_to t("new_snippet"), create_draft_admin_snippets_url, {:icon => 'add'} %>
7
+ </li>
8
+ </ul>
9
+ <br class='clear' />
10
+ </div>
11
+
12
+ <h1><%=t("snippets") %></h1>
13
+
14
+ <table class="index">
15
+ <tr>
16
+ <th><%=t("snippets_slug")%></th>
17
+ <th><%=t("action")%></th>
18
+ </tr>
19
+ <tbody>
20
+ <% @snippets.each do |snippet| %>
21
+ <tr class="<%= cycle('even', 'odd') %>" id="<%= dom_id snippet %>">
22
+ <td>
23
+ <%= snippet.slug %>
24
+ </td>
25
+ <td>
26
+ <%= link_to_edit snippet %> &nbsp;
27
+ <%= link_to_delete snippet %>
28
+ </td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -0,0 +1,13 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t("new_snippet") %></h1>
4
+
5
+ <%= render "shared/error_messages", :target => @snippet %>
6
+
7
+ <% form_for(:snippet, :url => collection_url) do |f| %>
8
+ <%= render :partial => "form", :locals => { :f => f } %>
9
+ <p class="form-buttons">
10
+ <%= button t("actions.create"), nil, 'submit' %>
11
+ <%= t("or") %> <%= link_to t("actions.cancel"), collection_url %>
12
+ </p>
13
+ <% end %>
@@ -0,0 +1 @@
1
+ <div id="snippet_<%=@snippet.id%>"><%= @snippet.content %></div>
@@ -0,0 +1,17 @@
1
+ require 'spree_core'
2
+ require 'spree_snippets_hooks'
3
+
4
+ module SpreeSnippets
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
+ Rails.env.production? ? require(c) : load(c)
12
+ end
13
+ end
14
+
15
+ config.to_prepare &method(:activate).to_proc
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ class SpreeSnippetsHooks < Spree::ThemeSupport::HookListener
2
+ insert_after :admin_tabs do
3
+ %(<%= tab(:snippets) %>)
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ namespace :spree_snippets do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_snippets:install:migrations'].invoke
5
+ # Not needed yet
6
+ # Rake::Task['spree_snippets:install:assets'].invoke
7
+ end
8
+
9
+ namespace :install do
10
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
11
+ task :migrations do
12
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
+ destination = File.join(Rails.root, 'db')
14
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
15
+ Spree::FileUtilz.mirror_files(source, destination)
16
+ end
17
+
18
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
19
+ task :assets do
20
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
21
+ destination = File.join(Rails.root, 'public')
22
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
23
+ Spree::FileUtilz.mirror_files(source, destination)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_snippets
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.5.0
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Maujean
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-05 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: spree_core
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.30.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: spree_editor
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ description:
39
+ email: cmaujean@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - LICENSE
48
+ - lib/spree_snippets.rb
49
+ - lib/spree_snippets_hooks.rb
50
+ - lib/tasks/install.rake
51
+ - lib/tasks/spree_snippets.rake
52
+ - app/controllers/admin/snippets_controller.rb
53
+ - app/controllers/spree/base_controller_decorator.rb
54
+ - app/helpers/admin/snippets_helper.rb
55
+ - app/helpers/snippet_helper.rb
56
+ - app/models/snippet.rb
57
+ - app/views/admin/snippets/_form.html.erb
58
+ - app/views/admin/snippets/edit.html.erb
59
+ - app/views/admin/snippets/index.html.erb
60
+ - app/views/admin/snippets/new.html.erb
61
+ - app/views/snippets/_snippet.html.erb
62
+ has_rdoc: true
63
+ homepage: http://github.com/cmaujean/spree-snippets
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.7
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: -51902383
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements:
87
+ - none
88
+ rubyforge_project: spree_snippets
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Admin configurable static content for CMS control over specific sections of a view
93
+ test_files: []
94
+