locomotive_cms 1.0.0.beta → 1.0.0.beta.2

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.
@@ -0,0 +1,25 @@
1
+ module Models
2
+ module Extensions
3
+ module Page
4
+ module Redirect
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+
10
+ field :redirect, :type => Boolean, :default => false
11
+
12
+ field :redirect_url, :type => String
13
+
14
+ validates_presence_of :redirect_url, :if => :redirect
15
+
16
+ validates_format_of :redirect_url, :with => Locomotive::Regexps::URL, :allow_blank => true
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+
data/app/models/page.rb CHANGED
@@ -8,6 +8,7 @@ class Page
8
8
  include Models::Extensions::Page::Parse
9
9
  include Models::Extensions::Page::Render
10
10
  include Models::Extensions::Page::Templatized
11
+ include Models::Extensions::Page::Redirect
11
12
 
12
13
  ## fields ##
13
14
  field :title
@@ -11,7 +11,7 @@
11
11
 
12
12
  = f.input :slug, :required => false, :hint => @page.slug.blank? ? ' ' : @page.url, :input_html => { :data_url => get_path_admin_pages_url, :disabled => @page.index? || @page.not_found? }, :wrapper_html => { :style => "#{'display: none' if @page.templatized?}" }
13
13
 
14
- = f.custom_input :templatized, :css => 'toggle' do
14
+ = f.custom_input :templatized, :css => 'toggle', :style => "#{'display: none' if @page.redirect?}" do
15
15
  = f.check_box :templatized
16
16
 
17
17
  = f.input :content_type_id, :as => :select, :collection => current_site.content_types.all.to_a, :include_blank => false, :wrapper_html => { :style => "#{'display: none' unless @page.templatized?}" }
@@ -19,7 +19,12 @@
19
19
  = f.custom_input :published, :css => 'toggle' do
20
20
  = f.check_box :published
21
21
 
22
- = f.input :cache_strategy, :as => :select, :collection => options_for_page_cache_strategy, :include_blank => false
22
+ = f.custom_input :redirect, :css => 'toggle', :style => "#{'display: none' if @page.templatized?}" do
23
+ = f.check_box :redirect
24
+
25
+ = f.input :cache_strategy, :as => :select, :collection => options_for_page_cache_strategy, :include_blank => false, :wrapper_html => { :style => "#{'display: none' if @page.redirect?}" }
26
+
27
+ = f.input :redirect_url, :required => true, :wrapper_html => { :style => "#{'display: none' unless @page.redirect?}" }
23
28
 
24
29
  = render 'editable_elements', :page => @page
25
30
 
data/config/assets.yml CHANGED
@@ -82,6 +82,7 @@ stylesheets:
82
82
  - public/stylesheets/admin/buttons.css
83
83
  - public/stylesheets/admin/formtastic.css
84
84
  - public/stylesheets/admin/formtastic_changes.css
85
+ - public/stylesheets/admin/assets.css
85
86
  - public/stylesheets/admin/application.css
86
87
  - public/stylesheets/admin/safari.css
87
88
  fancybox:
@@ -15,10 +15,21 @@ module Locomotive
15
15
 
16
16
  self.add_page(fullpath)
17
17
  end
18
+
19
+ # make sure all the pages were processed (redirection pages without template for instance)
20
+ self.pages.each { |fullpath, attributes| self.add_page_without_template(fullpath.to_s) }
18
21
  end
19
22
 
20
23
  protected
21
24
 
25
+ def add_page_without_template(fullpath)
26
+ page = context[:done][fullpath]
27
+
28
+ return page if page # already added, so skip it
29
+
30
+ self._save_page!(fullpath, nil)
31
+ end
32
+
22
33
  def add_page(fullpath)
23
34
  page = context[:done][fullpath]
24
35
 
@@ -30,6 +41,10 @@ module Locomotive
30
41
 
31
42
  self.build_parent_template(template)
32
43
 
44
+ self._save_page!(fullpath, template)
45
+ end
46
+
47
+ def _save_page!(fullpath, template)
33
48
  parent = self.find_parent(fullpath)
34
49
 
