railings 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rspec +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +89 -0
- data/Rakefile +2 -0
- data/lib/railings/domains.rb +21 -0
- data/lib/railings/extensions/array.rb +9 -0
- data/lib/railings/extensions/class.rb +9 -0
- data/lib/railings/extensions/extendable.rb +34 -0
- data/lib/railings/extensions/hash.rb +13 -0
- data/lib/railings/extensions/string.rb +17 -0
- data/lib/railings/filterable.rb +11 -0
- data/lib/railings/layout_helper.rb +38 -0
- data/lib/railings/routing_helper.rb +24 -0
- data/lib/railings/version.rb +3 -0
- data/lib/railings.rb +23 -0
- data/railings.gemspec +24 -0
- data/spec/extensions/class_spec.rb +12 -0
- data/spec/extensions/hash_spec.rb +7 -0
- data/spec/extensions/string_spec.rb +24 -0
- data/spec/spec_helper.rb +9 -0
- metadata +129 -0
data/.gitignore
ADDED
data/.rspec
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
railings (0.0.1)
|
5
|
+
rails (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionmailer (3.0.5)
|
12
|
+
actionpack (= 3.0.5)
|
13
|
+
mail (~> 2.2.15)
|
14
|
+
actionpack (3.0.5)
|
15
|
+
activemodel (= 3.0.5)
|
16
|
+
activesupport (= 3.0.5)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.4)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.13)
|
22
|
+
rack-test (~> 0.5.7)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.5)
|
25
|
+
activesupport (= 3.0.5)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.4)
|
28
|
+
activerecord (3.0.5)
|
29
|
+
activemodel (= 3.0.5)
|
30
|
+
activesupport (= 3.0.5)
|
31
|
+
arel (~> 2.0.2)
|
32
|
+
tzinfo (~> 0.3.23)
|
33
|
+
activeresource (3.0.5)
|
34
|
+
activemodel (= 3.0.5)
|
35
|
+
activesupport (= 3.0.5)
|
36
|
+
activesupport (3.0.5)
|
37
|
+
arel (2.0.9)
|
38
|
+
builder (2.1.2)
|
39
|
+
diff-lcs (1.1.2)
|
40
|
+
erubis (2.6.6)
|
41
|
+
abstract (>= 1.0.0)
|
42
|
+
i18n (0.5.0)
|
43
|
+
mail (2.2.15)
|
44
|
+
activesupport (>= 2.3.6)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.16)
|
49
|
+
polyglot (0.3.1)
|
50
|
+
rack (1.2.2)
|
51
|
+
rack-mount (0.6.14)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rack-test (0.5.7)
|
54
|
+
rack (>= 1.0)
|
55
|
+
rails (3.0.5)
|
56
|
+
actionmailer (= 3.0.5)
|
57
|
+
actionpack (= 3.0.5)
|
58
|
+
activerecord (= 3.0.5)
|
59
|
+
activeresource (= 3.0.5)
|
60
|
+
activesupport (= 3.0.5)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
railties (= 3.0.5)
|
63
|
+
railties (3.0.5)
|
64
|
+
actionpack (= 3.0.5)
|
65
|
+
activesupport (= 3.0.5)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.8.7)
|
69
|
+
rspec (2.5.0)
|
70
|
+
rspec-core (~> 2.5.0)
|
71
|
+
rspec-expectations (~> 2.5.0)
|
72
|
+
rspec-mocks (~> 2.5.0)
|
73
|
+
rspec-core (2.5.1)
|
74
|
+
rspec-expectations (2.5.0)
|
75
|
+
diff-lcs (~> 1.1.2)
|
76
|
+
rspec-mocks (2.5.0)
|
77
|
+
thor (0.14.6)
|
78
|
+
treetop (1.4.9)
|
79
|
+
polyglot (>= 0.3.1)
|
80
|
+
tzinfo (0.3.26)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
bundler (>= 1.0.0)
|
87
|
+
railings!
|
88
|
+
rails (~> 3.0)
|
89
|
+
rspec (>= 2.5)
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Railings
|
2
|
+
module Domains
|
3
|
+
MAPPINGS = YAML::load_file Rails.root.join 'config', 'domains.yml' rescue false
|
4
|
+
MAPPINGS ||= { }
|
5
|
+
|
6
|
+
def const_missing domain
|
7
|
+
Class.new do
|
8
|
+
@domain = domain.downcase.to_s
|
9
|
+
class << self
|
10
|
+
def matches? request
|
11
|
+
request.subdomain.include? subdomain
|
12
|
+
end
|
13
|
+
|
14
|
+
def subdomain
|
15
|
+
MAPPINGS.has_key?(@domain) ? MAPPINGS[@domain] : @domain
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Object
|
2
|
+
class Extendable < String
|
3
|
+
def initialize object, parts = []
|
4
|
+
@object, @parts = [object, parts.clone]
|
5
|
+
replace parts.insert(0, object.class.name.demodulize.downcase.dasherize).join('-')
|
6
|
+
end
|
7
|
+
|
8
|
+
def class
|
9
|
+
Extendable.new @object, @parts[1..-1].to_a
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
{
|
14
|
+
:class => self.class,
|
15
|
+
:id => self
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def method_missing symbol, *args
|
21
|
+
Extendable.new @object, @parts.push(symbol.to_s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def element
|
26
|
+
if respond_to?(:to_param)
|
27
|
+
Extendable.new(self, [to_param])
|
28
|
+
elsif respond_to?(:key)
|
29
|
+
Extendable.new(self, [key])
|
30
|
+
else
|
31
|
+
Extendable.new self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Railings
|
2
|
+
module Filterable
|
3
|
+
[:after, :before].each do |context|
|
4
|
+
[:index, :show, :new, :create, :update, :destroy].each do |action|
|
5
|
+
define_method "#{context}_#{action}", ->(filter, options = { }, &block) do
|
6
|
+
send "#{context}_filter", filter, options.merge!(:only => action), &block
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Railings
|
2
|
+
module LayoutHelper
|
3
|
+
def body controller, *classes
|
4
|
+
if @message
|
5
|
+
id = @message.element.class.pluralize
|
6
|
+
else
|
7
|
+
parts = [controller.controller_name]
|
8
|
+
parts.insert 0, controller.class.parent.name.downcase unless controller.class.parent == Object
|
9
|
+
id = parts.join '-'
|
10
|
+
end
|
11
|
+
{ :class => classes.push(controller.action_name).join(' '), :id => id }
|
12
|
+
end
|
13
|
+
|
14
|
+
def title controller
|
15
|
+
scope = [
|
16
|
+
controller.class.parent == Object ? nil : controller.class.parent.name.downcase,
|
17
|
+
controller.controller_name,
|
18
|
+
controller.action_name
|
19
|
+
].compact
|
20
|
+
|
21
|
+
options = { :default => '' }
|
22
|
+
controller.instance_variables.each do |name|
|
23
|
+
options.merge! name.to_s[1..-1].to_sym => controller.instance_variable_get(name).to_s if
|
24
|
+
controller.instance_variable_get(name).kind_of?(MongoMapper::Document)
|
25
|
+
end
|
26
|
+
|
27
|
+
while scope.any?
|
28
|
+
t(:title, options.merge!(:scope => scope)).tap do |title|
|
29
|
+
return title unless title.blank?
|
30
|
+
end
|
31
|
+
scope.pop
|
32
|
+
end
|
33
|
+
t :title, :default => ::Rails.application.class.parent.name.titleize
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Railings
|
2
|
+
module RoutingHelper
|
3
|
+
Rails::application::class::parent::Domains::MAPPINGS.keys.each do |name|
|
4
|
+
define_method "url_for_#{name}" do |options|
|
5
|
+
domain = Rails::application::class::parent::Domains.const_get(name.to_s.capitalize)
|
6
|
+
if domain && domain.respond_to?(:subdomain)
|
7
|
+
options[:host] = with_subdomain domain.subdomain
|
8
|
+
options[:only_path] = false
|
9
|
+
end
|
10
|
+
options
|
11
|
+
end
|
12
|
+
end if Rails::application::class::parent.const_defined? 'Domains'
|
13
|
+
|
14
|
+
def url_for_root options
|
15
|
+
request.subdomain.present? ? options.merge!(:host => with_subdomain, :only_path => false) : options
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_subdomain subdomain = ''
|
19
|
+
subdomain ||= ''
|
20
|
+
subdomain += "." unless subdomain.empty?
|
21
|
+
[subdomain, request.domain, request.port_string].join
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/railings.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Railings
|
2
|
+
autoload :Domains, 'railings/domains'
|
3
|
+
autoload :Filterable, 'railings/filterable'
|
4
|
+
autoload :LayoutHelper, 'railings/layout_helper'
|
5
|
+
autoload :RoutingHelper, 'railings/routing_helper'
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
config.to_prepare do
|
9
|
+
ApplicationController.send :extend, Filterable
|
10
|
+
ApplicationController.send :helper, RoutingHelper
|
11
|
+
ApplicationController.send :include, RoutingHelper
|
12
|
+
ApplicationController.send :helper, LayoutHelper
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer 'railings.setup_routing_domains' do
|
16
|
+
Rails::application::class::parent.const_set 'Domains', Domains
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Dir[File.join(File.dirname(__FILE__), 'railings', 'extensions', '*.rb')].each do |extension|
|
22
|
+
require extension
|
23
|
+
end
|
data/railings.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/railings/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "railings"
|
6
|
+
s.version = Railings::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Nathaniel Jones']
|
9
|
+
s.email = ['nathaniel@pointeractive.com']
|
10
|
+
s.homepage = "http://rubygems.org/gems/railings"
|
11
|
+
s.summary = "Ruby and Rails extensions"
|
12
|
+
s.description = "Ruby and Rails extensions, mostly with Ruby 1.9.2 and Rails ~> 3.0"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "railings"
|
16
|
+
|
17
|
+
s.add_dependency "rails", "~> 3.0"
|
18
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
19
|
+
s.add_development_dependency "rspec", ">= 2.5"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
23
|
+
s.require_path = 'lib'
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
it "should parenthesize a string" do
|
5
|
+
"wait, what?".parenthesize.should eql "(wait, what?)"
|
6
|
+
end
|
7
|
+
|
8
|
+
context "questionable" do
|
9
|
+
it "should be if a question mark is on end" do
|
10
|
+
'a?'.questionable?.should be_true
|
11
|
+
'a'.questionable?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should in-line replace the string" do
|
15
|
+
v = 'a'
|
16
|
+
v.questionable!
|
17
|
+
v.should eql 'a?'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not add multiple question marks" do
|
21
|
+
'a?'.questionable.should eql 'a?'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: railings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nathaniel Jones
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-04-05 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: "3.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 5
|
60
|
+
version: "2.5"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: Ruby and Rails extensions, mostly with Ruby 1.9.2 and Rails ~> 3.0
|
64
|
+
email:
|
65
|
+
- nathaniel@pointeractive.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- .rspec
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- Rakefile
|
78
|
+
- lib/railings.rb
|
79
|
+
- lib/railings/domains.rb
|
80
|
+
- lib/railings/extensions/array.rb
|
81
|
+
- lib/railings/extensions/class.rb
|
82
|
+
- lib/railings/extensions/extendable.rb
|
83
|
+
- lib/railings/extensions/hash.rb
|
84
|
+
- lib/railings/extensions/string.rb
|
85
|
+
- lib/railings/filterable.rb
|
86
|
+
- lib/railings/layout_helper.rb
|
87
|
+
- lib/railings/routing_helper.rb
|
88
|
+
- lib/railings/version.rb
|
89
|
+
- railings.gemspec
|
90
|
+
- spec/extensions/class_spec.rb
|
91
|
+
- spec/extensions/hash_spec.rb
|
92
|
+
- spec/extensions/string_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://rubygems.org/gems/railings
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 1
|
118
|
+
- 3
|
119
|
+
- 6
|
120
|
+
version: 1.3.6
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: railings
|
124
|
+
rubygems_version: 1.3.7
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Ruby and Rails extensions
|
128
|
+
test_files: []
|
129
|
+
|