radiant-site_area_tags-extension 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +16 -0
- data/Rakefile +117 -0
- data/app/models/site_area_tags.rb +154 -0
- data/lib/radiant-site_area_tags-extension.rb +2 -0
- data/lib/radiant-site_area_tags-extension/version.rb +3 -0
- data/lib/tasks/site_area_tags_extension_tasks.rake +55 -0
- data/radiant-site_area_tags-extension.gemspec +24 -0
- data/site_area_tags_extension.rb +10 -0
- data/spec/models/site_area_tags_spec.rb +339 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +44 -0
- metadata +80 -0
data/README
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
= Site Area Tags
|
2
|
+
|
3
|
+
Adds a few Radius tags concerning site "sections" or "area's". These are 100% extracted from the Trike Tags extension:
|
4
|
+
https://github.com/tricycle/radiant-trike-tags-extension
|
5
|
+
|
6
|
+
<r:site_area /> Renders the slug of the top-most parent page which is not the homepage
|
7
|
+
<r:site_sub_area /> Renders the second level parent page slug
|
8
|
+
|
9
|
+
<r:if_same_site_area /> and
|
10
|
+
<r:if_same_site_sub_area /> Render their contents if the local page context is in the same site
|
11
|
+
(sub-)area as the global page context
|
12
|
+
This is typically used inside another tag (like <pre><code><r:children:each></code></pre>) to add
|
13
|
+
conditional mark-up if the child element is in the current site area.
|
14
|
+
|
15
|
+
<r:unless_same_site_sub_area /> and
|
16
|
+
<r:unless_same_site_sub_area /> are also available
|
data/Rakefile
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Determine where the RSpec plugin is by loading the boot
|
2
|
+
unless defined? RADIANT_ROOT
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
case
|
5
|
+
when ENV["RADIANT_ENV_FILE"]
|
6
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
7
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
8
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
9
|
+
else
|
10
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'rake/rdoctask'
|
16
|
+
require 'rake/testtask'
|
17
|
+
|
18
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
19
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
require 'cucumber'
|
22
|
+
require 'cucumber/rake/task'
|
23
|
+
|
24
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
25
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
26
|
+
|
27
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
28
|
+
|
29
|
+
task :default => :spec
|
30
|
+
task :stats => "spec:statsetup"
|
31
|
+
|
32
|
+
desc "Run all specs in spec directory"
|
33
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
34
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
task :features => 'spec:integration'
|
39
|
+
|
40
|
+
namespace :spec do
|
41
|
+
desc "Run all specs in spec directory with RCov"
|
42
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
43
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
44
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
45
|
+
t.rcov = true
|
46
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Print Specdoc for all specs"
|
50
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
51
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
52
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
56
|
+
desc "Run the specs under spec/#{sub}"
|
57
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
58
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
59
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Run the Cucumber features"
|
64
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
65
|
+
t.fork = true
|
66
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
67
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
68
|
+
t.profile = "default"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Setup specs for stats
|
72
|
+
task :statsetup do
|
73
|
+
require 'code_statistics'
|
74
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
75
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
76
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
77
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
78
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
79
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
80
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
81
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
82
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
83
|
+
end
|
84
|
+
|
85
|
+
namespace :db do
|
86
|
+
namespace :fixtures do
|
87
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
88
|
+
task :load => :environment do
|
89
|
+
require 'active_record/fixtures'
|
90
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
91
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
92
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc 'Generate documentation for the site_area_tags extension.'
|
100
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
101
|
+
rdoc.rdoc_dir = 'rdoc'
|
102
|
+
rdoc.title = 'SiteAreaTagsExtension'
|
103
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
104
|
+
rdoc.rdoc_files.include('README')
|
105
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
106
|
+
end
|
107
|
+
|
108
|
+
# For extensions that are in transition
|
109
|
+
desc 'Test the site_area_tags extension.'
|
110
|
+
Rake::TestTask.new(:test) do |t|
|
111
|
+
t.libs << 'lib'
|
112
|
+
t.pattern = 'test/**/*_test.rb'
|
113
|
+
t.verbose = true
|
114
|
+
end
|
115
|
+
|
116
|
+
# Load any custom rakefiles for extension
|
117
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module SiteAreaTags
|
2
|
+
include Radiant::Taggable
|
3
|
+
|
4
|
+
desc %{
|
5
|
+
Renders the slug of the top-most parent page which is not the homepage
|
6
|
+
This functions nicely as a site area (or “section”) name
|
7
|
+
|
8
|
+
*Usage:*
|
9
|
+
<pre><code><r:site_area /></code></pre>
|
10
|
+
}
|
11
|
+
tag "site_area" do |tag|
|
12
|
+
site_area(tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc %{
|
16
|
+
Renders the second level parent page slug
|
17
|
+
(which functions nicely as a site sub-area name)
|
18
|
+
|
19
|
+
*Usage:*
|
20
|
+
<pre><code><r:site_subarea /></code></pre>
|
21
|
+
}
|
22
|
+
tag "site_subarea" do |tag|
|
23
|
+
site_subarea(tag)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc %{
|
27
|
+
Renders the contents of this tag if the local page context is in the same site
|
28
|
+
area as the global page context (see <pre><code><r:site_area /></code></pre>)
|
29
|
+
|
30
|
+
This is typically used inside another tag (like <pre><code><r:children:each></code></pre>) to add
|
31
|
+
conditional mark-up if the child element is in the current site area.
|
32
|
+
|
33
|
+
*Usage:*
|
34
|
+
<pre><code><r:if_same_site_area>…</if_same_site_area></code></pre>
|
35
|
+
|
36
|
+
*Example:*
|
37
|
+
<pre><code>
|
38
|
+
<r:children:each>
|
39
|
+
<r:link><r:title /><r:if_same_site_area>*</r:if_same_site_area></r:link>
|
40
|
+
</r:children:each>
|
41
|
+
</code></pre>
|
42
|
+
}
|
43
|
+
tag 'if_same_site_area' do |tag|
|
44
|
+
tag.expand if same_site_area?(tag)
|
45
|
+
end
|
46
|
+
|
47
|
+
desc %{
|
48
|
+
Renders the contents of this tag unless the local page context is in the same site
|
49
|
+
area as the global page context (see <pre><code><r:if_same_site_area /></code></pre> and <pre><code><r:site_area /></code></pre>)
|
50
|
+
|
51
|
+
This is typically used inside another tag (like <pre><code><r:children:each></code></pre>) to add
|
52
|
+
conditional mark-up if the child element is not in the current site area.
|
53
|
+
|
54
|
+
*Usage:*
|
55
|
+
<pre><code><r:unless_same_site_area>…</unless_same_site_area></code></pre>
|
56
|
+
}
|
57
|
+
tag 'unless_same_site_area' do |tag|
|
58
|
+
tag.expand unless same_site_area?(tag)
|
59
|
+
end
|
60
|
+
|
61
|
+
desc %{
|
62
|
+
Renders the contents of this tag if the local page context is in the same site
|
63
|
+
subarea as the global page context (see <pre><code><r:site_subarea /></code></pre>)
|
64
|
+
|
65
|
+
This is typically used inside another tag (like <pre><code><r:children:each></code></pre>) to add
|
66
|
+
conditional mark-up if the child element is in the same site sub-area as
|
67
|
+
the actual page.
|
68
|
+
|
69
|
+
*Usage:*
|
70
|
+
<pre><code><r:if_same_site_subarea>…</if_same_site_subarea></code></pre>
|
71
|
+
}
|
72
|
+
tag 'if_same_site_subarea' do |tag|
|
73
|
+
tag.expand if same_site_subarea?(tag)
|
74
|
+
end
|
75
|
+
|
76
|
+
desc %{
|
77
|
+
Renders the contents of this tag unless the local page context is in the same site
|
78
|
+
subarea as the global page context (see <pre><code><r:site_subarea /></code></pre>)
|
79
|
+
|
80
|
+
This is typically used inside another tag (like <r:children:each>) to add
|
81
|
+
conditional mark-up if the child element is is note in the same site sub-area
|
82
|
+
as the actual page.
|
83
|
+
|
84
|
+
*Usage:*
|
85
|
+
<pre><code><r:unless_same_site_subarea>…</unless_same_site_subarea></code></pre>
|
86
|
+
}
|
87
|
+
tag 'unless_same_site_subarea' do |tag|
|
88
|
+
tag.expand unless same_site_subarea?(tag)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def site_area(tag)
|
94
|
+
page = tag.locals.page
|
95
|
+
unless page.part("site_area").nil?
|
96
|
+
page.part("site_area").content
|
97
|
+
else
|
98
|
+
site_area = case page.ancestors.length
|
99
|
+
when 0
|
100
|
+
"homepage"
|
101
|
+
when 1
|
102
|
+
page.slug
|
103
|
+
else
|
104
|
+
page.ancestors[-2].slug
|
105
|
+
end
|
106
|
+
if site_area =~ /^\d/
|
107
|
+
site_area = "n#{site_area}"
|
108
|
+
end
|
109
|
+
site_area
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def site_subarea(tag)
|
114
|
+
page = tag.locals.page
|
115
|
+
unless page.part("site_subarea").nil?
|
116
|
+
page.part("site_subarea").content
|
117
|
+
else
|
118
|
+
site_area = case page.ancestors.length
|
119
|
+
when 0..1
|
120
|
+
""
|
121
|
+
when 2
|
122
|
+
page.slug
|
123
|
+
else
|
124
|
+
page.ancestors[-3].slug
|
125
|
+
end
|
126
|
+
if site_area =~ /^\d/
|
127
|
+
site_area = "n#{site_area}"
|
128
|
+
end
|
129
|
+
site_area
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def same_site_area?(tag)
|
134
|
+
local_page = tag.locals.page
|
135
|
+
local_site_area = site_area(tag)
|
136
|
+
|
137
|
+
tag.locals.page = tag.globals.page
|
138
|
+
global_site_area = site_area(tag)
|
139
|
+
|
140
|
+
tag.locals.page = local_page
|
141
|
+
|
142
|
+
local_site_area == global_site_area
|
143
|
+
end
|
144
|
+
|
145
|
+
def same_site_subarea?(tag)
|
146
|
+
local_page = tag.locals.page
|
147
|
+
local_site_subarea = site_subarea(tag)
|
148
|
+
tag.locals.page = tag.globals.page
|
149
|
+
global_site_subarea = site_subarea(tag)
|
150
|
+
tag.locals.page = local_page
|
151
|
+
|
152
|
+
((local_site_subarea == global_site_subarea) and (local_site_subarea != "" or global_site_subarea != ""))
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :site_area_tags do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Site Area Tags extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
SiteAreaTagsExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
SiteAreaTagsExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Site Area Tags to the instance public/ directory."
|
18
|
+
task :update => :environment do
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
20
|
+
puts "Copying assets from SiteAreaTagsExtension"
|
21
|
+
Dir[SiteAreaTagsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(SiteAreaTagsExtension.root, '')
|
23
|
+
directory = File.dirname(path)
|
24
|
+
mkdir_p RAILS_ROOT + directory, :verbose => false
|
25
|
+
cp file, RAILS_ROOT + path, :verbose => false
|
26
|
+
end
|
27
|
+
unless SiteAreaTagsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
|
28
|
+
puts "Copying rake tasks from SiteAreaTagsExtension"
|
29
|
+
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
|
30
|
+
mkdir_p local_tasks_path, :verbose => false
|
31
|
+
Dir[File.join SiteAreaTagsExtension.root, %w(lib tasks *.rake)].each do |file|
|
32
|
+
cp file, local_tasks_path, :verbose => false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Syncs all available translations for this ext to the English ext master"
|
38
|
+
task :sync => :environment do
|
39
|
+
# The main translation root, basically where English is kept
|
40
|
+
language_root = SiteAreaTagsExtension.root + "/config/locales"
|
41
|
+
words = TranslationSupport.get_translation_keys(language_root)
|
42
|
+
|
43
|
+
Dir["#{language_root}/*.yml"].each do |filename|
|
44
|
+
next if filename.match('_available_tags')
|
45
|
+
basename = File.basename(filename, '.yml')
|
46
|
+
puts "Syncing #{basename}"
|
47
|
+
(comments, other) = TranslationSupport.read_file(filename, basename)
|
48
|
+
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
|
49
|
+
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
|
50
|
+
TranslationSupport.write_file(filename, basename, comments, other)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-site_area_tags-extension/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-site_area_tags-extension"
|
7
|
+
s.version = RadiantSiteAreaTagsExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Benny Degezelle"]
|
10
|
+
s.email = ["benny@gorilla-webdesign.be"]
|
11
|
+
s.homepage = "http://github.com/jomz/radiant-site_area_tags-extension"
|
12
|
+
s.summary = %q{Site Area Tags for Radiant CMS}
|
13
|
+
s.description = %q{Makes Radiant better by adding site_area_tags!}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.post_install_message = %{
|
21
|
+
Add this to your radiant project with:
|
22
|
+
config.gem 'radiant-site_area_tags-extension', :version => '#{RadiantSiteAreaTagsExtension::VERSION}'
|
23
|
+
}
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'radiant-site_area_tags-extension/version'
|
2
|
+
class SiteAreaTagsExtension < Radiant::Extension
|
3
|
+
version RadiantSiteAreaTagsExtension::VERSION
|
4
|
+
description "Adds site_area_tags to Radiant."
|
5
|
+
url "http://github.com/jomz/radiant-site_area_tags-extension"
|
6
|
+
|
7
|
+
def activate
|
8
|
+
Page.send :include, SiteAreaTags
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,339 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "site_area tags :" do
|
4
|
+
dataset :users, :home_page
|
5
|
+
|
6
|
+
before do
|
7
|
+
create_page "First" do
|
8
|
+
create_page "First Child"
|
9
|
+
end
|
10
|
+
create_page "Parent" do
|
11
|
+
create_page "Child" do
|
12
|
+
create_page "Grandchild" do
|
13
|
+
create_page "Great Grandchild"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "<r:site_area />" do
|
20
|
+
fixture = [
|
21
|
+
# From page Expectation
|
22
|
+
[:home, 'homepage'],
|
23
|
+
[:parent, 'parent'],
|
24
|
+
[:child, 'parent'],
|
25
|
+
[:grandchild, 'parent'],
|
26
|
+
[:great_grandchild, 'parent'],
|
27
|
+
]
|
28
|
+
fixture.each do |page, expectation|
|
29
|
+
it "should return the top level parent page slug (from #{page})" do
|
30
|
+
page(page).should render("<r:site_area />").as(expectation)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return the content of page part 'site_area' unless it does not exist" do
|
35
|
+
child = page(:child)
|
36
|
+
create_page_part "site_area", :content => "Hello World", :page_id => child.id
|
37
|
+
child.should render("<r:site_area />").as("Hello World")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "<r:site_subarea />" do
|
42
|
+
fixture = [
|
43
|
+
# From page Expectation
|
44
|
+
[:home, ''],
|
45
|
+
[:parent, ''],
|
46
|
+
[:child, 'child'],
|
47
|
+
[:grandchild, 'child'],
|
48
|
+
[:great_grandchild, 'child'],
|
49
|
+
]
|
50
|
+
fixture.each do |page, expectation|
|
51
|
+
it "should return the second level parent page slug (from #{page})" do
|
52
|
+
page(page).should render("<r:site_subarea />").as(expectation)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return the content of page part 'site_subarea' unless it does not exist" do
|
57
|
+
child = page(:child)
|
58
|
+
create_page_part "site_subarea", :content => "Hello World", :page_id => child.id
|
59
|
+
child.should render("<r:site_subarea />").as("Hello World")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '<r:current_if_same_site_area />' do
|
64
|
+
fixture = [
|
65
|
+
# From page Found page path Expectation
|
66
|
+
[:parent, "/", ''],
|
67
|
+
[:parent, "/parent", 'current'],
|
68
|
+
[:parent, "/parent/child", 'current'],
|
69
|
+
[:parent, "/parent/child/grandchild", 'current'],
|
70
|
+
|
71
|
+
[:child, "/", ''],
|
72
|
+
[:child, "/parent", 'current'],
|
73
|
+
[:child, "/parent/child", 'current'],
|
74
|
+
[:child, "/parent/child/grandchild", 'current'],
|
75
|
+
|
76
|
+
[:grandchild, "/", ''],
|
77
|
+
[:grandchild, "/parent", 'current'],
|
78
|
+
[:grandchild, "/parent/child", 'current'],
|
79
|
+
[:grandchild, "/parent/child/grandchild", 'current'],
|
80
|
+
|
81
|
+
[:home, "/parent/child", ''],
|
82
|
+
|
83
|
+
[:first, "/parent", ''],
|
84
|
+
[:first_child,"/parent/child/grandchild", ''],
|
85
|
+
]
|
86
|
+
fixture.each do |page, path, expectation|
|
87
|
+
it "should return 'current' if the local page context is in the same site_area as the global page context (from #{page})" do
|
88
|
+
page(page).should render("<r:find url='#{path}'><r:current_if_same_site_area /></r:find>").as(expectation)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "<r:if_same_site_area />" do
|
95
|
+
fixture = [
|
96
|
+
# From page Found page path Expectation
|
97
|
+
[:parent, "/", ''],
|
98
|
+
[:parent, "/parent", 'yes'],
|
99
|
+
[:parent, "/parent/child", 'yes'],
|
100
|
+
[:parent, "/parent/child/grandchild", 'yes'],
|
101
|
+
|
102
|
+
[:child, "/", ''],
|
103
|
+
[:child, "/parent", 'yes'],
|
104
|
+
[:child, "/parent/child", 'yes'],
|
105
|
+
[:child, "/parent/child/grandchild", 'yes'],
|
106
|
+
|
107
|
+
[:grandchild, "/", ''],
|
108
|
+
[:grandchild, "/parent", 'yes'],
|
109
|
+
[:grandchild, "/parent/child", 'yes'],
|
110
|
+
[:grandchild, "/parent/child/grandchild", 'yes'],
|
111
|
+
|
112
|
+
[:home, "/parent/child", ''],
|
113
|
+
|
114
|
+
[:first, "/parent", ''],
|
115
|
+
[:first_child,"/parent/child/grandchild", ''],
|
116
|
+
]
|
117
|
+
fixture.each do |page, path, expectation|
|
118
|
+
it "should render contained text if the local page context is in the same site_area as the global page context (from #{page})" do
|
119
|
+
page(page).should render("<r:find url='#{path}'><r:if_same_site_area>yes</r:if_same_site_area></r:find>").as(expectation)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "<r:unless_same_site_area />" do
|
125
|
+
fixture = [
|
126
|
+
# From page Found page path Expectation
|
127
|
+
[:parent, "/", 'no'],
|
128
|
+
[:parent, "/parent", ''],
|
129
|
+
[:parent, "/parent/child", ''],
|
130
|
+
[:parent, "/parent/child/grandchild", ''],
|
131
|
+
|
132
|
+
[:child, "/", 'no'],
|
133
|
+
[:child, "/parent", ''],
|
134
|
+
[:child, "/parent/child", ''],
|
135
|
+
[:child, "/parent/child/grandchild", ''],
|
136
|
+
|
137
|
+
[:grandchild, "/", 'no'],
|
138
|
+
[:grandchild, "/parent", ''],
|
139
|
+
[:grandchild, "/parent/child", ''],
|
140
|
+
[:grandchild, "/parent/child/grandchild", ''],
|
141
|
+
|
142
|
+
[:home, "/parent/child", 'no'],
|
143
|
+
|
144
|
+
[:first, "/parent", 'no'],
|
145
|
+
[:first_child,"/parent/child/grandchild", 'no'],
|
146
|
+
]
|
147
|
+
fixture.each do |page, path, expectation|
|
148
|
+
it "should render contained text unless the local page context is in the same site_area as the global page context (from #{page})" do
|
149
|
+
page(page).should render("<r:find url='#{path}'><r:unless_same_site_area>no</r:unless_same_site_area></r:find>").as(expectation)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "<r:current_if_same_site_subarea />" do
|
155
|
+
fixture = [
|
156
|
+
# From page Found page path Expectation
|
157
|
+
[:parent, "/", ''],
|
158
|
+
[:parent, "/parent", ''],
|
159
|
+
[:parent, "/parent/child", ''],
|
160
|
+
[:parent, "/parent/child/grandchild", ''],
|
161
|
+
|
162
|
+
[:child, "/", ''],
|
163
|
+
[:child, "/parent", ''],
|
164
|
+
[:child, "/parent/child", 'current'],
|
165
|
+
[:child, "/parent/child/grandchild", 'current'],
|
166
|
+
|
167
|
+
[:grandchild, "/", ''],
|
168
|
+
[:grandchild, "/parent", ''],
|
169
|
+
[:grandchild, "/parent/child", 'current'],
|
170
|
+
[:grandchild, "/parent/child/grandchild", 'current'],
|
171
|
+
|
172
|
+
[:home, "/parent/child", ''],
|
173
|
+
|
174
|
+
[:first, "/parent", ''],
|
175
|
+
[:first_child,"/parent/child/grandchild", ''],
|
176
|
+
]
|
177
|
+
fixture.each do |page, path, expectation|
|
178
|
+
it "should return 'current' if the local page context is in the same site_subarea as the global page context (from #{page})" do
|
179
|
+
page(page).should render("<r:find url='#{path}'><r:current_if_same_site_subarea /></r:find>").as(expectation)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "<r:current_if_same_site_subarea />" do
|
185
|
+
fixture = [
|
186
|
+
# From page Found page path Expectation
|
187
|
+
[:parent, "/", ''],
|
188
|
+
[:parent, "/parent", ''],
|
189
|
+
[:parent, "/parent/child", ''],
|
190
|
+
[:parent, "/parent/child/grandchild", ''],
|
191
|
+
|
192
|
+
[:child, "/", ''],
|
193
|
+
[:child, "/parent", ''],
|
194
|
+
[:child, "/parent/child", 'current'],
|
195
|
+
[:child, "/parent/child/grandchild", 'current'],
|
196
|
+
|
197
|
+
[:grandchild, "/", ''],
|
198
|
+
[:grandchild, "/parent", ''],
|
199
|
+
[:grandchild, "/parent/child", 'current'],
|
200
|
+
[:grandchild, "/parent/child/grandchild", 'current'],
|
201
|
+
|
202
|
+
[:home, "/parent/child", ''],
|
203
|
+
|
204
|
+
[:first, "/parent", ''],
|
205
|
+
[:first_child,"/parent/child/grandchild", ''],
|
206
|
+
]
|
207
|
+
fixture.each do |page, path, expectation|
|
208
|
+
it "should render 'current' if the local page context is in the same site_subarea as the global page context (from #{page})" do
|
209
|
+
page(page).should render("<r:find url='#{path}'><r:current_if_same_site_subarea /></r:find>").as(expectation)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "<r:if_same_site_subarea />" do
|
215
|
+
fixture = [
|
216
|
+
# From page Found page path Expectation
|
217
|
+
[:parent, "/", ''],
|
218
|
+
[:parent, "/parent", ''],
|
219
|
+
[:parent, "/parent/child", ''],
|
220
|
+
[:parent, "/parent/child/grandchild", ''],
|
221
|
+
|
222
|
+
[:child, "/", ''],
|
223
|
+
[:child, "/parent", ''],
|
224
|
+
[:child, "/parent/child", 'yes'],
|
225
|
+
[:child, "/parent/child/grandchild", 'yes'],
|
226
|
+
|
227
|
+
[:grandchild, "/", ''],
|
228
|
+
[:grandchild, "/parent", ''],
|
229
|
+
[:grandchild, "/parent/child", 'yes'],
|
230
|
+
[:grandchild, "/parent/child/grandchild", 'yes'],
|
231
|
+
|
232
|
+
[:home, "/parent/child", ''],
|
233
|
+
|
234
|
+
[:first, "/parent", ''],
|
235
|
+
[:first_child,"/parent/child/grandchild", ''],
|
236
|
+
]
|
237
|
+
fixture.each do |page, path, expectation|
|
238
|
+
it "should render contained elements if the local page context is in the same site_subarea as the global page context (from #{page})" do
|
239
|
+
page(page).should render("<r:find url='#{path}'><r:if_same_site_subarea>yes</r:if_same_site_subarea></r:find>").as(expectation)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "<r:unless_same_site_subarea />" do
|
245
|
+
fixture = [
|
246
|
+
# From page Found page path Expectation
|
247
|
+
[:parent, "/", 'no'],
|
248
|
+
[:parent, "/parent", 'no'],
|
249
|
+
[:parent, "/parent/child", 'no'],
|
250
|
+
[:parent, "/parent/child/grandchild", 'no'],
|
251
|
+
|
252
|
+
[:child, "/", 'no'],
|
253
|
+
[:child, "/parent", 'no'],
|
254
|
+
[:child, "/parent/child", ''],
|
255
|
+
[:child, "/parent/child/grandchild", ''],
|
256
|
+
|
257
|
+
[:grandchild, "/", 'no'],
|
258
|
+
[:grandchild, "/parent", 'no'],
|
259
|
+
[:grandchild, "/parent/child", ''],
|
260
|
+
[:grandchild, "/parent/child/grandchild", ''],
|
261
|
+
|
262
|
+
[:home, "/parent/child", 'no'],
|
263
|
+
|
264
|
+
[:first, "/parent", 'no'],
|
265
|
+
[:first_child,"/parent/child/grandchild", 'no'],
|
266
|
+
]
|
267
|
+
fixture.each do |page, path, expectation|
|
268
|
+
it "should render contained elements unless the local page context is in the same site_subarea as the global page context (from #{page})" do
|
269
|
+
page(page).should render("<r:find url='#{path}'><r:unless_same_site_subarea>no</r:unless_same_site_subarea></r:find>").as(expectation)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "<r:current_if_same_page />" do
|
275
|
+
fixture = [
|
276
|
+
# From page Found page path Expectation
|
277
|
+
[:parent, "/", ''],
|
278
|
+
[:parent, "/parent", 'current'],
|
279
|
+
[:parent, "/parent/child", ''],
|
280
|
+
[:parent, "/parent/child/grandchild", ''],
|
281
|
+
|
282
|
+
[:child, "/", ''],
|
283
|
+
[:child, "/parent", ''],
|
284
|
+
[:child, "/parent/child", 'current'],
|
285
|
+
[:child, "/parent/child/grandchild", ''],
|
286
|
+
|
287
|
+
[:grandchild, "/", ''],
|
288
|
+
[:grandchild, "/parent", ''],
|
289
|
+
[:grandchild, "/parent/child", ''],
|
290
|
+
[:grandchild, "/parent/child/grandchild", 'current'],
|
291
|
+
|
292
|
+
[:home, "/", 'current'],
|
293
|
+
[:home, "/parent/child", ''],
|
294
|
+
|
295
|
+
[:first, "/parent", ''],
|
296
|
+
[:first_child,"/parent/child/grandchild", ''],
|
297
|
+
]
|
298
|
+
fixture.each do |page, path, expectation|
|
299
|
+
it "should return 'current' if the local page context is in the same as the global page context (from #{page})" do
|
300
|
+
page(page).should render("<r:find url='#{path}'><r:current_if_same_page /></r:find>").as(expectation)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "<r:link_with_current>" do
|
306
|
+
fixture = [
|
307
|
+
# From page href Link text Expectation
|
308
|
+
[:parent, "/", "Home", '<a href="/">Home</a>'],
|
309
|
+
[:parent, "/parent", "Parent", '<a href="/parent" class="current">Parent</a>'],
|
310
|
+
[:parent, "/parent/child", "Child", '<a href="/parent/child">Child</a>'],
|
311
|
+
[:parent, "/parent/child/grandchild", "GrandChild", '<a href="/parent/child/grandchild">GrandChild</a>'],
|
312
|
+
|
313
|
+
[:child, "/", "Home", '<a href="/">Home</a>'],
|
314
|
+
[:child, "/parent", "Parent", '<a href="/parent">Parent</a>'],
|
315
|
+
[:child, "/parent/child", "Child", '<a href="/parent/child" class="current">Child</a>'],
|
316
|
+
[:child, "/parent/child/grandchild", "GrandChild", '<a href="/parent/child/grandchild">GrandChild</a>'],
|
317
|
+
|
318
|
+
[:grandchild, "/", "Home", '<a href="/">Home</a>'],
|
319
|
+
[:grandchild, "/parent", "Parent", '<a href="/parent">Parent</a>'],
|
320
|
+
[:grandchild, "/parent/child", "Child", '<a href="/parent/child">Child</a>'],
|
321
|
+
[:grandchild, "/parent/child/grandchild", "GrandChild", '<a href="/parent/child/grandchild" class="current">GrandChild</a>'],
|
322
|
+
|
323
|
+
[:home, "/", "Home", '<a href="/" class="current">Home</a>'],
|
324
|
+
[:home, "/first", "First", '<a href="/first">First</a>'],
|
325
|
+
|
326
|
+
[:first, "/parent", "Parent", '<a href="/parent">Parent</a>'],
|
327
|
+
[:first_child,"/parent/child/grandchild", "GrandChild", '<a href="/parent/child/grandchild">GrandChild</a>'],
|
328
|
+
]
|
329
|
+
fixture.each do |page, path, link_text, expectation|
|
330
|
+
it "should render a simple link and add class='current' if it's a link to the current page (from #{page})" do
|
331
|
+
page(page).should render("<r:link_with_current href='#{path}'>#{link_text}</r:link_with_current>").as(expectation)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should render a simple link to the current page and add class='current' if attribute 'href' is not provided" do
|
336
|
+
page(:parent).should render("<r:link_with_current >Parent</r:link_with_current>").as('<a href="/parent/" class="current">Parent</a>')
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
|
20
|
+
include ApplicationHelper
|
21
|
+
|
22
|
+
module RadiantSpecHelpers
|
23
|
+
def page(symbol = nil)
|
24
|
+
@page = pages(symbol)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Runner.configure do |config|
|
29
|
+
config.use_transactional_fixtures = true
|
30
|
+
# config.use_instantiated_fixtures = false
|
31
|
+
config.fixture_path = RAILS_ROOT + '/vendor/extensions/trike_tags/spec/fixtures/'
|
32
|
+
config.include RadiantSpecHelpers
|
33
|
+
# You can declare fixtures for each behaviour like this:
|
34
|
+
# describe "...." do
|
35
|
+
# fixtures :table_a, :table_b
|
36
|
+
#
|
37
|
+
# Alternatively, if you prefer to declare them only once, you can
|
38
|
+
# do so here, like so ...
|
39
|
+
#
|
40
|
+
# config.global_fixtures = :table_a, :table_b
|
41
|
+
#
|
42
|
+
# If you declare global fixtures, be aware that they will be declared
|
43
|
+
# for all of your examples, even those that don't use them.
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-site_area_tags-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Benny Degezelle
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-01 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Makes Radiant better by adding site_area_tags!
|
23
|
+
email:
|
24
|
+
- benny@gorilla-webdesign.be
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- app/models/site_area_tags.rb
|
35
|
+
- lib/radiant-site_area_tags-extension.rb
|
36
|
+
- lib/radiant-site_area_tags-extension/version.rb
|
37
|
+
- lib/tasks/site_area_tags_extension_tasks.rake
|
38
|
+
- radiant-site_area_tags-extension.gemspec
|
39
|
+
- site_area_tags_extension.rb
|
40
|
+
- spec/models/site_area_tags_spec.rb
|
41
|
+
- spec/spec.opts
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/jomz/radiant-site_area_tags-extension
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-site_area_tags-extension', :version => '1.0.0'\n "
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Site Area Tags for Radiant CMS
|
77
|
+
test_files:
|
78
|
+
- spec/models/site_area_tags_spec.rb
|
79
|
+
- spec/spec.opts
|
80
|
+
- spec/spec_helper.rb
|