35
50
  attributes = {
@@ -42,20 +57,22 @@ module Locomotive
42
57
 
43
58
  # templatized ?
44
59
  if content_type_slug = attributes.delete(:content_type)
45
- fullpath.gsub!(/\/template$/, '/content_type_template')
46
60
  attributes.merge!({
47
61
  :templatized => true,
48
62
  :content_type => site.content_types.where(:slug => content_type_slug).first
49
63
  })
50
64
  end
51
65
 
52
- page = site.pages.where(:fullpath => fullpath).first || site.pages.build
66
+ # redirection page ?
67
+ attributes[:redirect] = true if attributes[:redirect_url].present?
68
+
69
+ page = site.pages.where(:fullpath => self.sanitize_fullpath(fullpath)).first || site.pages.build
53
70
 
54
71
  page.attributes = attributes
55
72
 
56
73
  page.save!
57
74
 
58
- self.log "adding #{page.fullpath} / #{page.position}"
75
+ self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}"
59
76
 
60
77
  site.reload
61
78
 
@@ -162,6 +179,10 @@ module Locomotive
162
179
  pages
163
180
  end
164
181
 
182
+ def sanitize_fullpath(fullpath)
183
+ fullpath.gsub(/\/template$/, '/content_type_template')
184
+ end
185
+
165
186
  end
166
187
  end
167
188
  end
@@ -19,7 +19,9 @@ module Locomotive
19
19
  def parse_parent_template
20
20
  if @template_name == 'parent'
21
21
  if @context[:cached_parent]
22
- @context[:parent_page] = @context[:cached_parent]
22
+ @context[:parent_page] = @context[:cached_parent] #.clone # parent must not be modified
23
+
24
+ @context[:cached_parent].instance_variable_set(:@template, nil) # force to reload the template
23
25
  @context[:cached_parent] = nil
24
26
  else
25
27
  @context[:parent_page] = @context[:page].parent
@@ -31,7 +33,12 @@ module Locomotive
31
33
 
32
34
  raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil?
33
35
 
34
- @context[:parent_page].template
36
+ # be sure to work with a copy of the parent template otherwise there will be conflicts
37
+ parent_template = @context[:parent_page].template.clone
38
+
39
+ @context[:parent_page].instance_variable_set(:@template, parent_template)
40
+
41
+ parent_template
35
42
  end
36
43
 
37
44
  end
@@ -22,7 +22,7 @@ module Locomotive
22
22
  html += inline_hints_for(name, options) || ''
23
23
  html += self.errors_on(name) || ''
24
24
 
25
- template.content_tag(:li, template.find_and_preserve(html), :class => "#{options[:css]} #{'error' unless @object.errors[name].empty?}")
25
+ template.content_tag(:li, template.find_and_preserve(html), :style => "#{options[:style]}", :class => "#{options[:css]} #{'error' unless @object.errors[name].empty?}")
26
26
  end
27
27
 
28
28
  def inline_errors_on(method, options = nil)
@@ -5,5 +5,7 @@ module Locomotive
5
5
 
6
6
  DOMAIN = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
7
7
 
8
+ URL = /((http|https|ftp):\/)?\/\S*/
9
+
8
10
  end
9
11
  end
@@ -9,10 +9,12 @@ module Locomotive
9
9
 
10
10
  def render_locomotive_page
11
11
  if request.fullpath =~ /^\/admin\//
12
- render :template => "/admin/errors/404", :layout => '/admin/layouts/box', :status => 404
12
+ render :template => "/admin/errors/404", :layout => '/admin/layouts/box', :status => :not_found
13
13
  else
14
14
  @page = locomotive_page
15
15
 
16
+ redirect_to(@page.redirect_url) and return if @page.present? && @page.redirect?
17
+
16
18
  render_no_page_error and return if @page.nil?
17
19
 
18
20
  output = @page.render(locomotive_context)
@@ -50,7 +52,7 @@ module Locomotive
50
52
  end
51
53
  end
52
54
 
53
- page || current_site.pages.not_found.published.first
55
+ page || not_found_page
54
56
  end
55
57
 
56
58
  def locomotive_context
@@ -91,13 +93,21 @@ module Locomotive
91
93
  end
92
94
  end
93
95
 
94
- render :text => output, :layout => false, :status => :ok
96
+ render :text => output, :layout => false, :status => page_status
97
+ end
98
+
99
+ def not_found_page
100
+ current_site.pages.not_found.published.first
95
101
  end
