acts-as-layoutable 0.0.1.7
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/MIT-LICENSE +20 -0
- data/README.markdown +50 -0
- data/Rakefile +78 -0
- data/init.rb +1 -0
- data/lib/acts-as-layoutable.rb +81 -0
- data/lib/acts-as-layoutable/area.rb +21 -0
- data/lib/acts-as-layoutable/builder.rb +61 -0
- data/lib/acts-as-layoutable/layout.rb +52 -0
- data/lib/acts-as-layoutable/template.rb +32 -0
- data/lib/acts-as-layoutable/widget.rb +18 -0
- data/rails/init.rb +3 -0
- data/test/lib/database.rb +49 -0
- data/test/lib/link.rb +3 -0
- data/test/lib/page.rb +3 -0
- data/test/lib/widgets.rb +13 -0
- data/test/test_helper.rb +155 -0
- data/test/test_layout.rb +40 -0
- metadata +84 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Lance Pollard (lancejpollard@gmail.com)
|
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.markdown
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# ActsAsLayoutable
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
### Install
|
6
|
+
|
7
|
+
sudo gem install acts-as-layoutable
|
8
|
+
|
9
|
+
### Usage
|
10
|
+
|
11
|
+
Layoutable do
|
12
|
+
# defines valid areas
|
13
|
+
areas :top, :bottom, :left, :right, :header, :footer, :center
|
14
|
+
|
15
|
+
grids do
|
16
|
+
full :top, :bottom, :left, :right, :center
|
17
|
+
left :top, :bottom, :right
|
18
|
+
portfolio :top, :bottom, :center
|
19
|
+
blog do
|
20
|
+
right :text, :social
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
widgets do
|
25
|
+
text do
|
26
|
+
title :string, :label => "Sample text"
|
27
|
+
body :text
|
28
|
+
end
|
29
|
+
|
30
|
+
social do
|
31
|
+
links :as => Link
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
That creates cells, areas, and layouts.
|
37
|
+
|
38
|
+
### Api
|
39
|
+
|
40
|
+
Layoutable.widgets #=> [text, social]
|
41
|
+
Layoutable.areas #=> [:top, :bottom, :left, :right, :header, :footer, :center]
|
42
|
+
Layoutable.layouts #=> [:full, :left, :portfolio]
|
43
|
+
layout = Layout.first
|
44
|
+
layout.widgets
|
45
|
+
layout.top_widgets
|
46
|
+
layout.bottom_widgets
|
47
|
+
|
48
|
+
- Each `Post` has a different `Layout` via `clone`.
|
49
|
+
- New layouts cannot be constructed outside of this dsl. Only the order and presence of cells within areas can be customized.
|
50
|
+
- `area` is the "context" for the join of Layout to Widget.
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require "rake/rdoctask"
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = "acts-as-layoutable"
|
7
|
+
s.authors = ["Lance Pollard"]
|
8
|
+
s.version = "0.0.1.7"
|
9
|
+
s.summary = "ActsAsLayoutable: Super Complex Layouts in Rails with single Configuration file"
|
10
|
+
s.homepage = "http://github.com/viatropos/acts-as-layoutable"
|
11
|
+
s.email = "lancejpollard@gmail.com"
|
12
|
+
s.description = "Super Complex Layouts in Rails with single Configuration file"
|
13
|
+
s.has_rdoc = false
|
14
|
+
s.rubyforge_project = "acts-as-layoutable"
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
|
17
|
+
s.require_path = "lib"
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
21
|
+
pkg.gem_spec = spec
|
22
|
+
pkg.package_dir = "pkg"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'run unit tests'
|
26
|
+
task :test do
|
27
|
+
Dir["test/**/*"].each do |file|
|
28
|
+
next unless File.basename(file) =~ /test_/
|
29
|
+
next unless File.extname(file) == ".rb"
|
30
|
+
system "ruby #{file}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Create .gemspec file (useful for github)"
|
35
|
+
task :gemspec do
|
36
|
+
File.open("pkg/#{spec.name}.gemspec", "w") do |f|
|
37
|
+
f.puts spec.to_ruby
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Build the gem into the current directory"
|
42
|
+
task :gem => :gemspec do
|
43
|
+
`gem build pkg/#{spec.name}.gemspec`
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Publish gem to rubygems"
|
47
|
+
task :publish => [:package] do
|
48
|
+
%x[gem push pkg/#{spec.name}-#{spec.version}.gem]
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Print a list of the files to be put into the gem"
|
52
|
+
task :manifest do
|
53
|
+
File.open("Manifest", "w") do |f|
|
54
|
+
spec.files.each do |file|
|
55
|
+
f.puts file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Install the gem locally"
|
61
|
+
task :install => [:package] do
|
62
|
+
File.mkdir("pkg") unless File.exists?("pkg")
|
63
|
+
command = "gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc"
|
64
|
+
command = "sudo #{command}" if ENV["SUDO"] == true
|
65
|
+
sh %{#{command}}
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Generate the rdoc"
|
69
|
+
Rake::RDocTask.new do |rdoc|
|
70
|
+
files = ["README.markdown", "lib/**/*.rb"]
|
71
|
+
rdoc.rdoc_files.add(files)
|
72
|
+
rdoc.main = "README.markdown"
|
73
|
+
rdoc.title = spec.summary
|
74
|
+
end
|
75
|
+
|
76
|
+
task :yank do
|
77
|
+
`gem yank #{spec.name} -v #{spec.version}`
|
78
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
File.dirname(__FILE__) + "/rails/init.rb"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_record'
|
4
|
+
require 'cockpit'
|
5
|
+
require 'acts-as-joinable'
|
6
|
+
|
7
|
+
def require_local(path, from = __FILE__)
|
8
|
+
files(path, from) {|file| require file if File.extname(file) == ".rb"}
|
9
|
+
end
|
10
|
+
|
11
|
+
def files(path, from = __FILE__, &block)
|
12
|
+
Dir.glob(File.expand_path(File.join(File.dirname(from), path))) {|file| yield file}
|
13
|
+
end
|
14
|
+
|
15
|
+
module ActsAsLayoutable
|
16
|
+
def self.included(base)
|
17
|
+
base.extend ClassMethods
|
18
|
+
base.send :include, InstanceMethods
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
|
23
|
+
def acts_as_layoutable(*args)
|
24
|
+
acts_as_joinable_on :layouts, :class_name => "ActsAsLayoutable::Layout"
|
25
|
+
# before_save :ensure_layout_exists
|
26
|
+
|
27
|
+
options = args.extract_options!
|
28
|
+
|
29
|
+
args.each do |action|
|
30
|
+
define_method "#{action.to_s}_layout" do
|
31
|
+
join_for(:parent, :layout, action)
|
32
|
+
end
|
33
|
+
define_method "#{action.to_s}_layout=" do |value|
|
34
|
+
set_joined(:parent, :layout, action, value)
|
35
|
+
end
|
36
|
+
define_method "#{action.to_s}_layout_id" do
|
37
|
+
result = join_for(:parent, :layout, action)
|
38
|
+
result ? result.id : nil
|
39
|
+
end
|
40
|
+
define_method "#{action.to_s}_layout_id=" do |value|
|
41
|
+
set_joined(:parent, :layout, action, value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def template(layoutable)
|
47
|
+
layoutable ? layoutable.template : nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module InstanceMethods
|
52
|
+
|
53
|
+
def ensure_layout_exists
|
54
|
+
if self.layouts.blank?
|
55
|
+
self.layouts << Layout.first
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def layout
|
60
|
+
self.layouts.first
|
61
|
+
end
|
62
|
+
|
63
|
+
def template
|
64
|
+
self.layout.template
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
require File.dirname(__FILE__) + '/acts-as-layoutable/builder'
|
71
|
+
require_local "acts-as-layoutable/*"
|
72
|
+
|
73
|
+
ActiveRecord::Base.send(:include, ActsAsLayoutable)
|
74
|
+
|
75
|
+
def Layoutable(*args, &block)
|
76
|
+
ActsAsLayoutable::Builder.define!(*args, &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
def Layouts(*args, &block)
|
80
|
+
Layoutable(*args, &block)
|
81
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActsAsLayoutable
|
2
|
+
|
3
|
+
class AreaBuilder < ActsAsLayoutable::Builder
|
4
|
+
|
5
|
+
def method_missing(meth, *args, &block)
|
6
|
+
self.item = ActsAsLayoutable::Area.create!(:name => meth.to_s)
|
7
|
+
args.each do |widget|
|
8
|
+
self.item.widgets << ActsAsLayoutable::Widget.find_or_create_by_name(widget.to_s)
|
9
|
+
end
|
10
|
+
self.collection << self.item
|
11
|
+
self.item.save
|
12
|
+
self.item
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class Area < ActiveRecord::Base
|
18
|
+
belongs_to :layout
|
19
|
+
has_many :widgets
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ActsAsLayoutable
|
2
|
+
class Builder
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def define!(*args, &block)
|
6
|
+
new(*args, &block).collection.uniq
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :item, :collection
|
11
|
+
|
12
|
+
def collection
|
13
|
+
@collection ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def klazz
|
17
|
+
self.class.to_s.gsub("Builder", "").constantize
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(*args, &block)
|
21
|
+
args.each do |name|
|
22
|
+
self.collection << klazz.create!(:name => name.to_s)
|
23
|
+
end
|
24
|
+
instance_eval(&block) if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def templates(*args, &block)
|
28
|
+
TemplateBuilder.define!(*args, &block)
|
29
|
+
end
|
30
|
+
alias paths templates
|
31
|
+
|
32
|
+
def layouts(*args, &block)
|
33
|
+
LayoutBuilder.define!(*args, &block)
|
34
|
+
end
|
35
|
+
alias grids layouts
|
36
|
+
|
37
|
+
def areas(*args, &block)
|
38
|
+
AreaBuilder.define!(*args, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def widgets(*args, &block)
|
42
|
+
WidgetBuilder.define!(*args, &block)
|
43
|
+
end
|
44
|
+
alias cells widgets
|
45
|
+
|
46
|
+
def method_missing(meth, *args, &block)
|
47
|
+
if context
|
48
|
+
result = "ActsAsLayoutable::#{context.singularize.camelize}".constantize.new
|
49
|
+
result.instance_eval(&block) if block_given?
|
50
|
+
return result
|
51
|
+
else
|
52
|
+
super(meth, *args, &block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def context
|
58
|
+
@context
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ActsAsLayoutable
|
2
|
+
|
3
|
+
class LayoutBuilder < ActsAsLayoutable::Builder
|
4
|
+
|
5
|
+
# the path to the template/view folder, so "app/views/posts" is "posts"
|
6
|
+
def template(path = nil)
|
7
|
+
self.item.path = path.to_s if path
|
8
|
+
end
|
9
|
+
alias path template
|
10
|
+
|
11
|
+
# the REST actions your layout will respond to
|
12
|
+
def actions(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def description(text = nil)
|
16
|
+
self.item.description = text.to_s if text
|
17
|
+
end
|
18
|
+
|
19
|
+
def areas(*args, &block)
|
20
|
+
ActsAsLayoutable::AreaBuilder.define!(*args, &block).each do |area|
|
21
|
+
self.item.areas << area
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(meth, *args, &block)
|
26
|
+
self.item = ActsAsLayoutable::Layout.find_or_create_by_name(meth.to_s)
|
27
|
+
self.instance_eval(&block) if block_given?
|
28
|
+
self.item.save
|
29
|
+
self.collection << item
|
30
|
+
self.item
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Layout < ActiveRecord::Base
|
36
|
+
acts_as_joinable
|
37
|
+
has_many :areas, :class_name => "ActsAsLayoutable::Area"
|
38
|
+
has_many :widgets, :class_name => "ActsAsLayoutable::Widget", :through => :areas
|
39
|
+
before_save :assure_key
|
40
|
+
|
41
|
+
validates_presence_of :name
|
42
|
+
|
43
|
+
def assure_key
|
44
|
+
self.key ||= self.name.underscore.downcase.gsub(/\s+/, "_")
|
45
|
+
end
|
46
|
+
|
47
|
+
def template
|
48
|
+
raise "Layout doesn't have a template" unless self.path
|
49
|
+
self.path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActsAsLayoutable
|
2
|
+
|
3
|
+
class TemplateBuilder < ActsAsLayoutable::Builder
|
4
|
+
|
5
|
+
def method_missing(meth, *args, &block)
|
6
|
+
key = meth.to_s
|
7
|
+
path = args.shift || key.dup
|
8
|
+
template = ActsAsLayoutable::Template.new(path, key)
|
9
|
+
Template.all << template
|
10
|
+
self.collection << template
|
11
|
+
template
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Template
|
17
|
+
attr_accessor :path, :key
|
18
|
+
|
19
|
+
def initialize(path, key)
|
20
|
+
@path = path
|
21
|
+
@key = key
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_accessor :all
|
26
|
+
|
27
|
+
def all
|
28
|
+
@all ||= []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActsAsLayoutable
|
2
|
+
|
3
|
+
class WidgetBuilder < ActsAsLayoutable::Builder
|
4
|
+
|
5
|
+
def method_missing(meth, *args, &block)
|
6
|
+
self.item = ActsAsLayoutable::Widget.create!(:name => meth.to_s)
|
7
|
+
ActsAsLayoutable::Widget.acts_as_configurable(meth, &block) if block_given?
|
8
|
+
self.collection << self.item
|
9
|
+
self.item.save
|
10
|
+
self.item
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class Widget < ActiveRecord::Base
|
16
|
+
belongs_to :area, :class_name => "ActsAsLayoutable::Area"
|
17
|
+
end
|
18
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
begin
|
2
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
3
|
+
rescue ArgumentError
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
5
|
+
end
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations = true
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define(:version => 1) do
|
10
|
+
|
11
|
+
create_table :layouts, :force => true do |t|
|
12
|
+
t.text :description
|
13
|
+
t.string :name
|
14
|
+
t.string :path # path to the layout, same as the 'render' method
|
15
|
+
t.string :key # some layouts use same views, but have different sub areas
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :areas, :force => true do |t|
|
20
|
+
t.string :name
|
21
|
+
t.references :layout
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table :widgets, :force => true do |t|
|
26
|
+
t.string :name
|
27
|
+
t.references :area
|
28
|
+
t.string :type
|
29
|
+
t.timestamps
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table :links, :force => true do |t|
|
33
|
+
t.string :name
|
34
|
+
t.timestamps
|
35
|
+
end
|
36
|
+
|
37
|
+
create_table :pages, :force => true do |t|
|
38
|
+
t.string :title
|
39
|
+
t.timestamps
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table :relationships do |t|
|
43
|
+
t.references :parent, :polymorphic => true
|
44
|
+
t.references :child, :polymorphic => true
|
45
|
+
t.string :context
|
46
|
+
t.timestamps
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/lib/link.rb
ADDED
data/test/lib/page.rb
ADDED
data/test/lib/widgets.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "ruby-debug"
|
3
|
+
gem 'test-unit'
|
4
|
+
require "test/unit"
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/test_case'
|
7
|
+
require 'active_record'
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
require 'shoulda'
|
10
|
+
require 'shoulda/active_record'
|
11
|
+
require 'acts-as-joinable'
|
12
|
+
|
13
|
+
this = File.expand_path(File.dirname(__FILE__))
|
14
|
+
require this + '/lib/database'
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '/../lib/acts-as-layoutable'))
|
17
|
+
|
18
|
+
require File.dirname(__FILE__) + '/lib/link'
|
19
|
+
require File.dirname(__FILE__) + '/lib/page'
|
20
|
+
|
21
|
+
ActiveRecord::Base.class_eval do
|
22
|
+
def self.detonate
|
23
|
+
all.map(&:destroy)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveSupport::TestCase.class_eval do
|
28
|
+
|
29
|
+
def load_layouts
|
30
|
+
Layoutable do
|
31
|
+
|
32
|
+
templates do
|
33
|
+
contact
|
34
|
+
error
|
35
|
+
overview
|
36
|
+
pages
|
37
|
+
large_portfolio "portfolio/large"
|
38
|
+
medium_portfolio "portfolio/medium"
|
39
|
+
small_portfolio "portfolio/small"
|
40
|
+
posts
|
41
|
+
end
|
42
|
+
|
43
|
+
layouts do
|
44
|
+
full do
|
45
|
+
description "A full width layout, mainly for text"
|
46
|
+
areas :top, :bottom, :left, :right, :header, :footer, :body
|
47
|
+
template :pages
|
48
|
+
end
|
49
|
+
left do
|
50
|
+
description "Side bar on the right, content on the left"
|
51
|
+
template :pages
|
52
|
+
areas :top, :bottom, :right, :header, :footer, :body
|
53
|
+
end
|
54
|
+
right do
|
55
|
+
description "Side bar on the left, content on the right"
|
56
|
+
template :pages
|
57
|
+
areas :top, :bottom, :left, :header, :footer, :body
|
58
|
+
end
|
59
|
+
blog do
|
60
|
+
description "Blog Layout"
|
61
|
+
template :posts
|
62
|
+
areas :right, :top, :bottom, :header, :footer, :body
|
63
|
+
end
|
64
|
+
page do
|
65
|
+
description "Page Layout"
|
66
|
+
template :pages
|
67
|
+
areas :right, :top, :bottom, :header, :footer, :body
|
68
|
+
end
|
69
|
+
contact do
|
70
|
+
description "Contact Layout"
|
71
|
+
template :contact
|
72
|
+
areas :top, :bottom, :header, :footer, :body
|
73
|
+
end
|
74
|
+
overview do
|
75
|
+
description "Overview Layout"
|
76
|
+
template :overview
|
77
|
+
areas :top, :bottom, :header, :footer, :body
|
78
|
+
end
|
79
|
+
large_portfolio do
|
80
|
+
description "Large Portfolio Layout"
|
81
|
+
template :large_portfolio
|
82
|
+
areas :top, :bottom, :header, :footer, :body
|
83
|
+
end
|
84
|
+
medium_portfolio do
|
85
|
+
description "Medium Portfolio Layout"
|
86
|
+
template :medium_portfolio
|
87
|
+
areas :top, :bottom, :header, :footer, :body
|
88
|
+
end
|
89
|
+
small_portfolio do
|
90
|
+
description "Small Portfolio Layout"
|
91
|
+
template :small_portfolio
|
92
|
+
areas :top, :bottom, :header, :footer, :body
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
widgets do
|
97
|
+
connect do
|
98
|
+
title :string
|
99
|
+
facebook :string
|
100
|
+
twitter :string
|
101
|
+
my_space :string
|
102
|
+
linked_in :string
|
103
|
+
stack_overflow :string
|
104
|
+
github :string
|
105
|
+
email :string
|
106
|
+
end
|
107
|
+
image do
|
108
|
+
title :string
|
109
|
+
url :string
|
110
|
+
alt_text :string
|
111
|
+
image_title :string
|
112
|
+
description :string
|
113
|
+
image_align :string
|
114
|
+
link_url :string
|
115
|
+
end
|
116
|
+
links do
|
117
|
+
title "Blog Roll"
|
118
|
+
end
|
119
|
+
login do
|
120
|
+
title "Login"
|
121
|
+
google true
|
122
|
+
facebook true
|
123
|
+
twitter true
|
124
|
+
open_id true
|
125
|
+
end
|
126
|
+
meta do
|
127
|
+
title "Meta"
|
128
|
+
end
|
129
|
+
search do
|
130
|
+
title "Search"
|
131
|
+
end
|
132
|
+
social do
|
133
|
+
title "Social"
|
134
|
+
end
|
135
|
+
tag_cloud do
|
136
|
+
title "Tag Cloud"
|
137
|
+
end
|
138
|
+
text do
|
139
|
+
title "Random Text"
|
140
|
+
body :string
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
def detonate
|
149
|
+
ActsAsLayoutable::Layout.detonate
|
150
|
+
ActsAsLayoutable::Area.detonate
|
151
|
+
ActsAsLayoutable::Widget.detonate
|
152
|
+
Page.detonate
|
153
|
+
Link.detonate
|
154
|
+
end
|
155
|
+
end
|
data/test/test_layout.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class LayoutTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
context "Layout" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
detonate
|
9
|
+
load_layouts
|
10
|
+
end
|
11
|
+
|
12
|
+
should "load the layouts" do
|
13
|
+
assert_equal 10, ActsAsLayoutable::Layout.count
|
14
|
+
assert_equal 7, ActsAsLayoutable::Area.count(:select => "DISTINCT name")
|
15
|
+
assert_equal 9, ActsAsLayoutable::Widget.count(:select => "DISTINCT name")
|
16
|
+
end
|
17
|
+
|
18
|
+
should "associate the correct areas to the layouts" do
|
19
|
+
blog = ActsAsLayoutable::Layout.find_by_name("blog")
|
20
|
+
assert_equal 6, blog.areas.length
|
21
|
+
end
|
22
|
+
|
23
|
+
context "create layouts for model" do
|
24
|
+
setup do
|
25
|
+
@page = Page.create!(:title => "Page title!")
|
26
|
+
@page.layouts << ActsAsLayoutable::Layout.first
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have one layout" do
|
30
|
+
assert_equal 1, @page.layouts.length
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
teardown do
|
35
|
+
detonate
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts-as-layoutable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 69
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- 7
|
11
|
+
version: 0.0.1.7
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Lance Pollard
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-07-02 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: Super Complex Layouts in Rails with single Configuration file
|
24
|
+
email: lancejpollard@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- README.markdown
|
33
|
+
- Rakefile
|
34
|
+
- init.rb
|
35
|
+
- MIT-LICENSE
|
36
|
+
- lib/acts-as-layoutable/area.rb
|
37
|
+
- lib/acts-as-layoutable/builder.rb
|
38
|
+
- lib/acts-as-layoutable/layout.rb
|
39
|
+
- lib/acts-as-layoutable/template.rb
|
40
|
+
- lib/acts-as-layoutable/widget.rb
|
41
|
+
- lib/acts-as-layoutable.rb
|
42
|
+
- rails/init.rb
|
43
|
+
- test/lib/database.rb
|
44
|
+
- test/lib/link.rb
|
45
|
+
- test/lib/page.rb
|
46
|
+
- test/lib/widgets.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
- test/test_layout.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/viatropos/acts-as-layoutable
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: acts-as-layoutable
|
79
|
+
rubygems_version: 1.3.7
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: "ActsAsLayoutable: Super Complex Layouts in Rails with single Configuration file"
|
83
|
+
test_files: []
|
84
|
+
|