nifty-utils 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nifty/utils/railtie.rb +2 -1
- data/lib/nifty/utils/version.rb +1 -1
- data/lib/nifty/utils/view_helpers.rb +46 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15c837b03926d9a2189ed66336f4efd74fb438c
|
4
|
+
data.tar.gz: 3266ae6faf062f9aceed51e34594f9f04a59aabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583eecdb5e6fdcadac895987036265b70e95b787aebf537f7808baac8a60d8178be6f7cfa80deb61363e94ca4cc24af7a19bcc372d08abc5008c744add855f62
|
7
|
+
data.tar.gz: 82bf84d00522374940cd09c64d0a4c5a10d75edf77079e92a18e586a8eb34d549f3e39e8e983c80190b4e117b4734c9ad6579bda0a6a525cfc0342bc74349e3f
|
data/lib/nifty/utils/railtie.rb
CHANGED
@@ -2,7 +2,8 @@ module Nifty
|
|
2
2
|
module Utils
|
3
3
|
class Railtie < Rails::Railtie #:nodoc:
|
4
4
|
|
5
|
-
initializer 'nifty.utils.initialize' do
|
5
|
+
initializer 'nifty.utils.initialize' do |app|
|
6
|
+
Rails.application.config.i18n.load_path << File.expand_path(File.join('..', '..', '..', '..', 'locales', 'en.yml'), __FILE__)
|
6
7
|
|
7
8
|
# Load the Active Record extensions
|
8
9
|
ActiveSupport.on_load(:active_record) do
|
data/lib/nifty/utils/version.rb
CHANGED
@@ -6,10 +6,13 @@ module Nifty
|
|
6
6
|
# element. The ID of the outputted div will be `flash-alert` where alert is the
|
7
7
|
# type of flash.
|
8
8
|
#
|
9
|
-
#
|
10
|
-
def display_flash
|
11
|
-
|
12
|
-
|
9
|
+
# * <tt>:types</tt>: the names of flash messages to display with this helper
|
10
|
+
def display_flash(options = {})
|
11
|
+
options[:types] ||= [:alert, :warning, :notice]
|
12
|
+
options[:types].map do |key|
|
13
|
+
if flash[key]
|
14
|
+
content_tag :div, content_tag(:p, h(flash[key])), :id => "flash-#{key}", :class => "flashMessage flashMessage--#{key}"
|
15
|
+
end
|
13
16
|
end.join.html_safe
|
14
17
|
end
|
15
18
|
|
@@ -47,6 +50,45 @@ module Nifty
|
|
47
50
|
content_tag :span, (bool ? "<span class='true'>✔#{true_text}</span>" : "<span class='false'>✘#{false_text}</span>").html_safe, :class => "boolean", :title => tip
|
48
51
|
end
|
49
52
|
|
53
|
+
# Returns a URL to share some content on Twitter
|
54
|
+
#
|
55
|
+
# * <tt>:text</tt> - the text you wish to tweet
|
56
|
+
# * <tt>:url</tt> - the URL you want to tweet
|
57
|
+
def twitter_share_url(options = {})
|
58
|
+
"https://twitter.com/share?text=#{CGI.escape(options[:text])}&url=#{CGI.escape(options[:url])}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns a length of time in works (no I18N)
|
62
|
+
#
|
63
|
+
def length_of_time_in_words(seconds, options = {})
|
64
|
+
days = (seconds / 60 / 60 / 24).floor
|
65
|
+
hours = ((seconds / 60 / 60) - (days * 24)).floor
|
66
|
+
minutes = ((seconds / 60) - (days * 24 * 60) - (hours * 60)).floor
|
67
|
+
seconds = (seconds - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60)).floor
|
68
|
+
Array.new.tap do |s|
|
69
|
+
if options[:short]
|
70
|
+
s << "#{days}d" if days > 0
|
71
|
+
s << "#{hours}h" if hours > 0
|
72
|
+
s << "#{minutes}m" if minutes > 0
|
73
|
+
s << "#{seconds}s" if seconds > 0
|
74
|
+
else
|
75
|
+
s << pluralize(days, 'day') if days > 0
|
76
|
+
s << pluralize(hours, 'hour') if hours > 0
|
77
|
+
s << pluralize(minutes, 'minute') if minutes > 0
|
78
|
+
s << pluralize(seconds, 'second') if seconds > 0
|
79
|
+
end
|
80
|
+
end.join(options[:short] ? ' ' : ', ')
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return an image path for an RFC4226 QR code for a tiven RTP token
|
84
|
+
def rfc4226_qrcode(token)
|
85
|
+
data = "otpauth://totp/#{request.host}?secret=#{token}"
|
86
|
+
data = Rack::Utils.escape(data)
|
87
|
+
url = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=#{data}"
|
88
|
+
image_tag(url, :alt => 'Google Authenticator QRCode', :width => 200, :height => 200)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
50
92
|
end
|
51
93
|
end
|
52
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nifty-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A set of useful utilties for Rails applications.
|
14
14
|
email:
|