lyb_sidebar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = LybSidebar
2
+
3
+ LybSidebar simplifies dries up common sidebar code.
4
+
5
+ = Install
6
+
7
+ In Rails 3, simply add
8
+
9
+ gem 'lyb_sidebar'
10
+
11
+ to your Gemfile.
12
+
13
+ = Example
14
+
15
+ class StatementController < ActionController::Base
16
+ sidebar
17
+ end
18
+
19
+ This will queue the partial 'statements/sidebar' to be rendered whenever
20
+ the 'prepare_sidebars' helper is called. The 'render_sidebars' will then
21
+ insert those queued sidebars.
22
+
23
+
24
+ = License
25
+
26
+ Copyright (c) 2011 Simon Hürlimann <simon.huerlimann@cyt.ch>
27
+
28
+ Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'LybSidebar'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
@@ -0,0 +1,3 @@
1
+ require 'lyb_sidebar/controller'
2
+ require 'lyb_sidebar/helper'
3
+ require 'lyb_sidebar/railtie' if defined?(::Rails::Railtie)
@@ -0,0 +1,3 @@
1
+ require 'lyb_sidebar/class_methods'
2
+ require 'lyb_sidebar/helper'
3
+ require 'lyb_sidebar/railtie' if defined?(::Rails::Railtie)
@@ -0,0 +1,4 @@
1
+ module LybSidebar
2
+ module ClassMethods
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module LybSidebar
2
+ module Controller
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_inheritable_accessor :sidebars
7
+ end
8
+
9
+ module ClassMethods
10
+ def sidebar(options = true)
11
+ if options.is_a? TrueClass
12
+ self.sidebars = ["#{controller_name}/sidebar"]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module LybSidebar
2
+ module Controller
3
+ module ClassMethods
4
+ def sidebar(options = true)
5
+ self.class_eval 'cattr_accessor :sidebars'
6
+ if options.is_a? TrueClass
7
+ self.sidebars = [controller_name]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ module LybSidebar
2
+ module Helper
3
+ # Tag support
4
+ def tag_filter(model = nil, filters = nil, scope = :tagged_with)
5
+ model ||= controller_name.singularize.camelize.constantize
6
+ filters ||= model.top_tags
7
+
8
+ render 'layouts/tag_filter', :filters => filters, :scope => scope
9
+ end
10
+
11
+ def sidebar_tag_filter
12
+ content_for :sidebar do
13
+ tag_filter
14
+ end
15
+ end
16
+
17
+ # Sidebar
18
+ def prepare_sidebars
19
+ return if controller.sidebars.nil?
20
+
21
+ for partial in controller.sidebars
22
+ render partial
23
+ end
24
+ end
25
+
26
+ def render_sidebar
27
+ content_for :sidebar
28
+ end
29
+
30
+ def render_sidebars
31
+ prepare_sidebars
32
+ render_sidebar
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ module LybSidebar
2
+ module Helper
3
+ # Tag support
4
+ def tag_filter(model = nil, filters = nil, scope = :tagged_with)
5
+ model ||= controller_name.singularize.camelize.constantize
6
+ filters ||= model.top_tags
7
+
8
+ render 'layouts/tag_filter', :filters => filters, :scope => scope
9
+ end
10
+
11
+ def sidebar_tag_filter
12
+ content_for :sidebar do
13
+ tag_filter
14
+ end
15
+ end
16
+
17
+ # Sidebar
18
+ def render_sidebar
19
+ content_for :sidebar
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'lyb_sidebar'
2
+ require 'rails'
3
+
4
+ module LybSidebar
5
+ class Railtie < Rails::Engine
6
+ initializer :after_initialize do
7
+ ActionController::Base.helper LybSidebar::Helper
8
+
9
+ ActionController::Base.send(:include, LybSidebar::Controller)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'lyb_sidebar'
2
+ require 'rails'
3
+
4
+ module LybSidebar
5
+ class Railtie < Rails::Engine
6
+ initializer :after_initialize do
7
+ ActionController::Base.helper LybSidebar::Helper
8
+
9
+ ActionController::Base.extend(LybSidebar::Controller::ClassMethods)
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lyb_sidebar
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - "Simon H\xC3\xBCrlimann (CyT)"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-11 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: LybSidebar simplifies dries up common sidebar code.
22
+ email:
23
+ - simon.huerlimann@cyt.ch
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/lyb_sidebar.rb~
32
+ - lib/lyb_sidebar.rb
33
+ - lib/lyb_sidebar/controller.rb~
34
+ - lib/lyb_sidebar/railtie.rb
35
+ - lib/lyb_sidebar/railtie.rb~
36
+ - lib/lyb_sidebar/controller.rb
37
+ - lib/lyb_sidebar/helper.rb~
38
+ - lib/lyb_sidebar/helper.rb
39
+ - lib/lyb_sidebar/class_methods.rb~
40
+ - MIT-LICENSE
41
+ - Rakefile
42
+ - README.rdoc
43
+ has_rdoc: true
44
+ homepage:
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.6
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: LybSidebar drys sidebars.
73
+ test_files: []
74
+