radiant-if_date_tags-extension 1.0.0

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.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # If Date Tags
2
+
3
+ This Radiant CMS extension introduces four new radius tags that compare specified-on-tag and derived-from-page dates to expand or not expand depending on the outcome.
4
+
5
+ Examples:
6
+
7
+ Consider these tags implemented on a page with a published_at date of April 2nd, 2017.
8
+
9
+ <r:if_date_earlier than="January 1 2017">Will not render because page.published_at is later</r:if_date_earlier>
10
+ <r:if_date_earlier date="published_at" than="April 2 2017">Will not render because published_at is not earlier</r:if_date_earlier>
11
+ <r:if_date_earlier date="published_at" than="April 2 2017" or_equal="true">Will render because published_at is equal</r:if_date_earlier>
12
+ <r:unless_date_earlier than="April 2 2017">Will not render because published_at is not earlier</r:unless_date_earlier>
13
+ <r:unless_date_earlier date="published_at" than="April 2 2017" or_equal="true">Will render because published_at is equal</r:unless_date_earlier>
14
+
15
+ <r:if_date_later than="January 1 2017">Will render because implied published_at is later</r:if_date_later>
16
+ <r:if_date_later date="published_at" than="March 10 2017">Will not render because published_at is not later</r:if_date_later>
17
+ <r:if_date_later date="published_at" than="April 2 2017" or_equal="true">Will render because published_at is equal</r:if_date_later>
18
+ <r:unless_date_later than="January 1 2017">Will not render because implied published_at is later</r:unless_date_later>
19
+ <r:unless_date_later date="published_at" than="January 1 2017">Will not render because published_at is later</r:unless_date_later>
20
+
21
+ Created by Benny Degezelle for nzffa.org.nz
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 'rdoc/task'
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_date_tags extension.'
100
+ RDoc::Task.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'IfDateTagsExtension'
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,11 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ dataset :if_date_tags
11
+ end
@@ -0,0 +1,22 @@
1
+ module NavigationHelpers
2
+
3
+ # Extend the standard PathMatchers with your own paths
4
+ # to be used in your features.
5
+ #
6
+ # The keys and values here may be used in your standard web steps
7
+ # Using:
8
+ #
9
+ # When I go to the "if_date_tags" admin page
10
+ #
11
+ # would direct the request to the path you provide in the value:
12
+ #
13
+ # admin_if_date_tags_path
14
+ #
15
+ PathMatchers = {} unless defined?(PathMatchers)
16
+ PathMatchers.merge!({
17
+ # /if_date_tags/i => 'admin_if_date_tags_path'
18
+ })
19
+
20
+ end
21
+
22
+ World(NavigationHelpers)
@@ -0,0 +1,22 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency "application_controller"
3
+ require "radiant-if_date_tags-extension"
4
+
5
+ class IfDateTagsExtension < Radiant::Extension
6
+ version RadiantIfDateTagsExtension::VERSION
7
+ description RadiantIfDateTagsExtension::DESCRIPTION
8
+ url RadiantIfDateTagsExtension::URL
9
+
10
+ # See your config/routes.rb file in this extension to define custom routes
11
+
12
+ extension_config do |config|
13
+ # config is the Radiant.configuration object
14
+ end
15
+
16
+ def activate
17
+ Page.send :include, IfDateTags::TagExtensions
18
+ # tab 'Content' do
19
+ # add_item "If Date Tags", "/admin/if_date_tags", :after => "Pages"
20
+ # end
21
+ end
22
+ end
@@ -0,0 +1,65 @@
1
+ module IfDateTags::TagExtensions
2
+ include Radiant::Taggable
3
+ class TagError < StandardError; end
4
+
5
+ desc %{
6
+ Expands only if the date field specified in the @date@ attribute is earlier than the date specified in the @than@ attribute.
7
+
8
+ If no @date@ attribute is passed, the current page's published_at or created_at will be used.
9
+ *Usage:*
10
+
11
+ <pre><code><r:if_date_earlier [date="published_at | created_at | updated_at"] than="August 1 2017" [or_equal="true"]>...</r:if_date_earlier></code></pre>
12
+
13
+ An r:unless_date_earlier tag with the same attributes is also available
14
+ }
15
+ tag 'if_date_earlier' do |tag|
16
+ than, date = than_and_date_from_attrs(tag)
17
+ condition = tag.attr['or_equal'] ? "<=" : "<"
18
+ tag.expand if eval("#{date} #{condition} #{than}")
19
+ end
20
+ tag 'unless_date_earlier' do |tag|
21
+ than, date = than_and_date_from_attrs(tag)
22
+ condition = tag.attr['or_equal'] ? "<=" : "<"
23
+ tag.expand unless eval("#{date} #{condition} #{than}")
24
+ end
25
+
26
+ desc %{
27
+ Expands only if the date field specified in the @date@ attribute is earlier than the date specified in the @than@ attribute.
28
+
29
+ If no @date@ attribute is passed, the current page's published_at or created_at will be used.
30
+ *Usage:*
31
+
32
+ <pre><code><r:if_date_later [date="published_at | created_at | updated_at"] than="August 1 2017" [or_equal="true"]>...</r:if_date_later></code></pre>
33
+
34
+ An r:unless_date_later tag with the same attributes is also available
35
+ }
36
+ tag 'if_date_later' do |tag|
37
+ than, date = than_and_date_from_attrs(tag)
38
+ condition = tag.attr['or_equal'] ? ">=" : ">"
39
+ tag.expand if eval("#{date} #{condition} #{than}")
40
+ end
41
+ tag 'unless_date_later' do |tag|
42
+ than, date = than_and_date_from_attrs(tag)
43
+ condition = tag.attr['or_equal'] ? ">=" : ">"
44
+ tag.expand unless eval("#{date} #{condition} #{than}")
45
+ end
46
+
47
+ def than_and_date_from_attrs(tag)
48
+ raise TagError.new("`#{tag.name}' tag must contain a than attribute.") unless tag.attr['than']
49
+ than = tag.attr.delete('than')
50
+ date_attr = tag.attr['date']
51
+ date = if date_attr
52
+ case
53
+ when Page.date_column_names.include?(date_attr)
54
+ tag.locals.page[date_attr].to_date
55
+ else
56
+ raise TagError, "Invalid value for 'date' attribute."
57
+ end
58
+ else
59
+ tag.locals.page.published_at.to_date || tag.locals.page.created_at.to_date
60
+ end
61
+
62
+ than = DateTime.parse(than)
63
+ return [ than.to_date, date.to_date ]
64
+ end
65
+ end
@@ -0,0 +1,8 @@
1
+ module RadiantIfDateTagsExtension
2
+ VERSION = "1.0.0"
3
+ SUMMARY = "If Date Tags for Radiant CMS"
4
+ DESCRIPTION = "Makes Radiant better by adding if_date radius tags"
5
+ URL = "http://github.com/jomz/radiant-if_date_tags-extension"
6
+ AUTHORS = ["Benny Degezelle"]
7
+ EMAIL = ["hi@monkeypatch.be"]
8
+ end
@@ -0,0 +1,47 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :if_date_tags do
4
+
5
+ desc "Runs the migration of the If Date Tags extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ IfDateTagsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ IfDateTagsExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the If Date 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 IfDateTagsExtension"
21
+ Dir[IfDateTagsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(IfDateTagsExtension.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
+ end
28
+
29
+ desc "Syncs all available translations for this ext to the English ext master"
30
+ task :sync => :environment do
31
+ # The main translation root, basically where English is kept
32
+ language_root = IfDateTagsExtension.root + "/config/locales"
33
+ words = TranslationSupport.get_translation_keys(language_root)
34
+
35
+ Dir["#{language_root}/*.yml"].each do |filename|
36
+ next if filename.match('_available_tags')
37
+ basename = File.basename(filename, '.yml')
38
+ puts "Syncing #{basename}"
39
+ (comments, other) = TranslationSupport.read_file(filename, basename)
40
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
41
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
42
+ TranslationSupport.write_file(filename, basename, comments, other)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-if_date_tags-extension"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-if_date_tags-extension"
7
+ s.version = RadiantIfDateTagsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = RadiantIfDateTagsExtension::AUTHORS
10
+ s.email = RadiantIfDateTagsExtension::EMAIL
11
+ s.homepage = RadiantIfDateTagsExtension::URL
12
+ s.summary = RadiantIfDateTagsExtension::SUMMARY
13
+ s.description = RadiantIfDateTagsExtension::DESCRIPTION
14
+
15
+ # Define gem dependencies here.
16
+ # Don't include a dependency on radiant itself: it causes problems when radiant is in vendor/radiant.
17
+ # s.add_dependency "something", "~> 1.0.0"
18
+ # s.add_dependency "radiant-some-extension", "~> 1.0.0"
19
+
20
+ ignores = if File.exist?('.gitignore')
21
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
22
+ else
23
+ []
24
+ end
25
+ s.files = Dir['**/*'] - ignores
26
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
27
+ # s.executables = Dir['bin/*'] - ignores
28
+ s.require_paths = ["lib"]
29
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,42 @@
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
+ # Include any datasets from loaded extensions
16
+ Radiant::Extension.descendants.each do |extension|
17
+ if File.directory?(extension.root + "/spec/datasets")
18
+ Dataset::Resolver.default << (extension.root + "/spec/datasets")
19
+ end
20
+ end
21
+
22
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
23
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
24
+ end
25
+
26
+ Spec::Runner.configure do |config|
27
+ # config.use_transactional_fixtures = true
28
+ # config.use_instantiated_fixtures = false
29
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
30
+
31
+ # You can declare fixtures for each behaviour like this:
32
+ # describe "...." do
33
+ # fixtures :table_a, :table_b
34
+ #
35
+ # Alternatively, if you prefer to declare them only once, you can
36
+ # do so here, like so ...
37
+ #
38
+ # config.global_fixtures = :table_a, :table_b
39
+ #
40
+ # If you declare global fixtures, be aware that they will be declared
41
+ # for all of your examples, even those that don't use them.
42
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-if_date_tags-extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Benny Degezelle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-07-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Makes Radiant better by adding if_date radius tags
15
+ email:
16
+ - hi@monkeypatch.be
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - cucumber.yml
22
+ - features/support/env.rb
23
+ - features/support/paths.rb
24
+ - if_date_tags_extension.rb
25
+ - lib/if_date_tags/tag_extensions.rb
26
+ - lib/radiant-if_date_tags-extension.rb
27
+ - lib/tasks/if_date_tags_extension_tasks.rake
28
+ - radiant-if_date_tags-extension.gemspec
29
+ - Rakefile
30
+ - README.md
31
+ - spec/spec.opts
32
+ - spec/spec_helper.rb
33
+ homepage: http://github.com/jomz/radiant-if_date_tags-extension
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.23.2
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: If Date Tags for Radiant CMS
57
+ test_files:
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ - features/support/env.rb
61
+ - features/support/paths.rb
62
+ has_rdoc: