locomotive_cms 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -176,7 +176,11 @@ module Locomotive
176
176
  self._slug = self._label.dup if self._slug.blank? && self._label.present?
177
177
 
178
178
  if self._slug.present?
179
- self._slug.permalink!
179
+ # if the slug includes one "_" at least, we consider that the "_" is used instead of "-".
180
+ underscore = !self._slug.index('_').nil?
181
+
182
+ self._slug.permalink!(underscore)
183
+
180
184
  self._slug = self.next_unique_slug if self.slug_already_taken?
181
185
  end
182
186
 
@@ -106,7 +106,12 @@ module Locomotive
106
106
 
107
107
  def normalize_slug
108
108
  self.slug = self.title.clone if self.slug.blank? && self.title.present?
109
- self.slug.permalink! if self.slug.present?
109
+ if self.slug.present?
110
+ # if the slug includes one "_" at least, we consider that the "_" is used instead of "-".
111
+ underscore = !self.slug.index('_').nil?
112
+
113
+ self.slug.permalink!(underscore)
114
+ end
110
115
  end
111
116
 
112
117
  def set_default_raw_template
@@ -15,8 +15,6 @@
15
15
   - 
16
16
  %i
17
17
  - case field.type.to_s
18
- - when 'string', 'text', 'boolean', 'date'
19
- = value
20
18
  - when 'file'
21
19
  - url = value.guess_url
22
20
  - url = url =~ /^http/ ? url : URI.join("http://#{@domain}", url).to_s # Amazon S3 (http/https) or local files ?
@@ -26,4 +24,8 @@
26
24
  - when 'belongs_to'
27
25
  = value.try(:_label)
28
26
  - when 'has_many', 'many_to_many'
29
- = value.map(&:_label).join(', ')
27
+ = value.map(&:_label).join(', ')
28
+ - when 'tags'
29
+ = value.join(', ')
30
+ - else
31
+ = value
@@ -36,6 +36,7 @@ module Locomotive
36
36
  tinymce/plugins/locomotive_media/*.js
37
37
  tinymce/plugins/locomotive_media/langs/*.js
38
38
  tinymce/themes/advanced/skins/locomotive/*.css
39
+ aloha/plugins/custom/locomotive_media/**/*.css
39
40
  aloha/plugins/custom/locomotive_media/**/*.js
40
41
  aloha/plugins/custom/inputcontrol/**/*.css
41
42
  aloha/plugins/custom/inputcontrol/**/*.js)
@@ -42,32 +42,53 @@ module Locomotive
42
42
 
43
43
  def collection
44
44
  if @context['with_scope']
45
- self.modify_with_scope_with_relations
45
+ self.modify_with_scope
46
46
  end
47
47
 
48
48
  @collection ||= @content_type.ordered_entries(@context['with_scope']).visible
49
49
  end
50
50
 
51
- def modify_with_scope_with_relations
52
- relations = @content_type.klass_with_custom_fields(:entries).relations
53
- @context['with_scope'].dup.each do |key, value|
54
- if relation = self.relation_with(key, relations)
55
- model = Locomotive::ContentType.class_name_to_content_type(relation.class_name, @context.registers[:site])
56
- entry = model.entries.where(model.label_field_name => value).first
51
+ def modify_with_scope
52
+ fields = @content_type.ordered_custom_fields(:entries)
57
53
 
58
- @context['with_scope'].delete(key)
59
- @context['with_scope'][relation.key] = entry
54
+ @context['with_scope'].dup.each do |key, value|
55
+ if relation = self.relation_with(key)
56
+ # belongs_to, has_many, many_to_many relationships: use the _id
57
+ self.modify_with_scope_with_relation(key, value, relation)
58
+ elsif field = fields.detect { |f| f.name == key && f.type == 'select' }
59
+ # use the id of the option instead of the name
60
+ self.modify_with_scope_with_select(key, value, field)
60
61
  end
61
62
  end
62
63
  end
63
64
 
64
- def relation_with(name, relations)
65
- if relations.keys.include?(name.to_s)
66
- relations[name]
67
- elsif relations.keys.include?(name.to_s.pluralize)
68
- relations[name.to_s.pluralize]
65
+ def modify_with_scope_with_relation(key, value, relation)
66
+ model = Locomotive::ContentType.class_name_to_content_type(relation.class_name, @context.registers[:site])
67
+ entry = model.entries.where(model.label_field_name => value).first
68
+
69
+ # modify the scope
70
+ @context['with_scope'].delete(key)
71
+ @context['with_scope'][relation.key] = entry
72
+ end
73
+
74
+ def relation_with(name)
75
+ @relations ||= @content_type.klass_with_custom_fields(:entries).relations
76
+
77
+ if @relations.keys.include?(name.to_s)
78
+ @relations[name]
79
+ elsif @relations.keys.include?(name.to_s.pluralize)
80
+ @relations[name.to_s.pluralize]
69
81
  end
