radiant-if_param_tags-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # If Param Tags
2
+
3
+ Adds 3 new Radius tags intended to make small hacks a bit easier;
4
+
5
+ ## <r:if/unless param />
6
+
7
+ Expands only if the param specified in 'name' is present.
8
+ If the additional 'matches' attribute is given, the param must match that to expand.
9
+
10
+ <r:if_param name="foo" [matches="on"]>Foo: <r:param name="foo" /></r:if_param>
11
+
12
+ ## &lt;r:param />
13
+
14
+ Renders the param if found.
15
+
16
+ <r:param name="foo" />
data/Rakefile ADDED
@@ -0,0 +1,109 @@
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, :features]
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 if_param_tags extension.'
100
+ Rake::RDocTask.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'IfParamTagsExtension'
103
+ rdoc.options << '--line-numbers' << '--inline-source'
104
+ rdoc.rdoc_files.include('README')
105
+ rdoc.rdoc_files.include('lib/**/*.rb')
106
+ end
107
+
108
+ # Load any custom rakefiles for extension
109
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,10 @@
1
+ require 'radiant-if_param_tags-extension'
2
+ class IfParamTagsExtension < Radiant::Extension
3
+ version RadiantIfParamTagsExtension::VERSION
4
+ description RadiantIfParamTagsExtension::DESCRIPTION
5
+ url RadiantIfParamTagsExtension::URL
6
+
7
+ def activate
8
+ Page.send :include, IfParamTags
9
+ end
10
+ end
@@ -0,0 +1,52 @@
1
+ module IfParamTags
2
+ include Radiant::Taggable
3
+
4
+ class TagError < StandardError; end
5
+
6
+ desc %{
7
+ Expands only if the param specified in 'name' is present.
8
+ If the additional 'matches' attribute is given, the param must match that to expand.
9
+
10
+ *Usage:*
11
+ <pre><code><r:if_param name="foo" [matches="on"]>Foo: <r:param name="foo" /></r:if_param></code></pre>
12
+ }
13
+ tag "if_param" do |tag|
14
+ name = tag.attr["name"]
15
+ raise TagError "A name attribute must be specified for if_param!" if name.blank?
16
+ if params[name]
17
+ regexp = build_regexp_for(tag, "matches") if tag.attr["matches"]
18
+ tag.expand if ( tag.attr["matches"].nil? || params[name].matches(regexp) )
19
+ end
20
+ end
21
+
22
+ desc %{
23
+ The exact opposite of r:if_param.
24
+ Expands only if the param specified in 'name' is present.
25
+ If the additional 'matches' attribute is given, the param must match that to expand.
26
+
27
+ *Usage:*
28
+ <pre><code><r:unless_param name="foo" [matches="on"]>Foo: <r:param name="foo" /></r:unless_param></code></pre>
29
+ }
30
+ tag "unless_param" do |tag|
31
+ name = tag.attr["name"]
32
+ raise TagError "A name attribute must be specified for unless_param!" if name.blank?
33
+ if params[name]
34
+ regexp = build_regexp_for(tag, "matches") if tag.attr["matches"]
35
+ tag.expand unless ( tag.attr["matches"].nil? || params[name].matches(regexp) )
36
+ else
37
+ tag.expand
38
+ end
39
+ end
40
+
41
+ desc %{
42
+ Renders the specified param
43
+
44
+ *Usage:*
45
+ <pre><code><r:param name="foo" /></code></pre>
46
+ }
47
+ tag "param" do |tag|
48
+ name = tag.attr["name"]
49
+ raise TagError "A name attribute must be specified for param!" if name.blank?
50
+ params[name]
51
+ end
52
+ end
@@ -0,0 +1,8 @@
1
+ module RadiantIfParamTagsExtension
2
+ VERSION = '1.0.0'
3
+ SUMMARY = "If_param tags for Radiant CMS"
4
+ DESCRIPTION = "Adds two Radius tags that help you in responding to params."
5
+ URL = "http://github.com/jomz/radiant-if_param_tags-extension"
6
+ AUTHORS = ["Benny Degezelle"]
7
+ EMAIL = ["hi@monkeypatch.be"]
8
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-if_param_tags-extension"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-if_param_tags-extension"
7
+ s.version = RadiantIfParamTagsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benny Degezelle"]
10
+ s.email = ["hi@monkeypatch.be"]
11
+ s.homepage = RadiantIfParamTagsExtension::URL
12
+ s.summary = RadiantIfParamTagsExtension::SUMMARY
13
+ s.description = RadiantIfParamTagsExtension::DESCRIPTION
14
+
15
+ ignores = if File.exist?('.gitignore')
16
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir['**/*'] - ignores
21
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
22
+ # s.executables = Dir['bin/*'] - ignores
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-if_param_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-09-20 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Adds two Radius tags that help you in responding to params.
23
+ email:
24
+ - hi@monkeypatch.be
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - cucumber.yml
33
+ - if_param_tags_extension.rb
34
+ - lib/if_param_tags.rb
35
+ - lib/radiant-if_param_tags-extension.rb
36
+ - radiant-if_param_tags-extension.gemspec
37
+ - Rakefile
38
+ - README.md
39
+ has_rdoc: true
40
+ homepage: http://github.com/jomz/radiant-if_param_tags-extension
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: If_param tags for Radiant CMS
73
+ test_files: []
74
+