spree_essential_cms 0.3.0.rc1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +64 -5
- data/Versionfile +8 -0
- data/app/controllers/spree/admin/contents_controller.rb +4 -4
- data/app/controllers/spree/admin/pages_controller.rb +6 -12
- data/app/controllers/spree/base_controller_decorator.rb +15 -0
- data/app/controllers/spree/home_controller_decorator.rb +23 -0
- data/app/controllers/spree/pages_controller.rb +2 -11
- data/app/models/spree/content.rb +40 -39
- data/app/models/spree/page.rb +21 -10
- data/app/models/spree/page_image.rb +10 -15
- data/app/views/spree/admin/contents/_form.html.erb +9 -4
- data/app/views/spree/admin/contents/edit.html.erb +0 -2
- data/app/views/spree/admin/contents/index.html.erb +22 -23
- data/app/views/spree/admin/contents/new.html.erb +0 -2
- data/app/views/spree/admin/contents/show.html.erb +0 -1
- data/app/views/spree/admin/page_images/edit.html.erb +1 -3
- data/app/views/spree/admin/page_images/index.html.erb +25 -25
- data/app/views/spree/admin/page_images/new.html.erb +3 -1
- data/app/views/spree/admin/pages/edit.html.erb +0 -2
- data/app/views/spree/admin/pages/index.html.erb +26 -26
- data/app/views/spree/admin/pages/new.html.erb +1 -1
- data/app/views/spree/admin/pages/show.html.erb +0 -2
- data/app/views/spree/pages/home.html.erb +10 -0
- data/app/views/spree/shared/_main_menu.html.erb +3 -7
- data/app/views/spree/shared/_main_menu_items.html.erb +6 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/it.yml +63 -0
- data/config/routes.rb +10 -12
- data/{lib/generators/templates/db/migrate/create_pages.rb → db/migrate/20120306185628_create_pages.rb} +0 -0
- data/{lib/generators/templates/db/migrate/create_contents.rb → db/migrate/20120306185638_create_contents.rb} +0 -0
- data/{lib/generators/templates/db/migrate/add_spree_namespace.rb → db/migrate/20120306185648_add_spree_namespace.rb} +0 -0
- data/lib/generators/spree_essentials/cms_generator.rb +3 -8
- data/lib/spree_essential_cms.rb +5 -19
- data/lib/spree_essential_cms/engine.rb +16 -0
- data/lib/spree_essential_cms/version.rb +1 -1
- data/lib/tasks/sample.rake +9 -13
- data/spree_essential_cms.gemspec +34 -0
- data/test/dummy_hooks/after_app_generator.rb +17 -0
- data/test/dummy_hooks/after_migrate.rb.sample +1 -0
- data/test/dummy_hooks/before_migrate.rb +11 -0
- data/test/dummy_hooks/templates/assets/javascripts/admin/all.js +1 -0
- data/test/dummy_hooks/templates/assets/javascripts/store/all.js +1 -0
- data/test/dummy_hooks/templates/assets/stylesheets/admin/all.css +3 -0
- data/test/dummy_hooks/templates/assets/stylesheets/store/all.css +3 -0
- data/test/dummy_hooks/templates/assets/stylesheets/store/screen.css +749 -0
- data/test/dummy_hooks/templates/initializers/spree_user_error_fix.rb +3 -0
- data/test/dummy_hooks/templates/overrides/main_menu.rb +6 -0
- data/test/integration/spree/admin/contents_integration_test.rb +116 -0
- data/test/integration/spree/admin/page_images_integration_test.rb +94 -0
- data/test/integration/spree/admin/pages_integration_test.rb +131 -0
- data/test/integration/spree/home_integration_test.rb +54 -0
- data/test/integration/spree/pages_integration_test.rb +122 -0
- data/test/support/factories.rb +21 -0
- data/test/support/files/1.jpg +0 -0
- data/test/support/files/2.jpg +0 -0
- data/test/support/helpers.rb +13 -0
- data/test/test_helper.rb +19 -0
- data/test/unit/spree/content_test.rb +39 -0
- data/test/unit/spree/essential_test.rb +9 -0
- data/test/unit/spree/page_image_test.rb +47 -0
- data/test/unit/spree/page_test.rb +53 -0
- metadata +117 -48
- data/app/assets/stylesheets/essentials/cms.css +0 -39
- data/app/controllers/spree/page_controller.rb +0 -20
- data/app/controllers/spree/spree_base_controller_decorator.rb +0 -12
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,17 @@ Otherwise, follow these steps to get up and running with SpreeEssentialCms:
|
|
14
14
|
Add spree_essential_cms to your Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
|
17
|
+
# Spree 1.1.x
|
18
|
+
gem 'spree_essential_cms', '~> 0.4.0'
|
19
|
+
|
20
|
+
# Spree 1.0.x
|
21
|
+
gem 'spree_essential_cms', '~> 0.3.0.rc1'
|
22
|
+
|
23
|
+
# Spree 0.70.x
|
24
|
+
gem 'spree_essential_cms', '~> 0.2.1'
|
25
|
+
|
26
|
+
# Spree 0.60.x and below
|
27
|
+
gem 'spree_essential_cms', '~> 0.1.2'
|
18
28
|
```
|
19
29
|
|
20
30
|
Now, bundle up with:
|
@@ -42,6 +52,19 @@ Boot your server and checkout the admin at `localhost:3000/admin`!
|
|
42
52
|
bundle exec rails s
|
43
53
|
```
|
44
54
|
|
55
|
+
### To use the built in main menu create a deface override in your application that looks like this:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
# app/overrides/main_menu.rb
|
59
|
+
Deface::Override.new(:virtual_path => "spree/shared/_store_menu",
|
60
|
+
:name => "spree_essential_cms_main_menu_items",
|
61
|
+
:insert_after => "#home-link[data-hook]",
|
62
|
+
:partial => "spree/shared/main_menu_items",
|
63
|
+
:disabled => false)
|
64
|
+
```
|
65
|
+
|
66
|
+
This example override can be found in `test/dummy_hooks/templates/main_menu.rb`
|
67
|
+
|
45
68
|
|
46
69
|
------------------------------------------------------------------------------
|
47
70
|
Usage
|
@@ -80,7 +103,7 @@ Use a content decorator when you want different contexts to have their own image
|
|
80
103
|
|
81
104
|
# app/models/content_decorator.rb
|
82
105
|
|
83
|
-
Content.class_eval do
|
106
|
+
Spree::Content.class_eval do
|
84
107
|
|
85
108
|
# override default image sizes
|
86
109
|
def default_attachment_sizes
|
@@ -107,12 +130,18 @@ Content.class_eval do
|
|
107
130
|
end
|
108
131
|
```
|
109
132
|
|
133
|
+
### Custom Home Page
|
134
|
+
|
135
|
+
This extension modifies the `Spree::HomeController.index` method and redirects to `/products`
|
136
|
+
if no root page is defined in the spree CMS. In order to define a custom home page you'll need to use another view
|
137
|
+
off of the `Spree::HomeController` class such as `splash`, add the root route
|
138
|
+
(`root :to => 'spree/home#splash'`) to your `config/routes.rb`, and add a blank page with path "/" in the spree CMS.
|
110
139
|
|
111
140
|
------------------------------------------------------------------------------
|
112
141
|
Demo
|
113
142
|
------------------------------------------------------------------------------
|
114
143
|
|
115
|
-
You can easily use the test/dummy app as a demo of spree_essential_cms. Just `cd` to where you develop and run:
|
144
|
+
You can easily use the `test/dummy` app as a demo of spree_essential_cms. Just `cd` to where you develop and run:
|
116
145
|
|
117
146
|
```bash
|
118
147
|
git clone git://github.com/citrus/spree_essential_cms.git
|
@@ -125,11 +154,40 @@ bundle exec rails s
|
|
125
154
|
```
|
126
155
|
|
127
156
|
|
157
|
+
------------------------------------------------------------------------------
|
158
|
+
Testing
|
159
|
+
------------------------------------------------------------------------------
|
160
|
+
|
161
|
+
Testing for spree_essential_cms is done with unit tests and capybara integration tests. To get setup, run the commands below:
|
162
|
+
|
163
|
+
```bash
|
164
|
+
git clone git://github.com/citrus/spree_essential_cms.git
|
165
|
+
cd spree_essential_cms
|
166
|
+
bundle install
|
167
|
+
bundle exec dummier
|
168
|
+
```
|
169
|
+
|
170
|
+
|
171
|
+
Now you've got a test app setup in `test/dummy`. Now you can run the tests with:
|
172
|
+
|
173
|
+
```bash
|
174
|
+
bundle exec rake
|
175
|
+
```
|
176
|
+
|
177
|
+
|
178
|
+
If for any reason you want to re-create your `test/dummy` app, just re-run `bundle exec dummier`.
|
179
|
+
|
180
|
+
|
128
181
|
------------------------------------------------------------------------------
|
129
182
|
Change Log
|
130
183
|
------------------------------------------------------------------------------
|
131
184
|
|
132
|
-
**2012/1
|
185
|
+
**0.4.0 - 2012/5/1**
|
186
|
+
|
187
|
+
* Add support for Spree 1.1.x
|
188
|
+
|
189
|
+
|
190
|
+
**0.3.0.rc1 - 2012/1/16**
|
133
191
|
|
134
192
|
* Add support for Spree 1.0.x
|
135
193
|
|
@@ -166,7 +224,6 @@ Change Log
|
|
166
224
|
To Do
|
167
225
|
------------------------------------------------------------------------------
|
168
226
|
|
169
|
-
* more tests... many many more.
|
170
227
|
* optimizations
|
171
228
|
* A 'create translation' button that clones the current page's contents into another language
|
172
229
|
* add widgets that you can drop into any page
|
@@ -180,7 +237,9 @@ Contributors
|
|
180
237
|
------------------------------------------------------------------------------
|
181
238
|
|
182
239
|
* Spencer Steffen ([@citrus](https://github.com/citrus))
|
240
|
+
* Stéphane Bounmy ([@sbounmy](https://github.com/sbounmy))
|
183
241
|
* Kyle West ([@kylewest](https://github.com/kylewest))
|
242
|
+
* Derek Ethier ([@ethier](https://github.com/ethier))
|
184
243
|
* [@kpitn](https://github.com/kpitn)
|
185
244
|
|
186
245
|
|
data/Versionfile
ADDED
@@ -29,10 +29,10 @@ class Spree::Admin::ContentsController < Spree::Admin::ResourceController
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def collection
|
32
|
-
params[:
|
33
|
-
params[:
|
34
|
-
@search = parent.contents.
|
35
|
-
@collection = @search.page(params[:page]).per(Spree::Config[:orders_per_page])
|
32
|
+
params[:q] ||= {}
|
33
|
+
params[:q][:sort] ||= "page.asc"
|
34
|
+
@search = parent.contents.search(params[:q])
|
35
|
+
@collection = @search.result.page(params[:page]).per(Spree::Config[:orders_per_page])
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -1,11 +1,5 @@
|
|
1
1
|
class Spree::Admin::PagesController < Spree::Admin::ResourceController
|
2
2
|
|
3
|
-
before_filter :load_resource
|
4
|
-
|
5
|
-
def index
|
6
|
-
@pages = collection
|
7
|
-
end
|
8
|
-
|
9
3
|
def location_after_save
|
10
4
|
case params[:action]
|
11
5
|
when "create"
|
@@ -30,12 +24,12 @@ class Spree::Admin::PagesController < Spree::Admin::ResourceController
|
|
30
24
|
def find_resource
|
31
25
|
@page ||= ::Spree::Page.find_by_path(params[:id])
|
32
26
|
end
|
33
|
-
|
27
|
+
|
34
28
|
def collection
|
35
|
-
params[:
|
36
|
-
params[:
|
37
|
-
@search = Spree::Page.
|
38
|
-
@collection = @search.page(params[:page]).per(Spree::Config[:orders_per_page])
|
29
|
+
params[:q] ||= {}
|
30
|
+
params[:q][:sort] ||= "page.asc"
|
31
|
+
@search = Spree::Page.search(params[:q])
|
32
|
+
@collection = @search.result.page(params[:page]).per(Spree::Config[:orders_per_page])
|
39
33
|
end
|
40
34
|
|
41
|
-
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Spree::BaseController.class_eval do
|
2
|
+
|
3
|
+
before_filter :get_pages
|
4
|
+
helper_method :current_page
|
5
|
+
|
6
|
+
def current_page
|
7
|
+
@page ||= Spree::Page.find_by_path(request.fullpath)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_pages
|
11
|
+
return if request.path =~ /^\/+admin/
|
12
|
+
@pages ||= Spree::Page.visible.order(:position).all
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Spree::HomeController.class_eval do
|
2
|
+
|
3
|
+
before_filter :get_homepage
|
4
|
+
|
5
|
+
def index
|
6
|
+
@searcher = Spree::Config.searcher_class.new(params)
|
7
|
+
@products = @searcher.retrieve_products
|
8
|
+
render :template => "spree/pages/home"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get_homepage
|
14
|
+
@page = Spree::Page.find_by_path("/")
|
15
|
+
redirect_to products_url if @page.nil?
|
16
|
+
@page
|
17
|
+
end
|
18
|
+
|
19
|
+
def accurate_title
|
20
|
+
@page.meta_title unless @page.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Spree::PagesController < Spree::BaseController
|
2
|
-
|
3
|
-
before_filter :get_page, :only => :show
|
4
2
|
|
5
3
|
def show
|
4
|
+
@page = current_page
|
5
|
+
raise ActionController::RoutingError.new("No route matches [GET] #{request.fullpath}") if @page.nil?
|
6
6
|
if @page.root?
|
7
7
|
@posts = Spree::Post.live.limit(5) if SpreeEssentials.has?(:blog)
|
8
8
|
@articles = Spree::Article.live.limit(5) if SpreeEssentials.has?(:news)
|
@@ -12,15 +12,6 @@ class Spree::PagesController < Spree::BaseController
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def get_page
|
16
|
-
@page = Spree::Page.includes(:images, :contents).active.find_by_path(page_path) rescue nil
|
17
|
-
raise ActionController::RoutingError.new(page_path) if @page.nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
def page_path
|
21
|
-
params[:page_path].blank? ? "/" : params[:page_path]
|
22
|
-
end
|
23
|
-
|
24
15
|
def accurate_title
|
25
16
|
@page.meta_title
|
26
17
|
end
|
data/app/models/spree/content.rb
CHANGED
@@ -1,62 +1,54 @@
|
|
1
1
|
class Spree::Content < ActiveRecord::Base
|
2
|
-
|
2
|
+
|
3
|
+
attr_accessor :delete_attachment
|
4
|
+
attr_accessible :page_id, :title, :path, :body, :hide_title, :link, :link_text, :context, :attachment, :delete_attachment
|
5
|
+
|
3
6
|
belongs_to :page
|
4
7
|
validates_associated :page
|
5
8
|
validates_presence_of :title, :page
|
6
9
|
|
7
10
|
default_scope order(:position)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:storage => "s3",
|
15
|
-
:s3_credentials => "#{Rails.root}/config/s3.yml"
|
16
|
-
else
|
17
|
-
has_attached_file :attachment,
|
18
|
-
:styles => Proc.new{ |clip| clip.instance.attachment_sizes },
|
19
|
-
:default_style => :preview,
|
20
|
-
:url => "/assets/contents/:id/:style/:basename.:extension",
|
21
|
-
:path => ":rails_root/public/assets/contents/:id/:style/:basename.:extension"
|
22
|
-
end
|
23
|
-
|
11
|
+
|
12
|
+
has_attached_file :attachment,
|
13
|
+
:styles => Proc.new{ |clip| clip.instance.attachment_sizes },
|
14
|
+
:default_style => :preview,
|
15
|
+
:url => "/spree/contents/:id/:style/:basename.:extension",
|
16
|
+
:path => ":rails_root/public/spree/contents/:id/:style/:basename.:extension"
|
24
17
|
|
25
18
|
cattr_reader :per_page
|
26
19
|
@@per_page = 10
|
27
|
-
|
28
|
-
|
20
|
+
|
29
21
|
scope :for, Proc.new{|context| where(:context => context)}
|
30
|
-
|
31
|
-
|
22
|
+
|
23
|
+
before_update :delete_attachment!, :if => :delete_attachment
|
24
|
+
before_update :reprocess_images_if_context_changed
|
25
|
+
|
32
26
|
[ :link_text, :link, :body ].each do |property|
|
33
27
|
define_method "has_#{property.to_s}?" do
|
34
28
|
has_value property
|
35
29
|
end
|
36
30
|
end
|
37
|
-
|
31
|
+
|
38
32
|
def has_full_link?
|
39
33
|
has_link? && has_link_text?
|
40
34
|
end
|
41
|
-
|
35
|
+
|
42
36
|
def has_image?
|
43
37
|
has_value(:attachment_file_name) && attachment_file_name.match(/gif|jpg|png/i)
|
44
38
|
end
|
45
|
-
|
39
|
+
|
46
40
|
def hide_title?
|
47
41
|
self.hide_title == true
|
48
42
|
end
|
49
|
-
|
50
|
-
|
43
|
+
|
51
44
|
def rendered_body
|
52
45
|
RDiscount.new(body.to_s).to_html.html_safe
|
53
46
|
end
|
54
|
-
|
55
|
-
|
47
|
+
|
56
48
|
def default_attachment_sizes
|
57
49
|
{ :mini => '48x48>', :medium => '427x287>' }
|
58
50
|
end
|
59
|
-
|
51
|
+
|
60
52
|
def attachment_sizes
|
61
53
|
case self.context
|
62
54
|
when 'slideshow'
|
@@ -66,18 +58,27 @@ class Spree::Content < ActiveRecord::Base
|
|
66
58
|
end
|
67
59
|
sizes
|
68
60
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
|
72
62
|
def context=(value)
|
73
63
|
write_attribute :context, value.to_s.parameterize
|
74
64
|
end
|
75
65
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
66
|
+
private
|
67
|
+
|
68
|
+
def delete_attachment!
|
69
|
+
del = delete_attachment.to_s
|
70
|
+
self.attachment = nil if del == "1" || del == "true"
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def reprocess_images_if_context_changed
|
75
|
+
return unless context_changed? && attachment_file_name.present?
|
76
|
+
attachment.reprocess!
|
77
|
+
end
|
78
|
+
|
79
|
+
def has_value(selector)
|
80
|
+
v = self.send selector
|
81
|
+
v && !v.to_s.blank?
|
82
|
+
end
|
82
83
|
|
83
|
-
end
|
84
|
+
end
|
data/app/models/spree/page.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
class Spree::Page < ActiveRecord::Base
|
2
2
|
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def find_by_path(_path)
|
6
|
+
return super('/') if _path == "_home_" && self.exists?(:path => "/")
|
7
|
+
super _path.to_s.sub(/^\/*/, "/").gsub("--", "/")
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessible :title, :path, :nav_title, :meta_title, :meta_description, :meta_keywords, :accessible, :visible
|
3
13
|
alias_attribute :name, :title
|
4
14
|
|
5
15
|
validates_presence_of :title
|
@@ -11,19 +21,14 @@ class Spree::Page < ActiveRecord::Base
|
|
11
21
|
scope :visible, active.where(:visible => true)
|
12
22
|
|
13
23
|
has_many :contents, :order => :position, :dependent => :destroy
|
14
|
-
has_many :images, :as => :viewable, :class_name =>
|
24
|
+
has_many :images, :as => :viewable, :class_name => "Spree::PageImage", :order => :position, :dependent => :destroy
|
15
25
|
|
16
26
|
before_validation :set_defaults
|
17
27
|
after_create :create_default_content
|
18
|
-
|
19
|
-
def self.find_by_path(_path)
|
20
|
-
return super('/') if _path == '_home_' && self.exists?(:path => '/')
|
21
|
-
super _path.to_s.sub(/^\/*/, '/').gsub('--', '/')
|
22
|
-
end
|
23
|
-
|
28
|
+
|
24
29
|
def to_param
|
25
|
-
return
|
26
|
-
path.sub(
|
30
|
+
return "_home_" if path == "/"
|
31
|
+
path.sub(/^\/*/, "")
|
27
32
|
end
|
28
33
|
|
29
34
|
def meta_title
|
@@ -47,6 +52,12 @@ class Spree::Page < ActiveRecord::Base
|
|
47
52
|
self.path == "/"
|
48
53
|
end
|
49
54
|
|
55
|
+
def path=(value)
|
56
|
+
value = value.to_s.strip
|
57
|
+
value.gsub!(/[\/\-\_]+$/, "") unless value == "/"
|
58
|
+
write_attribute :path, value
|
59
|
+
end
|
60
|
+
|
50
61
|
private
|
51
62
|
|
52
63
|
def set_defaults
|
@@ -54,7 +65,7 @@ class Spree::Page < ActiveRecord::Base
|
|
54
65
|
#return errors.add(:path, "is reserved. Please use another") if path.to_s =~ /home/
|
55
66
|
self.nav_title = title if nav_title.blank?
|
56
67
|
self.path = nav_title.parameterize if path.blank?
|
57
|
-
self.path = "/" + path.sub(/^\//,
|
68
|
+
self.path = "/" + path.sub(/^\//, "")
|
58
69
|
end
|
59
70
|
|
60
71
|
def create_default_content
|