70
82
  end
83
+
84
+ def modify_with_scope_with_select(key, value, field)
85
+ option = field.select_options.detect { |option| [option.name, option._id.to_s].include?(value) }
86
+
87
+ # modify the scope
88
+ @context['with_scope'].delete(key)
89
+ @context['with_scope']["#{key}_id"] = option.try(:_id)
90
+ end
91
+
71
92
  end
72
93
 
73
94
  end
@@ -14,6 +14,7 @@ module Locomotive
14
14
  end
15
15
 
16
16
  protected
17
+
17
18
  def scoped_pages
18
19
  if @context["with_scope"]
19
20
  self._source.pages.where(@context["with_scope"])
@@ -21,6 +22,7 @@ module Locomotive
21
22
  self._source.pages
22
23
  end
23
24
  end
25
+
24
26
  end
25
27
  end
26
28
  end
@@ -1,3 +1,3 @@
1
1
  module Locomotive #:nodoc
2
- VERSION = '2.2.0'
2
+ VERSION = '2.2.1'
3
3
  end
@@ -23,8 +23,10 @@ namespace :locomotive do
23
23
  page.send :_parse_and_serialize_template
24
24
  page.save
25
25
  puts "[#{site.name}][#{locale}] processing...#{page.title}"
26
- rescue TypeError => e
26
+ rescue TypeError
27
27
  pages.insert(0, page)
28
+ rescue ::Liquid::Error => e
29
+ puts "\tLiquid error: #{e.message} (#{page._id})"
28
30
  end
29
31
  end
30
32
  end
@@ -43,6 +43,10 @@ describe Locomotive::ContentEntry do
43
43
  build_content_entry(_slug: 'dogs').tap(&:save!)._slug.should == 'dogs'
44
44
  end
45
45
 
46
+ it 'accepts underscore instead of dashes' do
47
+ build_content_entry(_slug: 'monkey_wrench').tap(&:save!)._slug.should == 'monkey_wrench'
48
+ end
49
+
46
50
  it 'uses the given slug if it is unique' do
47
51
  build_content_entry(_slug: 'monkeys').tap(&:save!)._slug.should == 'monkeys'
48
52
  build_content_entry(_slug: 'cats-2').tap(&:save!)._slug.should == 'cats-2'
@@ -114,6 +114,10 @@ describe Locomotive::Page do
114
114
  page = FactoryGirl.build(:page, title: ' Valid ité.html ', slug: nil, site: page.site)
115
115
  page.should be_valid
116
116
  page.slug.should == 'valid-ite-dot-html'
117
+
118
+ page = FactoryGirl.build(:page, slug: ' convention_Valid ité.html ')
119
+ page.valid?
120
+ page.slug.should == 'convention_valid_ite_dot_html'
117
121
  end
118
122
 
119
123
  it 'has no cache strategy' do
@@ -180,9 +184,9 @@ describe Locomotive::Page do
180
184
  archives.reload.children.count.should == 2
181
185
  archives.children.last.depth.should == 2
182
186
  archives.children.last.children.first.depth.should == 3
183
-
187
+
184
188
  end
185
-
189
+
186
190
  it "builds children fullpaths" do
187
191
  sub_child_1 = FactoryGirl.create(:page, title: 'Sub Subpage 1', slug: 'bar', parent: @child_1, site: @home.site)
188
192
  sub_child_1.fullpath.should == "foo/bar"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotive_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-07 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -1416,7 +1416,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1416
1416
  version: '0'
1417
1417
  segments:
1418
1418
  - 0
1419
- hash: -31990377363803179
1419
+ hash: 4035827424997986314
1420
1420
  required_rubygems_version: !ruby/object:Gem::Requirement
1421
1421
  none: false
1422
1422
  requirements:
@@ -1425,7 +1425,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1425
1425
  version: '0'
1426
1426
  segments:
1427
1427
  - 0
1428
- hash: -31990377363803179
1428
+ hash: 4035827424997986314
1429
1429
  requirements: []
1430
1430
  rubyforge_project:
1431
1431
  rubygems_version: 1.8.23