locomotive_plugins 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ module Locomotive
5
+ describe Plugin do
6
+
7
+ before(:each) do
8
+ @config = {}
9
+ @plugin = MyPlugin.new(@config)
10
+ @useless_plugin = UselessPlugin.new(@config)
11
+ end
12
+
13
+ it 'should call custom initialization methods' do
14
+ @plugin.custom_attribute.should == 'Value'
15
+ end
16
+
17
+ it 'should store a list of before_filters' do
18
+ @plugin.before_filters.count.should == 2
19
+ @plugin.before_filters[0].should == :my_method1
20
+ @plugin.before_filters[1].should == :my_method2
21
+ end
22
+
23
+ it 'should have an empty array of before_filters by default' do
24
+ @useless_plugin.before_filters.should == []
25
+ end
26
+
27
+ it 'should optionally return a liquid drop' do
28
+ @plugin.to_liquid.class.should == MyPlugin::MyDrop
29
+ @useless_plugin.to_liquid.should be_nil
30
+ end
31
+
32
+ it 'should optionally return liquid filters' do
33
+ MyPlugin.liquid_filters.should == MyPlugin::Filters
34
+ UselessPlugin.liquid_filters.should be_nil
35
+ end
36
+
37
+ it 'should optionally return liquid tags' do
38
+ MyPlugin.liquid_tags.should == {}
39
+ PluginWithTags.liquid_tags.should == {
40
+ :paragraph => PluginWithTags::Paragraph,
41
+ :newline => PluginWithTags::Newline
42
+ }
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe LocomotivePlugins do
5
+
6
+ before(:each) do
7
+ LocomotivePlugins.clear_registered_plugins
8
+ end
9
+
10
+ it 'should register plugins under a given id' do
11
+ LocomotivePlugins.register_plugin(Locomotive::MyPlugin, 'my_amazing_plugin')
12
+ registered = LocomotivePlugins.registered_plugins
13
+ registered.count.should == 1
14
+ registered['my_amazing_plugin'].should == Locomotive::MyPlugin
15
+ end
16
+
17
+ it 'should register plugins under the default id' do
18
+ default_id = LocomotivePlugins.default_id(Locomotive::MyPlugin)
19
+ LocomotivePlugins.register_plugin(Locomotive::MyPlugin)
20
+ registered = LocomotivePlugins.registered_plugins
21
+ registered.count.should == 1
22
+ registered[default_id].should == Locomotive::MyPlugin
23
+ end
24
+
25
+ it 'should use the underscorized class name without any modules as the default id' do
26
+ LocomotivePlugins.default_id(Locomotive::MyPlugin).should == 'my_plugin'
27
+ end
28
+
29
+ end
@@ -0,0 +1,47 @@
1
+
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ require 'rspec'
6
+
7
+ require 'factory_girl'
8
+ require 'database_cleaner'
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
12
+
13
+ require 'locomotive_plugins'
14
+
15
+ # Set up mongoid
16
+ Mongoid.configure do |config|
17
+ config.master = Mongo::Connection.new.db('locomotive_plugins_test')
18
+ end
19
+
20
+ # Requires supporting ruby files with custom matchers and macros, etc,
21
+ # in spec/support/ and its subdirectories.
22
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
23
+
24
+ RSpec.configure do |config|
25
+ config.mock_with :mocha
26
+
27
+ # Use color in STDOUT
28
+ config.color_enabled = true
29
+
30
+ config.before(:suite) do
31
+ DatabaseCleaner.strategy = :truncation
32
+ DatabaseCleaner.orm = 'mongoid'
33
+ end
34
+
35
+ config.before(:each) do
36
+ Mongoid::IdentityMap.clear
37
+ end
38
+
39
+ config.before(:each) do
40
+ DatabaseCleaner.clean
41
+ end
42
+
43
+ config.after(:suite) do
44
+ DatabaseCleaner.clean
45
+ end
46
+
47
+ end
@@ -0,0 +1,3 @@
1
+ FactoryGirl.define do
2
+
3
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Locomotive
3
+ class MyOtherPlugin
4
+ include Locomotive::Plugin
5
+
6
+ before_filter :another_method
7
+
8
+ def config_template_file
9
+ File.join(File.dirname(__FILE__), '..', '..', 'fixtures',
10
+ 'config_template.haml')
11
+ end
12
+
13
+ def another_method
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+
2
+ module Locomotive
3
+ class MyPlugin
4
+ include Locomotive::Plugin
5
+
6
+ module Filters
7
+ end
8
+
9
+ class MyDrop < ::Liquid::Drop
10
+ end
11
+
12
+ before_filter :my_method1
13
+ before_filter :my_method2
14
+
15
+ attr_accessor :custom_attribute
16
+
17
+ def initialize_plugin
18
+ self.custom_attribute = 'Value'
19
+ end
20
+
21
+ def to_liquid
22
+ MyDrop.new
23
+ end
24
+
25
+ def config_template_file
26
+ File.join(File.dirname(__FILE__), '..', '..', 'fixtures',
27
+ 'config_template.html')
28
+ end
29
+
30
+ def self.liquid_filters
31
+ Filters
32
+ end
33
+
34
+ def my_method1
35
+ 'This is my first before filter!'
36
+ end
37
+
38
+ def my_method2
39
+ 'This is my second before filter!'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+
2
+ module Locomotive
3
+ class PluginWithDBModel
4
+ include Locomotive::Plugin
5
+
6
+ class VisitCount < Locomotive::Plugin::DBModel
7
+ field :count, default: 0
8
+ end
9
+
10
+ class Item < Locomotive::Plugin::DBModel
11
+ field :name
12
+ validates_presence_of :name
13
+ end
14
+
15
+ has_one :visit_count, VisitCount
16
+ has_many :items, Item
17
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+
2
+ module Locomotive
3
+ class PluginWithFilter
4
+ include Locomotive::Plugin
5
+
6
+ module Filters
7
+ def add_http(input)
8
+ if input.start_with?('http://')
9
+ input
10
+ else
11
+ "http://#{input}"
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.liquid_filters
17
+ Filters
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module Locomotive
3
+ class PluginWithManyFilterModules
4
+ include Locomotive::Plugin
5
+
6
+ module Filters
7
+ def add_newline(input)
8
+ "#{input}\n"
9
+ end
10
+ end
11
+
12
+ module MoreFilters
13
+ def remove_http(input)
14
+ input.sub(%r{^http://}, '')
15
+ end
16
+ end
17
+
18
+ def self.liquid_filters
19
+ [ Filters, MoreFilters ]
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module Locomotive
3
+ class PluginWithNonStringPath
4
+
5
+ include Locomotive::Plugin
6
+
7
+ class Pathname
8
+ def initialize(path)
9
+ @path = path
10
+ end
11
+
12
+ def to_s
13
+ @path.to_s || ''
14
+ end
15
+ end
16
+
17
+ def config_template_file
18
+ Pathname.new(File.join(File.dirname(__FILE__), '..', '..', 'fixtures',
19
+ 'config_template.html'))
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+
2
+ module Locomotive
3
+ class PluginWithTags
4
+
5
+ include Locomotive::Plugin
6
+
7
+ class Paragraph < ::Liquid::Block
8
+ def render(context)
9
+ "<p>#{render_all(@nodelist, context)}</p>"
10
+ end
11
+
12
+ def render_disabled(context)
13
+ render_all(@nodelist, context)
14
+ end
15
+ end
16
+
17
+ class Newline < ::Liquid::Tag
18
+ def render(context)
19
+ "<br />"
20
+ end
21
+ end
22
+
23
+ def self.liquid_tags
24
+ {
25
+ :paragraph => Paragraph,
26
+ :newline => Newline
27
+ }
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Locomotive
3
+ class UselessPlugin
4
+ include Locomotive::Plugin
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locomotive_plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta2
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Colibri Software
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: locomotive_liquid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.4'
30
+ - !ruby/object:Gem::Dependency
31
+ name: haml
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bson_ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mongoid
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.4.12
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.4.12
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: This gem allows developers to create plugins for Locomotive CMS with
111
+ particular functionality. See the README for more details
112
+ email: info@colibri-software.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - Rakefile
118
+ - lib/locomotive/plugin/db_model_container.rb
119
+ - lib/locomotive/plugin/liquid.rb
120
+ - lib/locomotive/plugin/liquid/prefixed_filter_module.rb
121
+ - lib/locomotive/plugin/liquid/tag_subclass_methods.rb
122
+ - lib/locomotive/plugin/db_models.rb
123
+ - lib/locomotive/plugin/db_model.rb
124
+ - lib/locomotive/plugin/config_ui.rb
125
+ - lib/locomotive/plugin.rb
126
+ - lib/version.rb
127
+ - lib/locomotive_plugins.rb
128
+ - spec/spec_helper.rb
129
+ - spec/support/plugins/my_other_plugin.rb
130
+ - spec/support/plugins/plugin_with_non_string_path.rb
131
+ - spec/support/plugins/plugin_with_tags.rb
132
+ - spec/support/plugins/useless_plugin.rb
133
+ - spec/support/plugins/plugin_with_filter.rb
134
+ - spec/support/plugins/plugin_with_many_filter_modules.rb
135
+ - spec/support/plugins/my_plugin.rb
136
+ - spec/support/plugins/plugin_with_db_model.rb
137
+ - spec/support/factories.rb
138
+ - spec/fixtures/config_template.haml
139
+ - spec/fixtures/config_template.html
140
+ - spec/lib/locomotive/plugin/liquid_spec.rb
141
+ - spec/lib/locomotive/plugin/db_models_spec.rb
142
+ - spec/lib/locomotive/plugin/config_ui_spec.rb
143
+ - spec/lib/locomotive/plugin_spec.rb
144
+ - spec/lib/locomotive_plugins_spec.rb
145
+ - README.md
146
+ - CHANGELOG
147
+ homepage: https://github.com/colibri-software/locomotive_plugins
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ~>
157
+ - !ruby/object:Gem::Version
158
+ version: '1.9'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>'
163
+ - !ruby/object:Gem::Version
164
+ version: 1.3.1
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.24
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Gem for creating plugins for Locomotive
171
+ test_files: []