layou2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +12 -0
- data/Rakefile +72 -0
- data/TODO +9 -0
- data/generators/layou2/layou2_generator.rb +11 -0
- data/generators/layou2/templates/initializer.rb +11 -0
- data/lib/layou2/helpers.rb +154 -0
- data/lib/layou2/version.rb +5 -0
- data/lib/layou2.rb +49 -0
- data/rails/init.rb +2 -0
- data/test/helpers_test.rb +4 -0
- data/test/integration/helpers_integration_test.rb +14 -0
- data/test/integration/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/integration/rails_app/app/controllers/home_controller.rb +11 -0
- data/test/integration/rails_app/app/controllers/ponies_controller.rb +12 -0
- data/test/integration/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/integration/rails_app/app/models/active_record/pony.rb +5 -0
- data/test/integration/rails_app/config/boot.rb +110 -0
- data/test/integration/rails_app/config/environment.rb +13 -0
- data/test/integration/rails_app/config/environments/test.rb +28 -0
- data/test/integration/rails_app/config/initializers/inflections.rb +2 -0
- data/test/integration/rails_app/config/initializers/layou2.rb +6 -0
- data/test/integration/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/integration/rails_app/config/initializers/session_store.rb +15 -0
- data/test/integration/rails_app/config/routes.rb +15 -0
- data/test/layou2_test.rb +18 -0
- data/test/orm/active_record.rb +35 -0
- data/test/support/assertions_helper.rb +28 -0
- data/test/support/debug_helper.rb +18 -0
- data/test/support/substitutions_helper.rb +38 -0
- data/test/support/webrat.rb +6 -0
- data/test/test_helper.rb +41 -0
- metadata +176 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jonas Grimfelt
|
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.textile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require File.join(File.dirname(__FILE__), 'lib', 'layou2', 'version')
|
7
|
+
|
8
|
+
# Gem managment tasks.
|
9
|
+
#
|
10
|
+
# == Generate gemspec, build & install locally:
|
11
|
+
#
|
12
|
+
# rake gemspec
|
13
|
+
# rake build
|
14
|
+
# sudo rake install
|
15
|
+
#
|
16
|
+
# == Git tag & push to origin/master and push gem to Rubygems.org:
|
17
|
+
#
|
18
|
+
# rake release
|
19
|
+
#
|
20
|
+
# == Release to Rubygems.org:
|
21
|
+
#
|
22
|
+
# rake gemcutter:release
|
23
|
+
#
|
24
|
+
begin
|
25
|
+
gem 'jeweler'
|
26
|
+
require 'jeweler'
|
27
|
+
|
28
|
+
Jeweler::Tasks.new do |spec|
|
29
|
+
spec.name = "layou2"
|
30
|
+
spec.version = ::Layou2::VERSION
|
31
|
+
spec.summary = %{The layout helpers.}
|
32
|
+
spec.description = spec.summary
|
33
|
+
spec.homepage = "http://github.com/grimen/#{spec.name}"
|
34
|
+
spec.authors = ["Jonas Grimfelt"]
|
35
|
+
spec.email = "grimen@gmail.com"
|
36
|
+
|
37
|
+
spec.files = FileList["[A-Z]*", File.join(*%w[{generators,lib,rails} ** *]).to_s]
|
38
|
+
|
39
|
+
spec.add_dependency 'activesupport', '>= 2.3.0'
|
40
|
+
spec.add_dependency 'actionpack', '>= 2.3.0'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'test-unit', '= 1.2.3'
|
43
|
+
spec.add_development_dependency 'mocha', '>= 0.9.8'
|
44
|
+
spec.add_development_dependency 'webrat', '>= 0.7.0'
|
45
|
+
spec.add_development_dependency 'leftright', '>= 0.0.3'
|
46
|
+
end
|
47
|
+
|
48
|
+
Jeweler::GemcutterTasks.new
|
49
|
+
rescue LoadError
|
50
|
+
puts "Jeweler - or one of its dependencies - is not available. " <<
|
51
|
+
"Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Default: run unit tests.'
|
55
|
+
task :default => :test
|
56
|
+
|
57
|
+
desc 'Test the plugin.'
|
58
|
+
Rake::TestTask.new(:test) do |test|
|
59
|
+
test.libs = ['lib', 'test']
|
60
|
+
test.pattern = 'test/**/*_test.rb'
|
61
|
+
test.verbose = true
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Generate documentation for the plugin.'
|
65
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
66
|
+
rdoc.rdoc_dir = 'rdoc'
|
67
|
+
rdoc.title = ''
|
68
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
69
|
+
rdoc.rdoc_files.include('README')
|
70
|
+
rdoc.rdoc_files.include('rails/init.rb')
|
71
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
72
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if defined?(::Layou2)
|
4
|
+
::Layou2.setup do |config|
|
5
|
+
# Configure how - and in what order - title/description/keywords should be looked up.
|
6
|
+
# config.i18n_scopes = ['{{model}}.links.{{action}}', 'links.{{action}}']
|
7
|
+
#
|
8
|
+
# Enable/Disable Link2 DOM selectors generation.
|
9
|
+
# config.dom_selectors = true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Layou2
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
def title(*args, &block)
|
7
|
+
options = args.extract_options!
|
8
|
+
options[:meta] = false if options[:meta].nil?
|
9
|
+
options[:as] ||= :h1
|
10
|
+
|
11
|
+
(args ||= []).each do |arg|
|
12
|
+
case arg
|
13
|
+
when String then
|
14
|
+
title = arg
|
15
|
+
when Symbol then
|
16
|
+
options[arg] = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
title ||= capture_if_given(&block)
|
20
|
+
title = t('.title', options.except(:class, :meta, :as, :strip)) if title.blank? # I18n
|
21
|
+
title = title.textilize(:strip) if options[:textile]
|
22
|
+
# TODO: meta(:title, title) if options.delete(:meta)
|
23
|
+
options[:class] = [::Layou2.dom_classes[:title], options[:class]].compact.join(' ')
|
24
|
+
|
25
|
+
content_tag(options[:as] , title, options.slice(:class))
|
26
|
+
end
|
27
|
+
|
28
|
+
def description(*args, &block)
|
29
|
+
options = args.extract_options!
|
30
|
+
options[:meta] = false if options[:meta].nil?
|
31
|
+
options[:as] ||= :p
|
32
|
+
|
33
|
+
(args ||= []).each do |arg|
|
34
|
+
case arg
|
35
|
+
when String then
|
36
|
+
description = arg
|
37
|
+
when Symbol then
|
38
|
+
options[arg] = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
description ||= capture_if_given(&block)
|
43
|
+
description = t('.description', options.except(:class, :meta, :as, :strip)) if description.blank? # I18n
|
44
|
+
description += options[:end_with] if options[:end_with] && description[-1,1] != options[:end_with]
|
45
|
+
description = description.textilize(:strip) if options[:textile]
|
46
|
+
# TODO: (:description, description) if options.delete(:meta)
|
47
|
+
options[:class] = [::Layou2.dom_classes[:description], options[:class]].compact.join(' ')
|
48
|
+
|
49
|
+
content_tag(options[:as], description, options.slice(:class))
|
50
|
+
end
|
51
|
+
|
52
|
+
def keywords(*args, &block)
|
53
|
+
options = args.extract_options!
|
54
|
+
options[:meta] = false if options[:meta].nil?
|
55
|
+
|
56
|
+
(args ||= []).each do |arg|
|
57
|
+
case arg
|
58
|
+
when String then
|
59
|
+
keywords = arg
|
60
|
+
when Symbol then
|
61
|
+
options[arg] = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
keywords ||= capture_if_given(&block)
|
66
|
+
keywords = t('.keywords', options.except(:meta)) if keywords.blank? # I18n
|
67
|
+
# TODO: meta(:keywords, description) if options.delete(:meta)
|
68
|
+
|
69
|
+
# no view output
|
70
|
+
end
|
71
|
+
|
72
|
+
def meta(*args)
|
73
|
+
options = args.extract_options!
|
74
|
+
|
75
|
+
if args.first.is_a?(Symbol) && args.last.is_a?(String)
|
76
|
+
content_for(args.first, args.last)
|
77
|
+
else
|
78
|
+
returning '' do |html|
|
79
|
+
options.slice(:title, :description, :keywords).each do |type|
|
80
|
+
html << content_for(type, options[type])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# meta_tag :title
|
87
|
+
# meta_tag :title, "Untitled"
|
88
|
+
# meta_tags :title => "Untitled", :keywords => 'default,tags'
|
89
|
+
def meta_tags(*args)
|
90
|
+
options = args.extract_options!
|
91
|
+
|
92
|
+
if args.first.is_a?(Symbol) && args.last.is_a?(String)
|
93
|
+
send :"#{args.first}_tag", (args.last if args.last.present?)
|
94
|
+
else
|
95
|
+
returning '' do |html|
|
96
|
+
options.slice(:title, :description, :keywords).each do |type|
|
97
|
+
html << send(:"#{type}_tag", (options[type] if options[type].present?))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
alias :meta_tag :meta_tags
|
103
|
+
|
104
|
+
def default_content_types(encoding = 'utf-8')
|
105
|
+
content_type_tag(:'content-type', "text/html;charset=#{encoding.upcase}") <<
|
106
|
+
content_type_tag(:'content-script-type', 'text/javascript') <<
|
107
|
+
content_type_tag(:'content-style-type', 'text/css')
|
108
|
+
end
|
109
|
+
|
110
|
+
def title_tag(default = ::I18n.t('meta.default_title', :default => ''))
|
111
|
+
content_tag(:title, @content_for_title || default)
|
112
|
+
end
|
113
|
+
|
114
|
+
def description_tag(default = ::I18n.t('meta.default_description', :default => ''))
|
115
|
+
content = @content_for_description || default
|
116
|
+
tag(:meta, :name => 'description', :content => content) unless content.blank?
|
117
|
+
end
|
118
|
+
|
119
|
+
def keywords_tag(default = ::I18n.t('meta.default_keywords', :default => ''))
|
120
|
+
content = @content_for_keywords || default
|
121
|
+
tag(:meta, :name => 'keywords', :content => content) unless content.blank?
|
122
|
+
end
|
123
|
+
|
124
|
+
def content_type_tag(http_equiv, content)
|
125
|
+
tag(:meta, :'http-equiv' => http_equiv, :content => content)
|
126
|
+
end
|
127
|
+
|
128
|
+
def html_attributes(doctype_base = :xhtml, lang = ::I18n.locale)
|
129
|
+
attrs = if doctype_base == :html
|
130
|
+
{:lang => lang}
|
131
|
+
else
|
132
|
+
{:xmlns => 'http://www.w3.org/1999/xhtml', :'xml:lang' => lang}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def body_attributes
|
137
|
+
{
|
138
|
+
:id => "#{controller.controller_name}",
|
139
|
+
:class => "#{controller.action_name}"
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def capture_if_given(else_content = nil, &block)
|
146
|
+
if block_given?
|
147
|
+
self.capture(&block)
|
148
|
+
else
|
149
|
+
else_content.to_s
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
data/lib/layou2.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
begin
|
3
|
+
require 'active_support'
|
4
|
+
rescue LoadError
|
5
|
+
gem 'activesupport'
|
6
|
+
require 'active_support'
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'action_view'
|
11
|
+
rescue LoadError
|
12
|
+
gem 'actionpack'
|
13
|
+
require 'action_view'
|
14
|
+
end
|
15
|
+
|
16
|
+
module Layou2
|
17
|
+
|
18
|
+
autoload :Helpers, 'layou2/helpers'
|
19
|
+
autoload :VERSION, 'layou2/version'
|
20
|
+
|
21
|
+
Error = Class.new(::StandardError)
|
22
|
+
NotImplementedYetError = Class.new(::NotImplementedError)
|
23
|
+
|
24
|
+
DEFAULT_DOM_CLASSES = {:title => 'title', :description => 'description'}
|
25
|
+
|
26
|
+
# DOM selectors for easier manipulation of Layou2 titles using CSS/JavaScript.
|
27
|
+
mattr_accessor :dom_classes
|
28
|
+
@@dom_classes = DEFAULT_DOM_CLASSES
|
29
|
+
|
30
|
+
class << self
|
31
|
+
|
32
|
+
# Yield self for configuration block:
|
33
|
+
#
|
34
|
+
# Layou2.setup do |config|
|
35
|
+
# config.dom_selectors = {}
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
def setup
|
39
|
+
yield(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add extended ActionView behaviour.
|
47
|
+
ActionView::Base.class_eval do
|
48
|
+
include ::Layou2::Helpers
|
49
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/test_helper'
|
3
|
+
|
4
|
+
class HelpersIntegrationTest < ActionController::IntegrationTest
|
5
|
+
|
6
|
+
test 'Layou2 + Rails = ♥' do
|
7
|
+
visit '/'
|
8
|
+
assert_response :success
|
9
|
+
assert_template 'home/index'
|
10
|
+
|
11
|
+
assert_contain "WIN"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def rubygems_version
|
71
|
+
Gem::RubyGemsVersion rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_version
|
75
|
+
if defined? RAILS_GEM_VERSION
|
76
|
+
RAILS_GEM_VERSION
|
77
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
78
|
+
ENV['RAILS_GEM_VERSION']
|
79
|
+
else
|
80
|
+
parse_gem_version(read_environment_rb)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_rubygems
|
85
|
+
min_version = '1.3.2'
|
86
|
+
require 'rubygems'
|
87
|
+
unless rubygems_version >= min_version
|
88
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
rescue LoadError
|
93
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_gem_version(text)
|
98
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def read_environment_rb
|
103
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# All that for this:
|
110
|
+
Rails.boot!
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file
|
2
|
+
|
3
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
+
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
5
|
+
TEST_ORM = :active_record unless defined? TEST_ORM
|
6
|
+
|
7
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
8
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
9
|
+
|
10
|
+
Rails::Initializer.run do |config|
|
11
|
+
config.frameworks -= [ :active_record ] unless TEST_ORM == :active_record
|
12
|
+
config.time_zone = 'UTC'
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
config.action_view.cache_template_loading = true
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
24
|
+
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
27
|
+
# like if you have constraints or database-specific column types
|
28
|
+
# config.active_record.schema_format = :sql
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
4
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
5
|
+
|
6
|
+
if defined?(ActiveRecord)
|
7
|
+
# Include Active Record class name as root for JSON serialized output.
|
8
|
+
ActiveRecord::Base.include_root_in_json = true
|
9
|
+
|
10
|
+
# Store the full class name (including module namespace) in STI type column.
|
11
|
+
ActiveRecord::Base.store_full_sti_class = true
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionController::Routing.generate_best_match = false
|
15
|
+
|
16
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
17
|
+
ActiveSupport.use_standard_json_time_format = true
|
18
|
+
|
19
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
20
|
+
# if you're including raw json in an HTML page.
|
21
|
+
ActiveSupport.escape_html_entities_in_json = false
|
22
|
+
|
23
|
+
# Clean up silencers
|
24
|
+
Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying cookie session data integrity.
|
4
|
+
# If you change this key, all old sessions will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
ActionController::Base.session = {
|
8
|
+
:key => '_rails_app_session',
|
9
|
+
:secret => '73d6541260e27f6651d2a0e444468482151f867aa40f8306b1dbf1e468e27a434e8e072c74498757e6091c6b92aa962df1e64163cc12d318d7b59b41758db165'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Use the database for sessions instead of the cookie-based default,
|
13
|
+
# which shouldn't be used to store highly confidential information
|
14
|
+
# (create the session table with "rake db:sessions:create")
|
15
|
+
# ActionController::Base.session_store = :active_record_store
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ActionController::Routing::Routes.draw do |map|
|
4
|
+
|
5
|
+
map.root :controller => 'home'
|
6
|
+
|
7
|
+
map.resources :ponies, :member => {:shut_up => :get} do |ponies|
|
8
|
+
ponies.resources :ponies
|
9
|
+
end
|
10
|
+
|
11
|
+
# WHY?: Tests fails when these are enabled.
|
12
|
+
# map.connect ':controller/:action/:id'
|
13
|
+
# map.connect ':controller/:action/:id.:format'
|
14
|
+
|
15
|
+
end
|
data/test/layou2_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class Layou2Test < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test "#setup: setup block yields self" do
|
7
|
+
Layou2.setup do |config|
|
8
|
+
assert_equal Layou2, config
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
test "#setup: should be configurable using setup helper" do
|
13
|
+
swap Layou2, :dom_classes => ({:title => 'boo'}) do
|
14
|
+
assert_equal ({:title => 'boo'}), Layou2.dom_classes
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'integration', 'rails_app', 'config', 'environment'))
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
ActiveRecord::Migration.verbose = false
|
6
|
+
ActiveRecord::Base.logger = Logger.new(nil)
|
7
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
8
|
+
|
9
|
+
class Pony < ActiveRecord::Base
|
10
|
+
end
|
11
|
+
|
12
|
+
class Rainbow < ActiveRecord::Base
|
13
|
+
end
|
14
|
+
|
15
|
+
ActiveRecord::Schema.define(:version => 1) do
|
16
|
+
create_table :ponies do |t|
|
17
|
+
t.string :name
|
18
|
+
t.string :color
|
19
|
+
t.boolean :super_powers
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :rainbows do |t|
|
23
|
+
t.string :name
|
24
|
+
t.decimal :intensity
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table :dinos do |t|
|
28
|
+
t.string :name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class ActiveSupport::TestCase
|
33
|
+
self.use_transactional_fixtures = true
|
34
|
+
self.use_instantiated_fixtures = false
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Layou2
|
4
|
+
module AssertionsHelper
|
5
|
+
def assert_not(assertion)
|
6
|
+
assert !assertion
|
7
|
+
end
|
8
|
+
|
9
|
+
def assert_blank(assertion)
|
10
|
+
assert assertion.blank?
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_not_blank(assertion)
|
14
|
+
assert !assertion.blank?
|
15
|
+
end
|
16
|
+
alias :assert_present :assert_not_blank
|
17
|
+
|
18
|
+
def assert_no_select(*args)
|
19
|
+
assert_raise ::Test::Unit::AssertionFailedError do
|
20
|
+
assert_select(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveSupport::TestCase.class_eval do
|
27
|
+
include Layou2::AssertionsHelper
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'i18n'
|
3
|
+
|
4
|
+
module Layou2
|
5
|
+
module DebugHelper
|
6
|
+
|
7
|
+
def debug_routes
|
8
|
+
::ActionController::Routing::Routes.named_routes.each do |name, route|
|
9
|
+
puts "%20s: %s" % [name, route]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ActiveSupport::TestCase.class_eval do
|
17
|
+
include Layou2::DebugHelper
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'i18n'
|
3
|
+
|
4
|
+
module Layou2
|
5
|
+
module SubstitutionsHelper
|
6
|
+
|
7
|
+
# Execute the block setting the given values and restoring old values after
|
8
|
+
# the block is executed.
|
9
|
+
def swap(object, new_values)
|
10
|
+
old_values = {}
|
11
|
+
new_values.each do |key, value|
|
12
|
+
old_values[key] = object.send key
|
13
|
+
object.send :"#{key}=", value
|
14
|
+
end
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
old_values.each do |key, value|
|
18
|
+
object.send :"#{key}=", value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def store_translations(locale, translations, &block)
|
23
|
+
current_translations = ::I18n.backend.send(:translations).send(:[], locale.to_sym)
|
24
|
+
|
25
|
+
begin
|
26
|
+
::I18n.backend.store_translations locale, translations
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
# ::I18n.reload!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveSupport::TestCase.class_eval do
|
37
|
+
include Layou2::SubstitutionsHelper
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] = 'test'
|
5
|
+
TEST_ORM = (ENV['ORM'] || :active_record).to_sym
|
6
|
+
|
7
|
+
# ORM / Schema.
|
8
|
+
require File.join(File.dirname(__FILE__), 'orm', TEST_ORM.to_s)
|
9
|
+
|
10
|
+
gem 'test-unit', '1.2.3'
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'leftright'
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'mocha'
|
19
|
+
require 'webrat'
|
20
|
+
|
21
|
+
require 'active_support/test_case'
|
22
|
+
require 'action_view/test_case'
|
23
|
+
|
24
|
+
# Support.
|
25
|
+
Dir[File.join(File.dirname(__FILE__), *%w[support ** *.rb]).to_s].each { |f| require f }
|
26
|
+
|
27
|
+
# Dummie-class.
|
28
|
+
class Unicorn
|
29
|
+
end
|
30
|
+
|
31
|
+
# Routes.
|
32
|
+
ActionController::Routing::Routes.draw do |map|
|
33
|
+
map.resources :ponies, :member => {:kick => :post} do |fraggles|
|
34
|
+
fraggles.resources :rainbows, :member => {:kick => :post}
|
35
|
+
end
|
36
|
+
map.resource :rainbow
|
37
|
+
|
38
|
+
map.root :controller => 'ponies'
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'layou2'
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: layou2
|
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
|
+
- Jonas Grimfelt
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-17 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 2.3.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: actionpack
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 2.3.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: test-unit
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 2
|
58
|
+
- 3
|
59
|
+
version: 1.2.3
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 9
|
72
|
+
- 8
|
73
|
+
version: 0.9.8
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: webrat
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 7
|
86
|
+
- 0
|
87
|
+
version: 0.7.0
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: leftright
|
92
|
+
prerelease: false
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
- 0
|
100
|
+
- 3
|
101
|
+
version: 0.0.3
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id006
|
104
|
+
description: The layout helpers.
|
105
|
+
email: grimen@gmail.com
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files:
|
111
|
+
- README.textile
|
112
|
+
- TODO
|
113
|
+
files:
|
114
|
+
- MIT-LICENSE
|
115
|
+
- README.textile
|
116
|
+
- Rakefile
|
117
|
+
- TODO
|
118
|
+
- generators/layou2/layou2_generator.rb
|
119
|
+
- generators/layou2/templates/initializer.rb
|
120
|
+
- lib/layou2.rb
|
121
|
+
- lib/layou2/helpers.rb
|
122
|
+
- lib/layou2/version.rb
|
123
|
+
- rails/init.rb
|
124
|
+
has_rdoc: true
|
125
|
+
homepage: http://github.com/grimen/layou2
|
126
|
+
licenses: []
|
127
|
+
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options:
|
130
|
+
- --charset=UTF-8
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.3.6
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: The layout helpers.
|
154
|
+
test_files:
|
155
|
+
- test/helpers_test.rb
|
156
|
+
- test/integration/helpers_integration_test.rb
|
157
|
+
- test/integration/rails_app/app/controllers/application_controller.rb
|
158
|
+
- test/integration/rails_app/app/controllers/home_controller.rb
|
159
|
+
- test/integration/rails_app/app/controllers/ponies_controller.rb
|
160
|
+
- test/integration/rails_app/app/helpers/application_helper.rb
|
161
|
+
- test/integration/rails_app/app/models/active_record/pony.rb
|
162
|
+
- test/integration/rails_app/config/boot.rb
|
163
|
+
- test/integration/rails_app/config/environment.rb
|
164
|
+
- test/integration/rails_app/config/environments/test.rb
|
165
|
+
- test/integration/rails_app/config/initializers/inflections.rb
|
166
|
+
- test/integration/rails_app/config/initializers/layou2.rb
|
167
|
+
- test/integration/rails_app/config/initializers/new_rails_defaults.rb
|
168
|
+
- test/integration/rails_app/config/initializers/session_store.rb
|
169
|
+
- test/integration/rails_app/config/routes.rb
|
170
|
+
- test/layou2_test.rb
|
171
|
+
- test/orm/active_record.rb
|
172
|
+
- test/support/assertions_helper.rb
|
173
|
+
- test/support/debug_helper.rb
|
174
|
+
- test/support/substitutions_helper.rb
|
175
|
+
- test/support/webrat.rb
|
176
|
+
- test/test_helper.rb
|