status_tag 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/status_tag.rb +5 -4
- data/lib/status_tag/choice.rb +7 -7
- data/lib/status_tag/presenter.rb +27 -4
- data/lib/status_tag/version.rb +1 -1
- metadata +1 -5
- data/mtm_profile/blazer_presenters/fit_status_presenter.rb +0 -17
- data/mtm_profile/blazer_presenters/measurement_status_presenter.rb +0 -18
- data/mtm_profile_presenters/fit_status_presenter.rb +0 -17
- data/mtm_profile_presenters/measurement_status_presenter.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291eb59983500803ea263a4778fe89dad8bbe5d2
|
4
|
+
data.tar.gz: afd44c1c01e1bfff6fc52527d14e7c692bc0ffe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a25ffef8e4993d0d6e27c3a36bb33ae11202fdb802feac0379bee4b36b25e7661a1f760e380ba4abae1021d10f955aa7ca98d2cf1ba2f9f2db14b6a96f602f0
|
7
|
+
data.tar.gz: 43ddd21610f2b809dbe5d50e5f7721f81196762af031e9f1f228a85173a7f1cfe8e8f49b437fa13ed440fa382e2fc3d9de929484e274ff0c97554adc1d8edc27
|
data/lib/status_tag.rb
CHANGED
@@ -38,14 +38,15 @@ module StatusTag
|
|
38
38
|
# However, does not currently support object being multiple records like Rails' `content_tag_for` does
|
39
39
|
def self.status_tag_signature_for(tag, object, prefix = false, options = nil)
|
40
40
|
presenter = status_tag_presenter(object: object, aspect: prefix)
|
41
|
-
|
42
|
-
|
41
|
+
presenter.decide
|
42
|
+
text = presenter.text
|
43
|
+
return text, nil if presenter.noop?
|
43
44
|
options ||= {}
|
44
45
|
options[:class] = Array(options[:class])
|
45
46
|
options[:class].concat(Array(presenter.class.css_class(object, prefix)))
|
46
|
-
options[:class] <<
|
47
|
+
options[:class] << presenter.css_class if presenter.css_class
|
47
48
|
options[:class] = options[:class].join(" ")
|
48
|
-
return
|
49
|
+
return text, [tag, presenter.object, presenter.aspect, options]
|
49
50
|
end
|
50
51
|
|
51
52
|
end
|
data/lib/status_tag/choice.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module StatusTag
|
2
2
|
class Choice
|
3
3
|
|
4
|
-
attr_accessor :name,
|
5
|
-
|
6
|
-
:
|
7
|
-
:text,
|
8
|
-
:noop
|
4
|
+
attr_accessor :name, # the method that will be called on the object to determine if this is the correct choice
|
5
|
+
# when nil, indicates this choice is the catch-all, naked `else`
|
6
|
+
:css_class, # css_class is for the CSS class that will differentiate each specific label type (color, size, etc)
|
7
|
+
:text, # text is the what the label says in the view port
|
8
|
+
:noop # designates a `name` as taking up space, but not rendering a tag, in the ordered set to tumble the results.
|
9
9
|
|
10
|
-
def initialize(name: nil,
|
10
|
+
def initialize(name: nil, css_class: "", text: "", noop: false)
|
11
11
|
@name = name
|
12
|
-
@
|
12
|
+
@css_class = css_class
|
13
13
|
@text = text
|
14
14
|
@noop = !!noop
|
15
15
|
end
|
data/lib/status_tag/presenter.rb
CHANGED
@@ -20,12 +20,15 @@ module StatusTag
|
|
20
20
|
DECIDE_ON = :object # or :self, which will send the messages to the presenter class
|
21
21
|
# (which has an internal reference to object) and would allow more complicated logic that
|
22
22
|
# pertains to the view, not the model.
|
23
|
+
CHOICE_ON = :object # or :self, which will send the messages to the presenter class
|
24
|
+
# (which has an internal reference to object) and would allow more complicated logic that
|
25
|
+
# pertains to the view, not the model.
|
23
26
|
|
24
27
|
attr_accessor :object, # e.g. an instance of the User class
|
25
28
|
:aspect # e.g. "state", "status" or some other descriptive name for this particular status tag
|
26
29
|
# Defaults to nil, so by default there is only one StatusTag presenter allowed per object class,
|
27
30
|
# as the aspect provides a namespace for additional presenters.
|
28
|
-
attr_reader :decider
|
31
|
+
attr_reader :decider, :choice
|
29
32
|
|
30
33
|
def initialize(object:, aspect: nil)
|
31
34
|
@object = object
|
@@ -34,13 +37,33 @@ module StatusTag
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def decide
|
37
|
-
if (self.class)::DECIDE_ON == :object
|
38
|
-
|
40
|
+
@choice = if (self.class)::DECIDE_ON == :object
|
41
|
+
decider.decide(object)
|
42
|
+
else
|
43
|
+
decider.decide(self)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def text
|
48
|
+
return "" unless choice
|
49
|
+
if choice.text.is_a?(Symbol)
|
50
|
+
receiver = (self.class)::CHOICE_ON == :object ? object : self
|
51
|
+
receiver.send(choice.text)
|
39
52
|
else
|
40
|
-
|
53
|
+
choice.text
|
41
54
|
end
|
42
55
|
end
|
43
56
|
|
57
|
+
def noop?
|
58
|
+
return true unless choice
|
59
|
+
choice.noop?
|
60
|
+
end
|
61
|
+
|
62
|
+
def css_class
|
63
|
+
return nil unless choice
|
64
|
+
choice.css_class
|
65
|
+
end
|
66
|
+
|
44
67
|
# An alternative to overriding the constant in subclasses is to override this method.
|
45
68
|
# If you override, do not change the signature.
|
46
69
|
# The params enable the ordered choices to be derived dynamically for your needs, but are not used by default.
|
data/lib/status_tag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: status_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
@@ -91,10 +91,6 @@ files:
|
|
91
91
|
- lib/status_tag/presenter.rb
|
92
92
|
- lib/status_tag/utils.rb
|
93
93
|
- lib/status_tag/version.rb
|
94
|
-
- mtm_profile/blazer_presenters/fit_status_presenter.rb
|
95
|
-
- mtm_profile/blazer_presenters/measurement_status_presenter.rb
|
96
|
-
- mtm_profile_presenters/fit_status_presenter.rb
|
97
|
-
- mtm_profile_presenters/measurement_status_presenter.rb
|
98
94
|
- status_tag.gemspec
|
99
95
|
homepage: http://github.com/pboling/status_tag
|
100
96
|
licenses: []
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module StatusTag
|
2
|
-
module MtmProfilePresenters
|
3
|
-
class FitStatusPresenter < Presenter
|
4
|
-
ORDERED_CHOICES = [
|
5
|
-
StatusTag::Choice.new(name: "new?", klass: "label-default-important", text: "B New"),
|
6
|
-
StatusTag::Choice.new(name: "bad_fit?", klass: "label-default-warning", text: "B Bad Fit"),
|
7
|
-
StatusTag::Choice.new(name: "confirmed?", klass: "label-default-success", text: "B Fit Confirmed"),
|
8
|
-
StatusTag::Choice.new(name: "pending?", noop: true), # TODO: Why do we not want pending to display?
|
9
|
-
StatusTag::Choice.new(name: nil, klass: "label-default-warning", text: "B Fit Unknown"),
|
10
|
-
]
|
11
|
-
CSS_CLASS = [
|
12
|
-
"label",
|
13
|
-
"label-default"
|
14
|
-
]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module StatusTag
|
2
|
-
module MtmProfilePresenters
|
3
|
-
class MeasurementStatusPresenter < Presenter
|
4
|
-
ORDERED_CHOICES = [
|
5
|
-
StatusTag::Choice.new(name: "bad?", klass: "label-default-warning", text: "B Bad Measure"),
|
6
|
-
StatusTag::Choice.new(name: "good?", klass: "label-default-success", text: "B Good Measure"),
|
7
|
-
StatusTag::Choice.new(name: "waiting_approval?", klass: "label-default-important", text: "B Pending Measure"),
|
8
|
-
StatusTag::Choice.new(name: "on_hold?", klass: "label-default-warning", text: "B On Hold"),
|
9
|
-
StatusTag::Choice.new(name: "not_measured?", klass: "label-default-important", text: "B Not Measured"),
|
10
|
-
StatusTag::Choice.new(name: nil, klass: "label-default-warning", text: "B Measure Unknown"),
|
11
|
-
]
|
12
|
-
CSS_CLASS = [
|
13
|
-
"label",
|
14
|
-
"label-default"
|
15
|
-
]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module StatusTag
|
2
|
-
module MtmProfilePresenters
|
3
|
-
class FitStatusPresenter < Presenter
|
4
|
-
ORDERED_CHOICES = [
|
5
|
-
StatusTag::Choice.new(name: "new?", klass: "label-default-important", text: "New"),
|
6
|
-
StatusTag::Choice.new(name: "bad_fit?", klass: "label-default-warning", text: "Bad Fit"),
|
7
|
-
StatusTag::Choice.new(name: "confirmed?", klass: "label-default-success", text: "Fit Confirmed"),
|
8
|
-
StatusTag::Choice.new(name: "pending?", noop: true), # TODO: Why do we not want pending to display?
|
9
|
-
StatusTag::Choice.new(name: nil, klass: "label-default-warning", text: "Fit Unknown"),
|
10
|
-
]
|
11
|
-
CSS_CLASS = [
|
12
|
-
"label",
|
13
|
-
"label-default"
|
14
|
-
]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module StatusTag
|
2
|
-
module MtmProfilePresenters
|
3
|
-
class MeasurementStatusPresenter < Presenter
|
4
|
-
ORDERED_CHOICES = [
|
5
|
-
StatusTag::Choice.new(name: "bad?", klass: "label-default-warning", text: "Bad Measure"),
|
6
|
-
StatusTag::Choice.new(name: "good?", klass: "label-default-success", text: "Good Measure"),
|
7
|
-
StatusTag::Choice.new(name: "waiting_approval?", klass: "label-default-important", text: "Pending Measure"),
|
8
|
-
StatusTag::Choice.new(name: "on_hold?", klass: "label-default-warning", text: "On Hold"),
|
9
|
-
StatusTag::Choice.new(name: "not_measured?", klass: "label-default-important", text: "Not Measured"),
|
10
|
-
StatusTag::Choice.new(name: nil, klass: "label-default-warning", text: "Measure Unknown"),
|
11
|
-
]
|
12
|
-
CSS_CLASS = [
|
13
|
-
"label",
|
14
|
-
"label-default"
|
15
|
-
]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|