refinerycms-pages 2.0.3 → 2.0.4

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.
@@ -18,11 +18,16 @@ module Refinery
18
18
  def expire_cache
19
19
  # TODO: Where does page_cache_directory come from??
20
20
  return unless page_cache_directory
21
- page_cache_directory = Pathname.new(page_cache_directory.to_s)
21
+ page_cache_directory_path = Pathname.new(page_cache_directory.to_s)
22
22
 
23
23
  # Delete the full Cache
24
- if (cache_root = page_cache_directory.join('refinery', 'cache', 'pages')).directory?
25
- cache_root.rmdir
24
+ if (cache_root = page_cache_directory_path.join('refinery', 'cache', 'pages')).directory?
25
+ cache_root.rmtree
26
+ end
27
+
28
+ # Delete the pages index files (/refinery/cache/pages.html*)
29
+ Pathname.glob(page_cache_directory_path.join('refinery', 'cache', 'pages.html*')).each do |cache_index|
30
+ cache_index.delete
26
31
  end
27
32
  end
28
33
  end
@@ -1,6 +1,15 @@
1
1
  module Refinery
2
2
  module Admin
3
3
  module PagesHelper
4
+ def parent_id_nested_set_options(current_page)
5
+ pages = []
6
+ nested_set_options(::Refinery::Page, current_page) {|page| pages << page}
7
+ # page.title needs the :translations association, doing something like
8
+ # nested_set_options(::Refinery::Page.includes(:translations), page) doesn't work, yet.
9
+ # See https://github.com/collectiveidea/awesome_nested_set/pull/123
10
+ ActiveRecord::Associations::Preloader.new(pages, :translations).run
11
+ pages.map {|page| ["#{'-' * page.level} #{page.title}", page.id]}
12
+ end
4
13
  end
5
14
  end
6
15
  end
@@ -72,8 +72,8 @@ module Refinery
72
72
  # For example with about/example we would need to find 'about' and then its child
73
73
  # called 'example' otherwise it may clash with another page called /example.
74
74
  def find_by_path(path)
75
- split_path = path.to_s.split('/')
76
- page = ::Refinery::Page.by_slug(split_path.shift).first
75
+ split_path = path.to_s.split('/').reject(&:blank?)
76
+ page = ::Refinery::Page.by_slug(split_path.shift, :parent_id => nil).first
77
77
  page = page.children.by_slug(split_path.shift).first until page.nil? || split_path.empty?
78
78
 
79
79
  page
@@ -103,12 +103,9 @@ module Refinery
103
103
  end
104
104
 
105
105
  # Finds a page using its slug. See by_title
106
- def by_slug(slug)
107
- if defined?(::Refinery::I18n)
108
- with_globalize(:locale => Refinery::I18n.frontend_locales, :slug => slug)
109
- else
110
- with_globalize(:locale => ::I18n.locale, :slug => slug)
111
- end
106
+ def by_slug(slug, conditions={})
107
+ locales = Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : ::I18n.locale
108
+ with_globalize({ :locale => locales, :slug => slug }.merge(conditions))
112
109
  end
113
110
 
114
111
  # Shows all pages with :show_in_menu set to true, but it also
@@ -332,16 +329,16 @@ module Refinery
332
329
  Rails.cache.fetch(path_cache_key) { ['', nested_url].join('/') }
333
330
  end
334
331
 
335
- def path_cache_key
336
- [cache_key, 'nested_path'].join('#')
332
+ def path_cache_key(locale = Globalize.locale)
333
+ [cache_key(locale), 'nested_path'].join('#')
337
334
  end
338
335
 
339
- def url_cache_key
340
- [cache_key, 'nested_url'].join('#')
336
+ def url_cache_key(locale = Globalize.locale)
337
+ [cache_key(locale), 'nested_url'].join('#')
341
338
  end
342
339
 
