whitelabel 0.3.0 → 0.4.0
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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +2 -5
- data/Gemfile.lock +23 -25
- data/README.md +25 -11
- data/lib/whitelabel/handler.rb +48 -0
- data/lib/whitelabel/version.rb +1 -1
- data/lib/whitelabel.rb +2 -44
- data/spec/spec_helper.rb +1 -2
- data/whitelabel.gemspec +3 -3
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f61691304e1cb815aa17c09be9c73713121359c93ec986c22f6bc97748ea349b
|
4
|
+
data.tar.gz: c46cb296325e46573e52452907b5e2fde43b66602100f453bb76f5866bf93399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b6b08afa04817c48be69b07ee7c6d7cdabead8b68fed3f6ec9fd18778a7ec8920104f72bf5cf0f7cc408d779bb16b9a883508a6ca906aaa1ab3ceffb116c86c
|
7
|
+
data.tar.gz: c08269c92c5273b720b00f12664a4bfa2944e017fb0a745ae555de0e7785de34bad1fb9012fe7e2908429f509ecb416c5b2444f090663e46fea1f6f03df2e92b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.2.0
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,38 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whitelabel (0.
|
4
|
+
whitelabel (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
diff-lcs (1.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rspec-expectations (~> 3.1.0)
|
20
|
-
rspec-mocks (~> 3.1.0)
|
21
|
-
rspec-core (3.1.7)
|
22
|
-
rspec-support (~> 3.1.0)
|
23
|
-
rspec-expectations (3.1.2)
|
9
|
+
byebug (11.1.3)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
rake (13.0.6)
|
12
|
+
rspec (3.12.0)
|
13
|
+
rspec-core (~> 3.12.0)
|
14
|
+
rspec-expectations (~> 3.12.0)
|
15
|
+
rspec-mocks (~> 3.12.0)
|
16
|
+
rspec-core (3.12.1)
|
17
|
+
rspec-support (~> 3.12.0)
|
18
|
+
rspec-expectations (3.12.2)
|
24
19
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
rspec-support (~> 3.12.0)
|
21
|
+
rspec-mocks (3.12.5)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.12.0)
|
24
|
+
rspec-support (3.12.0)
|
30
25
|
|
31
26
|
PLATFORMS
|
32
|
-
|
27
|
+
arm64-darwin-21
|
33
28
|
|
34
29
|
DEPENDENCIES
|
35
|
-
|
36
|
-
rake (
|
37
|
-
rspec (
|
30
|
+
byebug (> 11.0)
|
31
|
+
rake (> 11.3)
|
32
|
+
rspec (> 3.1)
|
38
33
|
whitelabel!
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.4.10
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/phoet/whitelabel)
|
2
|
+
|
1
3
|
# Whitelabel
|
2
4
|
|
3
5
|
This gem helps you providing whitelabel functionality in your application.
|
@@ -6,15 +8,21 @@ This gem helps you providing whitelabel functionality in your application.
|
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'whitelabel'
|
13
|
+
```
|
10
14
|
|
11
15
|
And then execute:
|
12
16
|
|
13
|
-
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
14
20
|
|
15
21
|
Or install it yourself as:
|
16
22
|
|
17
|
-
|
23
|
+
```bash
|
24
|
+
gem install whitelabel
|
25
|
+
```
|
18
26
|
|
19
27
|
## Usage
|
20
28
|
|
@@ -22,20 +30,25 @@ You can start with a pretty simple, file driven whitelabel configuration.
|
|
22
30
|
|
23
31
|
All you need is a config file:
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
```yaml
|
34
|
+
# config/whitelabel.yaml
|
35
|
+
---
|
36
|
+
- !ruby/struct:YourLabelClass
|
37
|
+
label_id: "white"
|
38
|
+
some_config: "for your application"
|
39
|
+
```
|
30
40
|
|
31
41
|
and an initializer:
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
```ruby
|
44
|
+
# config/initializers/whitelabel.rb
|
45
|
+
YourLabelClass = Struct.new :label_id, :some_config
|
46
|
+
Whitelabel.from_file Rails.root.join("config/whitelabel.yml")
|
47
|
+
```
|
36
48
|
|
37
49
|
Whitelabel works the same way I18n does, just set it up in your ApplicationController:
|
38
50
|
|
51
|
+
```ruby
|
39
52
|
# app/controllers/application_controller.rb
|
40
53
|
before_filter :switch_label
|
41
54
|
|
@@ -44,6 +57,7 @@ Whitelabel works the same way I18n does, just set it up in your ApplicationContr
|
|
44
57
|
redirect_to(labels_url(subdomain: false), alert: "Please select a Label!")
|
45
58
|
end
|
46
59
|
end
|
60
|
+
```
|
47
61
|
|
48
62
|
This example uses the subdomain to determine which label should be active, but you can implement whatever you like here.
|
49
63
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Whitelabel
|
2
|
+
module Handler
|
3
|
+
attr_accessor :labels
|
4
|
+
|
5
|
+
def from_file(path)
|
6
|
+
@labels = File.open(path) { |file| YAML.unsafe_load(file) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def label
|
10
|
+
Thread.current[:whitelabel]
|
11
|
+
end
|
12
|
+
|
13
|
+
def label=(label)
|
14
|
+
Thread.current[:whitelabel] = label
|
15
|
+
end
|
16
|
+
|
17
|
+
def label_for(pattern, identifier = :label_id)
|
18
|
+
self.label = find_label(pattern, identifier)
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_label(pattern, identifier = :label_id)
|
22
|
+
@labels.find { |label| label.send(identifier) =~ /^#{pattern}$/ }
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_label(tmp = nil)
|
26
|
+
if tmp
|
27
|
+
current_label = self.label
|
28
|
+
self.label = tmp
|
29
|
+
end
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
self.label = current_label if current_label
|
33
|
+
end
|
34
|
+
|
35
|
+
def each_label(&block)
|
36
|
+
labels.map { |label| with_label(label, &block) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def [](accessor)
|
40
|
+
raise "set a label before calling '#{accessor}'" if self.label.nil?
|
41
|
+
self.label.send :"#{accessor}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def reset!
|
45
|
+
Thread.current[:whitelabel] = nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/whitelabel/version.rb
CHANGED
data/lib/whitelabel.rb
CHANGED
@@ -1,52 +1,10 @@
|
|
1
1
|
require "whitelabel/version"
|
2
|
+
require "whitelabel/handler"
|
2
3
|
|
3
4
|
require "yaml"
|
4
5
|
|
5
6
|
module Whitelabel
|
6
7
|
class << self
|
7
|
-
|
8
|
-
|
9
|
-
def from_file(path)
|
10
|
-
@labels = File.open(path) { |file| YAML.load(file) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def label
|
14
|
-
Thread.current[:whitelabel]
|
15
|
-
end
|
16
|
-
|
17
|
-
def label=(label)
|
18
|
-
Thread.current[:whitelabel] = label
|
19
|
-
end
|
20
|
-
|
21
|
-
def label_for(pattern, identifier=:label_id)
|
22
|
-
self.label = find_label(pattern, identifier)
|
23
|
-
end
|
24
|
-
|
25
|
-
def find_label(pattern, identifier=:label_id)
|
26
|
-
@labels.find { |label| label.send(identifier) =~ /^#{pattern}$/ }
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_label(tmp=nil)
|
30
|
-
if tmp
|
31
|
-
current_label = self.label
|
32
|
-
self.label = tmp
|
33
|
-
end
|
34
|
-
yield
|
35
|
-
ensure
|
36
|
-
self.label = current_label if current_label
|
37
|
-
end
|
38
|
-
|
39
|
-
def each_label(&block)
|
40
|
-
labels.map { |label| with_label(label, &block) }
|
41
|
-
end
|
42
|
-
|
43
|
-
def [](accessor)
|
44
|
-
raise "set a label before calling '#{accessor}'" if self.label.nil?
|
45
|
-
self.label.send :"#{accessor}"
|
46
|
-
end
|
47
|
-
|
48
|
-
def reset!
|
49
|
-
Thread.current[:whitelabel] = nil
|
50
|
-
end
|
8
|
+
include Whitelabel::Handler
|
51
9
|
end
|
52
10
|
end
|
data/spec/spec_helper.rb
CHANGED
data/whitelabel.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.version = Whitelabel::VERSION
|
16
16
|
|
17
|
-
gem.add_development_dependency('rspec', '
|
18
|
-
gem.add_development_dependency('
|
19
|
-
gem.add_development_dependency('rake', '
|
17
|
+
gem.add_development_dependency('rspec', '> 3.1')
|
18
|
+
gem.add_development_dependency('byebug', '> 11.0')
|
19
|
+
gem.add_development_dependency('rake', '> 11.3')
|
20
20
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whitelabel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Schröder
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '11.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '11.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '11.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '11.3'
|
55
55
|
description: This gem helps you providing whitelabel functionality in your application
|
56
56
|
email:
|
57
57
|
- phoetmail@googlemail.com
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
71
|
- lib/whitelabel.rb
|
72
|
+
- lib/whitelabel/handler.rb
|
72
73
|
- lib/whitelabel/version.rb
|
73
74
|
- spec/fixtures/whitelabel.yml
|
74
75
|
- spec/lib/whitelabel_spec.rb
|
@@ -77,7 +78,7 @@ files:
|
|
77
78
|
homepage: https://github.com/phoet/whitelabel
|
78
79
|
licenses: []
|
79
80
|
metadata: {}
|
80
|
-
post_install_message:
|
81
|
+
post_install_message:
|
81
82
|
rdoc_options: []
|
82
83
|
require_paths:
|
83
84
|
- lib
|
@@ -92,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
96
|
+
rubygems_version: 3.4.10
|
97
|
+
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: This gem helps you providing whitelabel functionality in your application
|
100
100
|
test_files:
|