site_framework 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/db/migrate/20160216141442_add_default_template_to_sites.rb +9 -0
- data/lib/site_framework/action_controller/base.rb +18 -0
- data/lib/site_framework/routing/default_constraint.rb +12 -0
- data/lib/site_framework/routing/site_constraint.rb +14 -0
- data/lib/site_framework/routing/sites.rb +1 -1
- data/lib/site_framework/version.rb +1 -1
- data/lib/site_framework.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62be8f127063701148dbaea74352fe781c1f78a2
|
4
|
+
data.tar.gz: 39437c595f044e4a4ef5d6733b5178fa678b464c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e3ca92919e98c4db6a46a08aaafc54045ef7ddf5192b2c74389b1222510f729b57fe418e9f138262ae7964e40f3bc9d001054af753dd8a4ac2824326257198
|
7
|
+
data.tar.gz: 8a51d6565a1b2725fa0bcad57cab31f213119c7c12d235a5728c6dd9eab37c14a5673c23a2dd886b28d672232cd820c5e2e60debc4f0c10b26e1827f0671ee1a
|
data/README.md
CHANGED
@@ -82,6 +82,23 @@ end
|
|
82
82
|
|
83
83
|
**Personally I prefer this (B) option since it's more Railish.**
|
84
84
|
|
85
|
+
### Access Current Site and Domain in Controllers
|
86
|
+
After installing `site_framework` you'll have `site`, `domain` and `domain_name` methods
|
87
|
+
on your `request` objects to access the respected models. But if current request belongs
|
88
|
+
to default site the return value of these methods would be `nil`
|
89
|
+
|
90
|
+
### Access Current Site/Domain elsewhre
|
91
|
+
You can access to current `site`, `domain` and `domain_name` via `SiteFramework::CurrentState` object
|
92
|
+
every where just like this:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
SiteFramework::CurrentState.instance.site
|
96
|
+
SiteFramework::CurrentState.instance.domain
|
97
|
+
SiteFramework::CurrentState.instance.domain_name
|
98
|
+
```
|
99
|
+
|
100
|
+
In case of default site these methods will return `nil`
|
101
|
+
|
85
102
|
### Model Concern
|
86
103
|
**SiteFramework** provides an **ActiveSupport** concern which transparently
|
87
104
|
makes your models aware of the current **Site** and **Domain**. By includeing
|
@@ -93,6 +110,13 @@ All you have to do is to open there models and include the given concern.
|
|
93
110
|
|
94
111
|
Piece of cake. right?
|
95
112
|
|
113
|
+
### Default template
|
114
|
+
Since `v4.0` site model contains a field aka `default_template` which is blank by default.
|
115
|
+
By default if current request does not belongs to default site and `default_template` is not
|
116
|
+
blank, **site framework** will prepend the `default_template` to `view_path` of your application.
|
117
|
+
|
118
|
+
By this feature each site can have their own set of views.
|
119
|
+
|
96
120
|
## Contributing
|
97
121
|
|
98
122
|
1. Fork it
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ActionController::Base.class_eval do
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def set_template_path
|
6
|
+
unless request.site
|
7
|
+
# We are in site namespace
|
8
|
+
unless request.site.default_template.blank?
|
9
|
+
prepend_view_path[request.site.default_template]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
ActionController::Base.instance_eval do
|
17
|
+
before_action :set_template_path
|
18
|
+
end
|
@@ -19,6 +19,18 @@ class SiteFramework::Routing::DefaultConstraint
|
|
19
19
|
SiteFramework::CurrentState.instance.domain = nil
|
20
20
|
SiteFramework::CurrentState.instance.site = nil
|
21
21
|
|
22
|
+
request.instance_eval do
|
23
|
+
def site
|
24
|
+
end
|
25
|
+
|
26
|
+
def domain
|
27
|
+
end
|
28
|
+
|
29
|
+
def domamin_name
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
22
34
|
true
|
23
35
|
else
|
24
36
|
logger.info("Domain name '#{request.host}' does not match with any exist domains")
|
@@ -25,6 +25,20 @@ class SiteFramework::Routing::SiteConstraint
|
|
25
25
|
setup(domain_obj)
|
26
26
|
initialize_site_default_state
|
27
27
|
|
28
|
+
request.instance_eval do
|
29
|
+
def site
|
30
|
+
domain_obj.site
|
31
|
+
end
|
32
|
+
|
33
|
+
def domain
|
34
|
+
domain_obj.domain
|
35
|
+
end
|
36
|
+
|
37
|
+
def domamin_name
|
38
|
+
domain_obj.domain_name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
true
|
29
43
|
else
|
30
44
|
logger.info("Domain name '#{request.host}' does not match with any exist domains")
|
data/lib/site_framework.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'site_framework/current_state'
|
2
1
|
require 'site_framework/helpers'
|
3
2
|
|
4
3
|
# Main module of `site_framework` gem
|
@@ -10,11 +9,14 @@ module SiteFramework
|
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
12
|
+
require 'site_framework/current_state'
|
13
13
|
require 'site_framework/engine'
|
14
14
|
require 'site_framework/railtie'
|
15
15
|
require 'site_framework/orm'
|
16
16
|
require 'site_framework/routing'
|
17
17
|
require 'site_framework/action_dispatch'
|
18
|
+
require 'site_framework/action_controller/base'
|
19
|
+
|
18
20
|
|
19
21
|
case SiteFramework::ORM.current_orm
|
20
22
|
when 'active_record'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Rahmani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -69,7 +69,9 @@ files:
|
|
69
69
|
- config/routes.rb
|
70
70
|
- db/migrate/20140118200201_create_site_framework_domains.rb
|
71
71
|
- db/migrate/20140303141448_create_site_framework_sites.rb
|
72
|
+
- db/migrate/20160216141442_add_default_template_to_sites.rb
|
72
73
|
- lib/site_framework.rb
|
74
|
+
- lib/site_framework/action_controller/base.rb
|
73
75
|
- lib/site_framework/action_dispatch.rb
|
74
76
|
- lib/site_framework/active_record/concerns.rb
|
75
77
|
- lib/site_framework/active_record/migration.rb
|