343
- def cache_key
344
- [Refinery::Core.base_cache_key, 'page', ::I18n.locale, id].compact.join('/')
340
+ def cache_key(locale)
341
+ [Refinery::Core.base_cache_key, 'page', locale, id].compact.join('/')
345
342
  end
346
343
 
347
344
  # Returns true if this page is "published"
@@ -453,8 +450,10 @@ module Refinery
453
450
  return true unless Refinery::Pages.marketable_urls
454
451
 
455
452
  [self, children].flatten.each do |page|
456
- Rails.cache.delete(page.url_cache_key)
457
- Rails.cache.delete(page.path_cache_key)
453
+ ((Refinery.i18n_enabled? && Refinery::I18n.frontend_locales) || [::I18n.locale]).each do |locale|
454
+ Rails.cache.delete(page.url_cache_key(locale))
455
+ Rails.cache.delete(page.path_cache_key(locale))
456
+ end
458
457
  end
459
458
  end
460
459
  alias_method :invalidate_child_cached_url, :invalidate_cached_urls
@@ -18,8 +18,7 @@
18
18
  <%= f.label :parent_id, t('.parent_page') %>
19
19
  <%= refinery_help_tag t('.parent_page_help') %>
20
20
  </span>
21
- <%= f.select :parent_id, nested_set_options(::Refinery::Page, @page) {|i| "#{'-' * i.level} #{i.title}" },
22
- :include_blank => true %>
21
+ <%= f.select :parent_id, parent_id_nested_set_options(@page), :include_blank => true %>
23
22
  </div>
24
23
  <% if Refinery::Pages.use_layout_templates %>
25
24
  <div class='field'>
@@ -27,7 +26,11 @@
27
26
  <%= f.label :layout_template, t('.layout_template') %>
28
27
  <%= refinery_help_tag t('.layout_template_help') %>
29
28
  </span>
30
- <%= f.select(:layout_template, @valid_layout_templates) %>
29
+ <% if @page.parent_id? %>
30
+ <%= f.select(:layout_template, @valid_layout_templates, {:selected => @page.parent.layout_template}) %>
31
+ <% else %>
32
+ <%= f.select(:layout_template, @valid_layout_templates) %>
33
+ <% end %>
31
34
  </div>
32
35
  <% end %>
33
36
  <% if Refinery::Pages.use_view_templates %>
@@ -36,7 +39,11 @@
36
39
  <%= f.label :view_template, t('.view_template') %>
37
40
  <%= refinery_help_tag t('.view_template_help') %>
38
41
  </span>
39
- <%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}) %>
42
+ <% if @page.parent_id? %>
43
+ <%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}, {:selected => @page.parent.view_template }) %>
44
+ <% else %>
45
+ <%= f.select(:view_template, @valid_view_templates.map{|t| [t.titleize, t]}) %>
46
+ <% end %>
40
47
  </div>
41
48
  <% end %>
42
49
 
@@ -68,8 +68,10 @@ en:
68
68
  parent_page_help: You can put a page under another page by selecting it in the list. If you want this page to be a top-level page, just leave it blank.
69
69
  menu_title_help: If you want the menu to display a different title than the one that dipsplays on the page, enter it here.
70
70
  custom_slug_help: A slug is a human-readable ID used to create a page&apos;s full URL, for example &apos;about-us&apos;. To override the slug that is automatically created by Refinery, enter your custom slug here.
71
+ layout_template: Layout template
72
+ layout_template_help: You can choose a different layout template for this page
71
73
  view_template: View template
72
- view_template_help: You can chose different template for this page
74
+ view_template_help: You can choose a different view template for this page
73
75
  form_advanced_options_seo:
74
76
  seo: Search Engine Optimization
75
77
  seo_override_title: Browser title
@@ -43,6 +43,9 @@ ru:
43
43
  view_live_html: Показать эту страницу вживую <br/><em>(откроется в новом окне)</em>
44
44
  hidden: скрытая
45
45
  draft: черновик
46
+ form:
47
+ preview: Посмотреть
48
+ preview_changes: Посмотреть свои изменения перед сохранением
46
49
  form_new_page_parts:
