trusty-snippets-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.md +7 -0
  2. data/Rakefile +109 -0
  3. data/app/controllers/admin/snippets_controller.rb +8 -0
  4. data/app/helpers/admin/snippets_helper.rb +3 -0
  5. data/app/models/snippet.rb +23 -0
  6. data/app/models/snippet_finder.rb +24 -0
  7. data/app/models/snippet_tags.rb +80 -0
  8. data/app/views/admin/snippets/_form.html.haml +29 -0
  9. data/app/views/admin/snippets/_popups.html.haml +4 -0
  10. data/app/views/admin/snippets/edit.html.haml +11 -0
  11. data/app/views/admin/snippets/index.html.haml +33 -0
  12. data/app/views/admin/snippets/new.html.haml +9 -0
  13. data/app/views/admin/snippets/remove.html.haml +17 -0
  14. data/config/initializers/radiant_config.rb +3 -0
  15. data/config/locales/en.yml +16 -0
  16. data/config/routes.rb +8 -0
  17. data/cucumber.yml +1 -0
  18. data/features/admin/configuration.feature +9 -0
  19. data/features/admin/pagination.feature +27 -0
  20. data/features/admin/snippets_management.feature +82 -0
  21. data/features/step_definitions/admin/snippet_steps.rb +25 -0
  22. data/features/support/env.rb +11 -0
  23. data/features/support/paths.rb +22 -0
  24. data/lib/snippets/engine.rb +5 -0
  25. data/lib/tasks/snippets_extension_tasks.rake +47 -0
  26. data/lib/trusty-snippets-extension.rb +8 -0
  27. data/snippets_extension.rb +69 -0
  28. data/spec/ci/before_script +22 -0
  29. data/spec/ci/script +2 -0
  30. data/spec/controllers/admin/snippets_controller_spec.rb +110 -0
  31. data/spec/datasets/snippets_dataset.rb +44 -0
  32. data/spec/fixtures/snippet_template.radius +1 -0
  33. data/spec/lib/radiant/admin_ui_spec.rb +33 -0
  34. data/spec/models/page_spec.rb +81 -0
  35. data/spec/models/snippet_finder_spec.rb +20 -0
  36. data/spec/models/snippet_spec.rb +59 -0
  37. data/spec/models/user_action_observer_spec.rb +25 -0
  38. data/spec/snippets_spec_helper.rb +36 -0
  39. data/spec/spec.opts +6 -0
  40. data/trusty-snippets-extension.gemspec +26 -0
  41. metadata +120 -0
