wnm_support 0.0.3 → 0.0.4
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.
- data/README.md +60 -0
- data/changelog.md +9 -0
- data/lib/wnm_support/active_record_ext/view_helpers.rb +1 -1
- data/lib/wnm_support/railtie.rb +21 -0
- data/lib/wnm_support/version.rb +1 -1
- data/lib/wnm_support/view_helpers/bool_to_human.rb +15 -0
- data/lib/wnm_support/view_helpers/youtube.rb +18 -0
- data/lib/wnm_support.rb +4 -7
- data/spec/wnm_support/activer_record_ext/destroy_validation_spec.rb +2 -0
- data/spec/wnm_support/activer_record_ext/multi_action_spec.rb +2 -0
- data/spec/wnm_support/activer_record_ext/{mysql_order_by_filed_spec.rb → mysql_order_by_field_spec.rb} +2 -0
- data/spec/wnm_support/activer_record_ext/mysql_truncate_spec.rb +2 -0
- data/spec/wnm_support/activer_record_ext/view_helpers_spec.rb +2 -0
- data/spec/wnm_support/view_helpers/bool_to_human_spec.rb +45 -0
- data/spec/wnm_support/view_helpers/youtube_spec.rb +49 -0
- data/wnm_support.gemspec +7 -5
- metadata +34 -11
data/README.md
CHANGED
@@ -35,6 +35,66 @@ And then execute:
|
|
35
35
|
|
36
36
|
[1,2,3,4].halved # => [ [1, 2], [3, 4] ]
|
37
37
|
|
38
|
+
### Active record extensions
|
39
|
+
|
40
|
+
|
41
|
+
# helpers
|
42
|
+
class News < ActiveRecord::Base
|
43
|
+
attribute_accessor :name
|
44
|
+
|
45
|
+
def short_name
|
46
|
+
helpers.truncate(name) # you can access any view helper methods by calling helpers
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# truncate
|
51
|
+
News.truncate # destroy all records in database, without calling any callbacks
|
52
|
+
|
53
|
+
# order be field
|
54
|
+
News.create!(:name => "first") # id => 1
|
55
|
+
News.create!(:name => "second") # id => 2
|
56
|
+
News.create!(:name => "third") # id => 3
|
57
|
+
|
58
|
+
news = News.order_by_field(:id, [2, 3, 1])
|
59
|
+
news[0] # news record with id = 2
|
60
|
+
news[1] # news record with id = 3
|
61
|
+
news[2] # news record with id = 1
|
62
|
+
|
63
|
+
# multi actions
|
64
|
+
News.multi # => [:destroy] # every model has this method
|
65
|
+
|
66
|
+
# destroy validation
|
67
|
+
item = News.create!(:name => "new item")
|
68
|
+
item.destroy # => false
|
69
|
+
item.can_destroy? # => false
|
70
|
+
|
71
|
+
class News < ActiveRecord::Base
|
72
|
+
def can_destroy?
|
73
|
+
name == "new item"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
item = News.find_by_name("new item")
|
78
|
+
item.can_destroy? # => true
|
79
|
+
item.destroy # => true
|
80
|
+
|
81
|
+
### View helpers
|
82
|
+
|
83
|
+
bool_to_human true # => "yes"
|
84
|
+
bool_to_human false # => "no"
|
85
|
+
bool_to_human nil # => "no"
|
86
|
+
|
87
|
+
bool_to_human_with_empty true # => "yes"
|
88
|
+
bool_to_human_with_empty false # => "no"
|
89
|
+
bool_to_human_with_empty nil # => ""
|
90
|
+
|
91
|
+
|
92
|
+
url = youtube_prepare_url("youtube.com/watch?v=lala")
|
93
|
+
url # => "youtube.com/v/lala"
|
94
|
+
|
95
|
+
video = youtube_video(url, 100, 200)
|
96
|
+
video # => <object width='100' height='200'><param url='youtube.com/v/lala'>...</object>
|
97
|
+
|
38
98
|
## Contributing
|
39
99
|
|
40
100
|
1. Fork it
|
data/changelog.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 0.0.4
|
2
|
+
## added
|
3
|
+
* view helper BoolToHuman
|
4
|
+
* view helper Youtube
|
5
|
+
* railtie load view helpers
|
6
|
+
* railtie load active record extensions
|
7
|
+
* readme section for active record extensions
|
8
|
+
* readme section for active record view helpers
|
9
|
+
|
1
10
|
# 0.0.3
|
2
11
|
* add support for active record extentions
|
3
12
|
** DestroyValidation
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WnmSupport
|
2
|
+
module ViewHelpers
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "wnm_support.view_helpers" do
|
5
|
+
ActionView::Base.send :include, BoolToHuman
|
6
|
+
ActionView::Base.send :include, Youtube
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "wnm_support.active_record_ext" do
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
11
|
+
ActiveRecord::Base.send :include, WnmSupport::ActiveRecordExt::DestroyValidation
|
12
|
+
ActiveRecord::Base.send :include, WnmSupport::ActiveRecordExt::ViewHelpers
|
13
|
+
ActiveRecord::Base.send :include, WnmSupport::ActiveRecordExt::MultiAction
|
14
|
+
ActiveRecord::Base.send :include, WnmSupport::ActiveRecordExt::MysqlTruncate
|
15
|
+
ActiveRecord::Base.send :include, WnmSupport::ActiveRecordExt::MysqlOrderByField
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/wnm_support/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WnmSupport
|
2
|
+
module ViewHelpers
|
3
|
+
module BoolToHuman
|
4
|
+
def bool_to_human(value)
|
5
|
+
I18n.t(value == true ? "yes" : "no")
|
6
|
+
end
|
7
|
+
|
8
|
+
def bool_to_human_with_empty(value)
|
9
|
+
return "" if value.nil?
|
10
|
+
|
11
|
+
bool_to_human(value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WnmSupport
|
2
|
+
module ViewHelpers
|
3
|
+
module Youtube
|
4
|
+
def youtube_prepare_url(url)
|
5
|
+
url = url.to_s.gsub(/watch\?v=/, "v/").gsub(/&feature=.*/, "")
|
6
|
+
url << "?fs=1&hl=sk_SK"
|
7
|
+
url
|
8
|
+
end
|
9
|
+
|
10
|
+
def youtube_video(url, width, height)
|
11
|
+
url = url.to_s
|
12
|
+
width = width.to_i.to_s
|
13
|
+
height = height.to_i.to_s
|
14
|
+
'<object width="'+width+'" height="'+height+'"><param name="movie" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" allowscriptaccess="always" allowfullscreen="true"></embed></object>'.html_safe
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/wnm_support.rb
CHANGED
@@ -18,10 +18,7 @@ require "wnm_support/active_record_ext/multi_action"
|
|
18
18
|
require "wnm_support/active_record_ext/mysql_truncate"
|
19
19
|
require "wnm_support/active_record_ext/mysql_order_by_field"
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
include WnmSupport::ActiveRecordExt::MysqlTruncate
|
26
|
-
include WnmSupport::ActiveRecordExt::MysqlOrderByField
|
27
|
-
end
|
21
|
+
require "wnm_support/view_helpers/bool_to_human"
|
22
|
+
require "wnm_support/view_helpers/youtube"
|
23
|
+
|
24
|
+
require "wnm_support/railtie" if defined?(Rails)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class MyHelper
|
4
|
+
include WnmSupport::ViewHelpers::BoolToHuman
|
5
|
+
end
|
6
|
+
|
7
|
+
describe WnmSupport::ViewHelpers::BoolToHuman do
|
8
|
+
let(:helper) { MyHelper.new }
|
9
|
+
|
10
|
+
describe "bool_to_human" do
|
11
|
+
it "should call translate with yes if value is true" do
|
12
|
+
I18n.should_receive(:t).with("yes").and_return("yes")
|
13
|
+
|
14
|
+
helper.bool_to_human(true).should eq "yes"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should call translate with no if value is false" do
|
18
|
+
I18n.should_receive(:t).with("no").and_return("no")
|
19
|
+
|
20
|
+
helper.bool_to_human(false).should eq "no"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should call translate with no if value is nil" do
|
24
|
+
I18n.should_receive(:t).with("no").and_return("no")
|
25
|
+
|
26
|
+
helper.bool_to_human(nil).should eq "no"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "bool_to_human_with_empty" do
|
31
|
+
it "should return empty string if value is nil" do
|
32
|
+
helper.bool_to_human_with_empty(nil).should eq ""
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should call bool_to_human if value is true" do
|
36
|
+
helper.should_receive(:bool_to_human).with(true).and_return("yes")
|
37
|
+
helper.bool_to_human_with_empty(true).should eq "yes"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should call bool_to_human if value is false" do
|
41
|
+
helper.should_receive(:bool_to_human).with(false).and_return("no")
|
42
|
+
helper.bool_to_human_with_empty(false).should eq "no"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class MyHelper
|
4
|
+
include WnmSupport::ViewHelpers::Youtube
|
5
|
+
end
|
6
|
+
|
7
|
+
describe WnmSupport::ViewHelpers::Youtube do
|
8
|
+
let(:helper) { MyHelper.new }
|
9
|
+
|
10
|
+
describe "youtube_prepare_url" do
|
11
|
+
it "should change watch?v= to v/" do
|
12
|
+
url = "youtube.com/watch?v=lala"
|
13
|
+
helper.youtube_prepare_url(url).should include("youtube.com/v/lala")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should strip out useless params" do
|
17
|
+
url = "youtube.com/watch?v=lala&feature=hocico"
|
18
|
+
helper.youtube_prepare_url(url).should include("youtube.com")
|
19
|
+
helper.youtube_prepare_url(url).should_not include("&feature=")
|
20
|
+
helper.youtube_prepare_url(url).should_not include("hocico")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should add special params " do
|
24
|
+
url = "youtube.com/watch?v=lala"
|
25
|
+
helper.youtube_prepare_url(url).should include("?fs=1&hl=sk_SK")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "youtube_video" do
|
30
|
+
it "create flash object" do
|
31
|
+
url = "youtube.com/watch?v=lala"
|
32
|
+
video = helper.youtube_video(url, 100, 200)
|
33
|
+
video.should include("<object")
|
34
|
+
video.should include("youtube.com")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should include given width" do
|
38
|
+
video = helper.youtube_video("", 100, 200)
|
39
|
+
video.should include('width="100"')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should include given height" do
|
43
|
+
video = helper.youtube_video("", 100, 200)
|
44
|
+
video.should include('height="200"')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
data/wnm_support.gemspec
CHANGED
@@ -7,18 +7,20 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "wnm_support"
|
8
8
|
gem.version = WnmSupport::VERSION
|
9
9
|
gem.authors = ["Miroslav Hettes"]
|
10
|
-
gem.email = ["
|
10
|
+
gem.email = ["hettes@webynamieru.sk"]
|
11
11
|
gem.description = %q{Extend core methods in Rails}
|
12
|
-
gem.summary = %q{Extend core
|
13
|
-
gem.homepage = "https://
|
12
|
+
gem.summary = %q{Extend core methods in Rails}
|
13
|
+
gem.homepage = "https://github.com/mirrec/wnm_support"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency "activesupport"
|
21
|
-
gem.add_runtime_dependency "activerecord"
|
20
|
+
gem.add_runtime_dependency "activesupport", ">= 3.0"
|
21
|
+
gem.add_runtime_dependency "activerecord", ">= 3.0"
|
22
|
+
gem.add_runtime_dependency "actionpack", ">= 3.0"
|
23
|
+
|
22
24
|
gem.add_development_dependency "rspec"
|
23
25
|
gem.add_development_dependency "rake"
|
24
26
|
gem.add_development_dependency "active_record_no_table"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wnm_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
29
|
+
version: '3.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activerecord
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
37
|
+
version: '3.0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,23 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: actionpack
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rspec
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +125,7 @@ dependencies:
|
|
109
125
|
version: '0'
|
110
126
|
description: Extend core methods in Rails
|
111
127
|
email:
|
112
|
-
-
|
128
|
+
- hettes@webynamieru.sk
|
113
129
|
executables: []
|
114
130
|
extensions: []
|
115
131
|
extra_rdoc_files: []
|
@@ -137,11 +153,14 @@ files:
|
|
137
153
|
- lib/wnm_support/core_ext/to_boolean.rb
|
138
154
|
- lib/wnm_support/core_ext/to_integer.rb
|
139
155
|
- lib/wnm_support/core_ext/unicode.rb
|
156
|
+
- lib/wnm_support/railtie.rb
|
140
157
|
- lib/wnm_support/version.rb
|
158
|
+
- lib/wnm_support/view_helpers/bool_to_human.rb
|
159
|
+
- lib/wnm_support/view_helpers/youtube.rb
|
141
160
|
- spec/spec_helper.rb
|
142
161
|
- spec/wnm_support/activer_record_ext/destroy_validation_spec.rb
|
143
162
|
- spec/wnm_support/activer_record_ext/multi_action_spec.rb
|
144
|
-
- spec/wnm_support/activer_record_ext/
|
163
|
+
- spec/wnm_support/activer_record_ext/mysql_order_by_field_spec.rb
|
145
164
|
- spec/wnm_support/activer_record_ext/mysql_truncate_spec.rb
|
146
165
|
- spec/wnm_support/activer_record_ext/view_helpers_spec.rb
|
147
166
|
- spec/wnm_support/core_ext/array_spec.rb
|
@@ -151,8 +170,10 @@ files:
|
|
151
170
|
- spec/wnm_support/core_ext/nil_class_spec.rb
|
152
171
|
- spec/wnm_support/core_ext/string_spec.rb
|
153
172
|
- spec/wnm_support/core_ext/true_class_spec.rb
|
173
|
+
- spec/wnm_support/view_helpers/bool_to_human_spec.rb
|
174
|
+
- spec/wnm_support/view_helpers/youtube_spec.rb
|
154
175
|
- wnm_support.gemspec
|
155
|
-
homepage: https://
|
176
|
+
homepage: https://github.com/mirrec/wnm_support
|
156
177
|
licenses: []
|
157
178
|
post_install_message:
|
158
179
|
rdoc_options: []
|
@@ -175,12 +196,12 @@ rubyforge_project:
|
|
175
196
|
rubygems_version: 1.8.24
|
176
197
|
signing_key:
|
177
198
|
specification_version: 3
|
178
|
-
summary: Extend core
|
199
|
+
summary: Extend core methods in Rails
|
179
200
|
test_files:
|
180
201
|
- spec/spec_helper.rb
|
181
202
|
- spec/wnm_support/activer_record_ext/destroy_validation_spec.rb
|
182
203
|
- spec/wnm_support/activer_record_ext/multi_action_spec.rb
|
183
|
-
- spec/wnm_support/activer_record_ext/
|
204
|
+
- spec/wnm_support/activer_record_ext/mysql_order_by_field_spec.rb
|
184
205
|
- spec/wnm_support/activer_record_ext/mysql_truncate_spec.rb
|
185
206
|
- spec/wnm_support/activer_record_ext/view_helpers_spec.rb
|
186
207
|
- spec/wnm_support/core_ext/array_spec.rb
|
@@ -190,3 +211,5 @@ test_files:
|
|
190
211
|
- spec/wnm_support/core_ext/nil_class_spec.rb
|
191
212
|
- spec/wnm_support/core_ext/string_spec.rb
|
192
213
|
- spec/wnm_support/core_ext/true_class_spec.rb
|
214
|
+
- spec/wnm_support/view_helpers/bool_to_human_spec.rb
|
215
|
+
- spec/wnm_support/view_helpers/youtube_spec.rb
|