almost-happy 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/Rakefile +1 -0
- data/almost-happy.gemspec +7 -4
- data/lib/almost_happy/convertable.rb +11 -11
- data/lib/almost_happy/publishable.rb +18 -6
- data/lib/almost_happy/scopeable.rb +11 -7
- data/lib/almost_happy.rb +8 -8
- metadata +36 -7
data/README.md
CHANGED
@@ -33,8 +33,9 @@ using the specific format etc.
|
|
33
33
|
|
34
34
|
When a model is marked as publishable, it provides the following instance methods:
|
35
35
|
|
36
|
-
* `published?` - returns a boolean indicating if it's
|
36
|
+
* `published?` - returns a boolean indicating if it's published. also aliased to `published` for forms.
|
37
37
|
* `publish!` - mark the post as published right now.
|
38
|
+
* `published=(value)` - mark items as published in forms.
|
38
39
|
|
39
40
|
And, the following class methods:
|
40
41
|
|
data/Rakefile
CHANGED
data/almost-happy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{almost-happy}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-07}
|
13
13
|
s.description = %q{Helpers, convertors etc for Rails 3 to make page / post models for simple cases simple}
|
14
14
|
s.email = %q{sutto@sutto.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.homepage = %q{http://github.com/Sutto/almost-happy}
|
39
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
40
40
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.3.
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
42
|
s.summary = %q{Simple tools for AR + Rails 3 to help make managing your content easy}
|
43
43
|
s.test_files = [
|
44
44
|
"test/helper.rb",
|
@@ -49,17 +49,19 @@ Gem::Specification.new do |s|
|
|
49
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
50
|
s.specification_version = 3
|
51
51
|
|
52
|
-
if Gem::Version.new(Gem::
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
53
|
s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0.beta3"])
|
54
54
|
s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
|
55
55
|
s.add_runtime_dependency(%q<rdiscount>, [">= 0"])
|
56
56
|
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<open4>, [">= 0"])
|
57
58
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
59
|
else
|
59
60
|
s.add_dependency(%q<activerecord>, [">= 3.0.0.beta3"])
|
60
61
|
s.add_dependency(%q<RedCloth>, [">= 0"])
|
61
62
|
s.add_dependency(%q<rdiscount>, [">= 0"])
|
62
63
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
64
|
+
s.add_dependency(%q<open4>, [">= 0"])
|
63
65
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
66
|
end
|
65
67
|
else
|
@@ -67,6 +69,7 @@ Gem::Specification.new do |s|
|
|
67
69
|
s.add_dependency(%q<RedCloth>, [">= 0"])
|
68
70
|
s.add_dependency(%q<rdiscount>, [">= 0"])
|
69
71
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
72
|
+
s.add_dependency(%q<open4>, [">= 0"])
|
70
73
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
74
|
end
|
72
75
|
end
|
@@ -3,37 +3,37 @@ require 'set'
|
|
3
3
|
module AlmostHappy
|
4
4
|
module Convertable
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
included do
|
8
8
|
class_attribute :convertable_fields
|
9
9
|
self.convertable_fields = Set.new
|
10
10
|
before_save :process_convertable_sections
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
module ClassMethods
|
14
|
-
|
14
|
+
|
15
15
|
def validate_convertable_format
|
16
16
|
validates_presence_of :format
|
17
17
|
validates_with AlmostHappy::FormatValidator
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
module InstanceMethods
|
23
|
-
|
23
|
+
|
24
24
|
protected
|
25
|
-
|
25
|
+
|
26
26
|
def process_convertable_sections
|
27
27
|
convertable_fields.each do |field|
|
28
28
|
AlmostHappy::Convertor.new(self, field).render if should_render?(field)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def should_render?(field)
|
33
33
|
send(:"rendered_#{field}").blank? || format_changed? || send(:"#{field}_changed?")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
@@ -1,18 +1,30 @@
|
|
1
1
|
module AlmostHappy
|
2
2
|
module Publishable
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
4
|
+
|
5
5
|
module InstanceMethods
|
6
|
-
|
6
|
+
|
7
|
+
def published=(value)
|
8
|
+
# Sets the attribute, uses the ar conversion method)
|
9
|
+
if defined?(ActiveRecord)
|
10
|
+
value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
|
11
|
+
else
|
12
|
+
value = value.present? && !["0", "false"].include?(value.to_s)
|
13
|
+
end
|
14
|
+
real_value = value ? Time.now : nil
|
15
|
+
self.published_at = value
|
16
|
+
end
|
17
|
+
|
7
18
|
def published?
|
8
19
|
published_at.present? && published_at <= Time.now
|
9
20
|
end
|
10
|
-
|
21
|
+
alias published published?
|
22
|
+
|
11
23
|
def publish!
|
12
24
|
update_attribute :published_at, Time.now
|
13
25
|
end
|
14
|
-
|
26
|
+
|
15
27
|
end
|
16
|
-
|
28
|
+
|
17
29
|
end
|
18
|
-
end
|
30
|
+
end
|
@@ -1,22 +1,26 @@
|
|
1
1
|
module AlmostHappy
|
2
2
|
module Scopeable
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
4
|
+
|
5
5
|
module ClassMethods
|
6
|
-
|
6
|
+
|
7
7
|
def published
|
8
8
|
where 'published_at IS NOT NULL AND published_at <= ?', Time.now
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
def unpublished
|
12
|
+
where 'published_at IS NULL OR published_at > ?', Time.now
|
13
|
+
end
|
14
|
+
|
11
15
|
def ordered
|
12
16
|
order 'published_at DESC'
|
13
17
|
end
|
14
|
-
|
18
|
+
|
15
19
|
def ordered_for_preview
|
16
20
|
order '(published_at IS NULL) DESC, published_at DESC'
|
17
21
|
end
|
18
|
-
|
22
|
+
|
19
23
|
end
|
20
|
-
|
24
|
+
|
21
25
|
end
|
22
|
-
end
|
26
|
+
end
|
data/lib/almost_happy.rb
CHANGED
@@ -4,19 +4,19 @@ require 'active_support/core_ext/class/attribute'
|
|
4
4
|
require 'active_support/concern'
|
5
5
|
|
6
6
|
module AlmostHappy
|
7
|
-
VERSION = '0.
|
8
|
-
|
7
|
+
VERSION = '0.2.0'.freeze
|
8
|
+
|
9
9
|
extend ActiveSupport::Autoload
|
10
|
-
|
10
|
+
|
11
11
|
autoload :ActiveRecordMixin
|
12
|
-
|
12
|
+
|
13
13
|
autoload :Convertor
|
14
14
|
autoload :FormatValidator
|
15
|
-
|
15
|
+
|
16
16
|
autoload :Convertable
|
17
17
|
autoload :Scopeable
|
18
18
|
autoload :Publishable
|
19
|
-
|
19
|
+
|
20
20
|
::ActiveRecord::Base.send :include, ActiveRecordMixin if defined?(::ActiveRecord::Base)
|
21
|
-
|
22
|
-
end
|
21
|
+
|
22
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: almost-happy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Darcy Laycock
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-07 00:00:00 +08:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activerecord
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: -1848230021
|
27
30
|
segments:
|
28
31
|
- 3
|
29
32
|
- 0
|
@@ -36,9 +39,11 @@ dependencies:
|
|
36
39
|
name: RedCloth
|
37
40
|
prerelease: false
|
38
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
39
43
|
requirements:
|
40
44
|
- - ">="
|
41
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
42
47
|
segments:
|
43
48
|
- 0
|
44
49
|
version: "0"
|
@@ -48,9 +53,11 @@ dependencies:
|
|
48
53
|
name: rdiscount
|
49
54
|
prerelease: false
|
50
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
54
61
|
segments:
|
55
62
|
- 0
|
56
63
|
version: "0"
|
@@ -60,26 +67,44 @@ dependencies:
|
|
60
67
|
name: nokogiri
|
61
68
|
prerelease: false
|
62
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
63
71
|
requirements:
|
64
72
|
- - ">="
|
65
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
66
75
|
segments:
|
67
76
|
- 0
|
68
77
|
version: "0"
|
69
78
|
type: :runtime
|
70
79
|
version_requirements: *id004
|
71
80
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
81
|
+
name: open4
|
73
82
|
prerelease: false
|
74
83
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
75
85
|
requirements:
|
76
86
|
- - ">="
|
77
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
78
89
|
segments:
|
79
90
|
- 0
|
80
91
|
version: "0"
|
81
|
-
type: :
|
92
|
+
type: :runtime
|
82
93
|
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: shoulda
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
type: :development
|
107
|
+
version_requirements: *id006
|
83
108
|
description: Helpers, convertors etc for Rails 3 to make page / post models for simple cases simple
|
84
109
|
email: sutto@sutto.net
|
85
110
|
executables: []
|
@@ -117,23 +142,27 @@ rdoc_options:
|
|
117
142
|
require_paths:
|
118
143
|
- lib
|
119
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
120
146
|
requirements:
|
121
147
|
- - ">="
|
122
148
|
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
123
150
|
segments:
|
124
151
|
- 0
|
125
152
|
version: "0"
|
126
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
127
155
|
requirements:
|
128
156
|
- - ">="
|
129
157
|
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
130
159
|
segments:
|
131
160
|
- 0
|
132
161
|
version: "0"
|
133
162
|
requirements: []
|
134
163
|
|
135
164
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.3.
|
165
|
+
rubygems_version: 1.3.7
|
137
166
|
signing_key:
|
138
167
|
specification_version: 3
|
139
168
|
summary: Simple tools for AR + Rails 3 to help make managing your content easy
|