96
102
 
97
103
  def editing_page?
98
104
  self.params[:editing] == true && current_admin
99
105
  end
100
106
 
107
+ def page_status
108
+ @page == not_found_page ? :not_found : :ok
109
+ end
110
+
101
111
  end
102
112
 
103
113
  end
@@ -1,3 +1,3 @@
1
1
  module Locomotive #:nodoc
2
- VERSION = "1.0.0.beta"
2
+ VERSION = "1.0.0.beta.2"
3
3
  end
@@ -26,7 +26,8 @@ $(document).ready(function() {
26
26
  params += '&_method=put';
27
27
 
28
28
  $.post($(this).attr('data_url'), params, function(data) {
29
- $.growl('success', data.notice);
29
+ var error = typeof(data.error) != 'undefined';
30
+ $.growl((error ? 'error' : 'success'), (error ? data.error : data.notice));
30
31
  }, 'json');
31
32
  }
32
33
  });
@@ -35,15 +36,31 @@ $(document).ready(function() {
35
36
 
36
37
  $.subscribe('toggle.page_templatized.checked', function(event, data) {
37
38
  $('#page_slug_input').hide();
39
+ $('#page_redirect').parent('li').hide();
38
40
  $('#page_content_type_id_input').show();
39
41
  }, []);
40
42
 
41
43
  $.subscribe('toggle.page_templatized.unchecked', function(event, data) {
42
44
  $('#page_slug_input').show();
45
+ $('#page_redirect').parent('li').show();
43
46
  $('#page_slug').val(makeSlug($('#page_title').val())).addClass('touched');
44
47
  $('#page_content_type_id_input').hide();
45
48
  }, []);
46
49
 
50
+ // redirect feature
51
+
52
+ $.subscribe('toggle.page_redirect.checked', function(event, data) {
53
+ $('#page_templatized').parent('li').hide();
54
+ $('#page_cache_strategy_input').hide();
55
+ $('#page_redirect_url_input').show();
56
+ }, []);
57
+
58
+ $.subscribe('toggle.page_redirect.unchecked', function(event, data) {
59
+ $('#page_templatized').parent('li').show();
60
+ $('#page_cache_strategy_input').show();
61
+ $('#page_redirect_url_input').hide();
62
+ }, []);
63
+
47
64
  // automatic slug from page title
48
65
  $('#page_title').keypress(function() {
49
66
  var input = $(this);
@@ -1,5 +1,3 @@
1
- @import url(/stylesheets/admin/assets.css);
2
-
3
1
  /* ___ application messages ___ */
4
2
 
5
3
  div.notice {
@@ -171,6 +171,8 @@ form.formtastic div.actions a {
171
171
  top: 4px;
172
172
  }
173
173
 
174
+ form.formtastic div.actions a.remove { color: #ff092c !important; }
175
+
174
176
  form.formtastic div.actions p a:hover { text-decoration: underline; }
175
177
 
176
178
  form.formtastic div.actions .last p { text-align: right; }
@@ -89,7 +89,7 @@
89
89
  left: 7px;
90
90
  }
91
91
 
92
- #page-toolbar ul li.sep { float: left; margin: 0 15px 0 10px; }
92
+ #page-toolbar ul li.sep { float: left; margin: 0 15px 0 10px; width: auto !important; background: none !important; }
93
93
 
94
94
  #page-toolbar ul li.sep span {
95
95
  display: block;
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotive_cms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31098193
4
+ hash: 62196359
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - beta
11
- version: 1.0.0.beta
11
+ - 2
12
+ version: 1.0.0.beta.2
12
13
  platform: ruby
13
14
  authors:
14
15
  - Didier Lafforgue
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-01-04 00:00:00 +01:00
20
+ date: 2011-01-10 00:00:00 +01:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -446,6 +447,7 @@ files:
446
447
  - app/models/extensions/asset/vignette.rb
447
448
  - app/models/extensions/page/editable_elements.rb
448
449
  - app/models/extensions/page/parse.rb
450
+ - app/models/extensions/page/redirect.rb
449
451
  - app/models/extensions/page/render.rb
450
452
  - app/models/extensions/page/templatized.rb
451
453
  - app/models/extensions/page/tree.rb