@@ -0,0 +1 @@
1
+ <h1>Hello</h1>
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../snippets_spec_helper.rb')
2
+
3
+ describe Radiant::AdminUI do
4
+ let(:admin) do
5
+ @admin = Radiant::AdminUI.new
6
+ @admin.snippet = @admin.load_default_snippet_regions
7
+ @admin
8
+ end
9
+
10
+ subject{ admin }
11
+ its(:snippet){ should_not be_nil }
12
+ its(:snippets){ should_not be_nil }
13
+
14
+ context 'edit Region' do
15
+ subject{ admin.snippet.edit }
16
+ its(:main){ should == %w{ edit_header edit_form } }
17
+ its(:form){ should == %w{ edit_title edit_content edit_filter } }
18
+ its(:form_bottom){ should == %w{ edit_buttons edit_timestamp } }
19
+ end
20
+
21
+ context 'new Region' do
22
+ subject{ admin.snippet.new }
23
+ its(:main){ should == %w{ edit_header edit_form } }
24
+ its(:form){ should == %w{ edit_title edit_content edit_filter } }
25
+ its(:form_bottom){ should == %w{ edit_buttons edit_timestamp } }
26
+ end
27
+
28
+ subject{ admin.snippet.index }
29
+ its(:top){ should == [] }
30
+ its(:thead){ should == %w{ title_header actions_header } }
31
+ its(:tbody){ should == %w{ title_cell actions_cell } }
32
+ its(:bottom){ should == %w{ new_button } }
33
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../snippets_spec_helper.rb')
2
+
3
+ describe "Page rendering snippets" do
4
+ dataset :pages, :snippets
5
+
6
+ test_helper :render
7
+
8
+ let(:page){ pages(:home) }
9
+
10
+ it 'should render a snippet' do
11
+ page.render_snippet(snippets(:first)).should == 'test'
12
+ end
13
+
14
+ it 'should render a snippet with a filter' do
15
+ page.render_snippet(snippets(:markdown)).should include(%{**markdown** for Snippets!})
16
+ end
17
+
18
+ it 'should render a snippet with a tag' do
19
+ page.render_snippet(snippets(:radius)).should == 'Home'
20
+ end
21
+
22
+ describe "<r:snippet>" do
23
+ it "should render the contents of the specified snippet" do
24
+ page.should render('<r:snippet name="first" />').as('test')
25
+ end
26
+
27
+ it "should render an error when the snippet does not exist" do
28
+ page.should render('<r:snippet name="non-existent" />').with_error("snippet not found: non-existent")
29
+ end
30
+
31
+ it "should render an error when not given a 'name' attribute" do
32
+ page.should render('<r:snippet />').with_error("`snippet' tag must contain `name' attribute")
33
+ end
34
+
35
+ it "should filter the snippet with its assigned filter" do
36
+ page.should render('<r:page><r:snippet name="markdown" /></r:page>').matching(Regexp.new(Regexp.quote('**markdown** for Snippets!')))
37
+ end
38
+
39
+ it "should maintain the global page inside the snippet" do
40
+ parent_page = pages(:parent)
41
+ parent_page.should render('<r:snippet name="global_page_cascade" />').as("#{parent_page.title} " * parent_page.children.count)
42
+ end
43
+
44
+ it "should maintain the global page when the snippet renders recursively" do
45
+ pages(:child).should render('<r:snippet name="recursive" />').as("Great GrandchildGrandchildChild")
46
+ end
47
+
48
+ it "should render the specified snippet when called as an empty double-tag" do
49
+ page.should render('<r:snippet name="first"></r:snippet>').as('test')
50
+ end
51
+
52
+ it "should capture contents of a double tag, substituting for <r:yield/> in snippet" do
53
+ page.should render('<r:snippet name="yielding">inner</r:snippet>').
54
+ as('Before...inner...and after')
55
+ end
56
+
57
+ it "should do nothing with contents of double tag when snippet doesn't yield" do
58
+ page.should render('<r:snippet name="first">content disappears!</r:snippet>').
59
+ as('test')
60
+ end
61
+
62
+ it "should render nested yielding snippets" do
63
+ page.should render('<r:snippet name="div_wrap"><r:snippet name="yielding">Hello, World!</r:snippet></r:snippet>').
64
+ as('<div>Before...Hello, World!...and after</div>')
65
+ end
66
+
67
+ it "should render double-tag snippets called from within a snippet" do
68
+ page.should render('<r:snippet name="nested_yields">the content</r:snippet>').
69
+ as('<snippet name="div_wrap">above the content below</snippet>')
70
+ end
71
+
72
+ it "should render contents each time yield is called" do
73
+ page.should render('<r:snippet name="yielding_often">French</r:snippet>').
74
+ as('French is Frencher than French')
75
+ end
76
+ end
77
+
78
+ it "should do nothing when called from page body" do
79
+ page.should render('<r:yield/>').as("")
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../snippets_spec_helper.rb')
2
+
3
+ class TestSnippetFinder; end
4
+ class AlternateSnippetFinder; end
5
+
6
+ describe 'SnippetFinder' do
7
+ it 'finds a snippet by name in the first finder type' do
8
+ SnippetFinder.stub!(:finder_types).and_return([TestSnippetFinder, AlternateSnippetFinder])
9
+ TestSnippetFinder.should_receive(:find_by_name).and_return(OpenStruct.new(:name => 'test_snippet'))
10
+
11
+ SnippetFinder.find_by_name('test_snippet')
12
+ end
13
+ it 'finds a snippet by name in the next finder type after no result from the previous' do
14
+ SnippetFinder.stub!(:finder_types).and_return([TestSnippetFinder, AlternateSnippetFinder])
15
+ TestSnippetFinder.stub!(:find_by_name).and_return(nil)
16
+ AlternateSnippetFinder.should_receive(:find_by_name).and_return(OpenStruct.new(:name => 'alternate_snippet'))
17
+
18
+ SnippetFinder.find_by_name('alternate_snippet')
19
+ end
20
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../snippets_spec_helper.rb')
2
+
3
+ describe Snippet do
4
+ dataset :snippets
5
+ test_helper :validations
6
+
7
+ before :each do
8
+ @original_filter = Radiant::Config['defaults.snippet.filter']
9
+ @snippet = @model = Snippet.new(snippet_params)
10
+ end
11
+
12
+ after :each do
13
+ Radiant::Config['defaults.snippet.filter'] = @original_filter
14
+ end
15
+
16
+ it "should take the filter from the default filter" do
17
+ Radiant::Config.should_receive(:[]).with("defaults.snippet.filter").and_return('Textile')
18
+ snippet = Snippet.new :name => 'new-snippet'
19
+ snippet.filter_id.should == "Textile"
20
+ end
21
+
22
+ it "shouldn't override existing snippets filters with the default filter" do
23
+ snippet = Snippet.find(:first, :conditions => {:filter_id => nil})
24
+ Radiant::Config.stub!(:[]).with("defaults.snippet.filter").and_return('Textile')
25
+ snippet.reload
26
+ snippet.filter_id.should_not == "Textile"
27
+ end
28
+
29
+ it 'should validate length of' do
30
+ {
31
+ :name => 100,
32
+ :filter_id => 25
33
+ }.each do |field, max|
34
+ assert_invalid field, ('this must not be longer than %d characters' % max), 'x' * (max + 1)
35
+ assert_valid field, 'x' * max
36
+ end
37
+ end
38
+
39
+ it 'should validate presence of' do
40
+ [:name].each do |field|
41
+ assert_invalid field, 'this must not be blank', '', ' ', nil
42
+ end
43
+ end
44
+
45
+ it 'should validate uniqueness of' do
46
+ assert_invalid :name, 'this name is already in use', 'first', 'another', 'markdown'
47
+ assert_valid :name, 'just-a-test'
48
+ end
49
+
50
+ it 'should validate format of name' do
51
+ assert_valid :name, 'abc', 'abcd-efg', 'abcd_efg', 'abc.html', '/', '123'
52
+ assert_invalid :name, 'cannot contain spaces or tabs'
53
+ end
54
+
55
+ it 'should allow the filter to be specified' do
56
+ @snippet = snippets(:markdown)
57
+ @snippet.filter.should be_kind_of(SnippetMarkdownFilter)
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../snippets_spec_helper.rb')
2
+
3
+ describe UserActionObserver do
4
+ dataset :users, :pages_with_layouts, :snippets
5
+
6
+ before(:each) do
7
+ @user = users(:existing)
8
+ UserActionObserver.current_user = @user
9
+ end
10
+
11
+ it 'should observe create' do
12
+ snippet = Snippet.create!(snippet_params)
13
+ snippet.created_by.should == @user
14
+ end
15
+
16
+ it 'should observe update' do
17
+ [
18
+ snippets(:first)
19
+ ].each do |model|
20
+ model.attributes = model.attributes.dup
21
+ model.save.should == true
22
+ model.updated_by.should == @user
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
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
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ 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,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trusty-snippets-extension"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "trusty-snippets-extension"
7
+ s.version = TrustySnippetsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = TrustySnippetsExtension::AUTHORS
10
+ s.email = TrustySnippetsExtension::EMAIL
11
+ s.homepage = TrustySnippetsExtension::URL
12
+ s.summary = TrustySnippetsExtension::SUMMARY
13
+ s.description = TrustySnippetsExtension::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
+
25
+ s.add_dependency "trusty-cms", "~> 1.0.1"
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trusty-snippets-extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jim Gay
9
+ - Eric Sipple
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-11-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: trusty-cms
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.1
31
+ description: Makes Trusty better by adding snippets!
32
+ email:
33
+ - sipple@trustarts.org
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - app/controllers/admin/snippets_controller.rb
39
+ - app/helpers/admin/snippets_helper.rb
40
+ - app/models/snippet.rb
41
+ - app/models/snippet_finder.rb
42
+ - app/models/snippet_tags.rb
43
+ - app/views/admin/snippets/_form.html.haml
44
+ - app/views/admin/snippets/_popups.html.haml
45
+ - app/views/admin/snippets/edit.html.haml
46
+ - app/views/admin/snippets/index.html.haml
47
+ - app/views/admin/snippets/new.html.haml
48
+ - app/views/admin/snippets/remove.html.haml
49
+ - config/initializers/radiant_config.rb
50
+ - config/locales/en.yml
51
+ - config/routes.rb
52
+ - cucumber.yml
53
+ - features/admin/configuration.feature
54
+ - features/admin/pagination.feature
55
+ - features/admin/snippets_management.feature
56
+ - features/step_definitions/admin/snippet_steps.rb
57
+ - features/support/env.rb
58
+ - features/support/paths.rb
59
+ - lib/snippets/engine.rb
60
+ - lib/tasks/snippets_extension_tasks.rake
61
+ - lib/trusty-snippets-extension.rb
62
+ - Rakefile
63
+ - README.md
64
+ - snippets_extension.rb
65
+ - spec/ci/before_script
66
+ - spec/ci/script
67
+ - spec/controllers/admin/snippets_controller_spec.rb
68
+ - spec/datasets/snippets_dataset.rb
69
+ - spec/fixtures/snippet_template.radius
70
+ - spec/lib/radiant/admin_ui_spec.rb
71
+ - spec/models/page_spec.rb
72
+ - spec/models/snippet_finder_spec.rb
73
+ - spec/models/snippet_spec.rb
74
+ - spec/models/user_action_observer_spec.rb
75
+ - spec/snippets_spec_helper.rb
76
+ - spec/spec.opts
77
+ - trusty-snippets-extension.gemspec
78
+ homepage: http://github.com/pgharts/trusty-snippets-extension
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.29
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Snippets for Trusty CMS
102
+ test_files:
103
+ - spec/ci/before_script
104
+ - spec/ci/script
105
+ - spec/controllers/admin/snippets_controller_spec.rb
106
+ - spec/datasets/snippets_dataset.rb
107
+ - spec/fixtures/snippet_template.radius
108
+ - spec/lib/radiant/admin_ui_spec.rb
109
+ - spec/models/page_spec.rb
110
+ - spec/models/snippet_finder_spec.rb
111
+ - spec/models/snippet_spec.rb
112
+ - spec/models/user_action_observer_spec.rb
113
+ - spec/snippets_spec_helper.rb
114
+ - spec/spec.opts
115
+ - features/admin/configuration.feature
116
+ - features/admin/pagination.feature
117
+ - features/admin/snippets_management.feature
118
+ - features/step_definitions/admin/snippet_steps.rb
119
+ - features/support/env.rb
120
+ - features/support/paths.rb