47
50
  title: Заголовок
48
51
  form_page_parts:
@@ -16,7 +16,7 @@ module Refinery
16
16
  ).gsub("home page", "Dashboard")
17
17
  =end
18
18
 
19
- render :template => "/pages/show", :layout => layout?, :status => 404
19
+ render :template => "/refinery/pages/show", :layout => layout?, :status => 404
20
20
  return false
21
21
  else
22
22
  super
@@ -14,14 +14,14 @@ Gem::Specification.new do |s|
14
14
  s.email = %q{info@refinerycms.com}
15
15
  s.homepage = %q{http://refinerycms.com}
16
16
  s.rubyforge_project = %q{refinerycms}
17
- s.authors = ['Philip Arndt', 'Uģis Ozols', 'David Jones', 'Steven Heidel']
17
+ s.authors = ['Philip Arndt', 'Uģis Ozols', 'Rob Yurkowski', 'David Jones', 'Steven Heidel']
18
18
  s.license = %q{MIT}
19
19
  s.require_paths = %w(lib)
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.test_files = `git ls-files -- spec/*`.split("\n")
23
23
 
24
- s.add_dependency 'awesome_nested_set', '~> 2.1.0'
24
+ s.add_dependency 'awesome_nested_set', '~> 2.1.3'
25
25
  s.add_dependency 'seo_meta', '~> 1.3.0'
26
26
  s.add_dependency 'refinerycms-core', version
27
27
  s.add_dependency 'babosa', '!= 0.3.6'
@@ -411,5 +411,24 @@ module Refinery
411
411
  end
412
412
  end
413
413
 
414
+ describe '.find_by_path' do
415
+ let(:page_title) { 'team' }
416
+ let(:child_title) { 'about' }
417
+ let(:created_root_about) { subject.class.create!(:title => child_title, :deletable => true) }
418
+
419
+ before(:each) do
420
+ # Ensure pages are created.
421
+ created_child
422
+ created_root_about
423
+ end
424
+
425
+ it "should return (root) about page when looking for '/about'" do
426
+ Refinery::Page.find_by_path('/about').should == created_root_about
427
+ end
428
+
429
+ it "should return child about page when looking for '/team/about'" do
430
+ Refinery::Page.find_by_path('/team/about').should == created_child
431
+ end
432
+ end
414
433
  end
415
434
  end
@@ -506,6 +506,39 @@ module Refinery
506
506
  end
507
507
  end
508
508
  end
509
+
510
+ describe 'advanced options' do
511
+ describe 'view and layout templates' do
512
+ context 'when parent page has templates set' do
513
+ before(:each) do
514
+ Refinery::Pages.stub(:use_layout_templates).and_return(true)
515
+ Refinery::Pages.stub(:use_view_templates).and_return(true)
516
+ Refinery::Pages.stub(:layout_template_whitelist).and_return(['abc', 'refinery'])
517
+ Refinery::Pages.stub(:view_template_whitelist).and_return(['abc', 'refinery'])
518
+ Refinery::Pages.stub(:valid_templates).and_return(['abc', 'refinery'])
519
+ parent_page = FactoryGirl.create(:page, :view_template => 'refinery',
520
+ :layout_template => 'refinery')
521
+ parent_page.children.create(FactoryGirl.attributes_for(:page))
522
+ end
523
+
524
+ specify 'sub page should inherit them' do
525
+ visit refinery.admin_pages_path
526
+
527
+ within '.nested' do
528
+ click_link 'Edit this page'
529
+ end
530
+
531
+ within '#page_layout_template' do
532
+ page.find('option[value=refinery]').selected?.should eq('selected')
533
+ end
534
+
535
+ within '#page_view_template' do
536
+ page.find('option[value=refinery]').selected?.should eq('selected')
537
+ end
538
+ end
539
+ end
540
+ end
541
+ end
509
542
  end
510
543
 
511
544
  describe "TranslatePages" do
@@ -571,6 +604,15 @@ module Refinery
571
604
  Globalize.locale = :en
572
605
  end
573
606
 
607
+ let(:about_page) do
608
+ page = Refinery::Page.last
609
+ # we need page parts so that there's wymeditor
610
+ Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
611
+ page.parts.create(:title => default_page_part, :body => nil, :position => index)
612
+ end
613
+ page
614
+ end
615
+
574
616
  describe "adding page link" do
575
617
  describe "with relative urls" do
576
618
  before(:each) { Refinery::Pages.absolute_page_links = false }
@@ -589,6 +631,7 @@ module Refinery
589
631
  page.should have_selector("a[href='/about']")
590
632
  end
591
633
  end
634
+
592
635
  describe "with absolute urls" do
593
636
  before(:each) { Refinery::Pages.absolute_page_links = true }
594
637
 
@@ -606,6 +649,37 @@ module Refinery
606
649
  page.should have_selector("a[href='http://www.example.com/about']")
607
650
  end
608
651
  end
652
+
653
+ # see https://github.com/resolve/refinerycms/pull/1583
654
+ context "when switching locales" do
655
+ specify "dialog has correct links", :js => true do
656
+ visit refinery.edit_admin_page_path(about_page)
657
+
658
+ click_link "Add Link"
659
+
660
+ page.should have_selector("iframe#dialog_frame")
661
+
662
+ page.within_frame("dialog_frame") do
663
+ page.should have_content("About")
664
+ page.should have_css("a[href$='/about']")
665
+
666
+ click_link "cancel_button"
667
+ end
668
+
669
+ within "#switch_locale_picker" do
670
+ click_link "Ru"
671
+ end
672
+
673
+ click_link "Add Link"
674
+
675
+ page.should have_selector("iframe#dialog_frame")
676
+
677
+ page.within_frame("dialog_frame") do
678
+ page.should have_content("About Ru")
679
+ page.should have_css("a[href$='/ru/about-ru']")
680
+ end
681
+ end
682
+ end
609
683
  end
610
684
  end
611
685
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Philip Arndt
9
9
  - Uģis Ozols
10
+ - Rob Yurkowski
10
11
  - David Jones
11
12
  - Steven Heidel
12
13
  autorequire:
@@ -21,7 +22,7 @@ dependencies:
21
22
  requirements:
22
23
  - - ~>
23
24
  - !ruby/object:Gem::Version
24
- version: 2.1.0
25
+ version: 2.1.3
25
26
  type: :runtime
26
27
  prerelease: false
27
28
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +30,7 @@ dependencies:
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
- version: 2.1.0
33
+ version: 2.1.3
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: seo_meta
35
36
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +54,7 @@ dependencies:
53
54
  requirements:
54
55
  - - '='
55
56
  - !ruby/object:Gem::Version
56
- version: 2.0.3
57
+ version: 2.0.4
57
58
  type: :runtime
58
59
  prerelease: false
59
60
  version_requirements: !ruby/object:Gem::Requirement
@@ -61,7 +62,7 @@ dependencies:
61
62
  requirements:
62
63
  - - '='
63
64
  - !ruby/object:Gem::Version
64
- version: 2.0.3
65
+ version: 2.0.4
65
66
  - !ruby/object:Gem::Dependency
66
67
  name: babosa
67
68
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
195
  version: '0'
195
196
  segments:
196
197
  - 0
197
- hash: 515173493532561148
198
+ hash: 1077792218542240122
198
199
  required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  none: false
200
201
  requirements:
@@ -203,10 +204,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  version: '0'
204
205
  segments:
205
206
  - 0
206
- hash: 515173493532561148
207
+ hash: 1077792218542240122
207
208
  requirements: []
208
209
  rubyforge_project: refinerycms
209
- rubygems_version: 1.8.19
210
+ rubygems_version: 1.8.22
210
211
  signing_key:
211
212
  specification_version: 3
212
213
  summary: Pages extension for Refinery CMS