platformx 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +31 -0
- data/Rakefile +20 -0
- data/lib/platformx.rb +106 -0
- data/lib/platformx/auth.rb +74 -0
- data/lib/platformx/configuration.rb +35 -0
- data/lib/platformx/date.rb +96 -0
- data/lib/platformx/facebook.rb +16 -0
- data/lib/platformx/faker.rb +100 -0
- data/lib/platformx/form.rb +953 -0
- data/lib/platformx/google_map.rb +42 -0
- data/lib/platformx/instagram.rb +115 -0
- data/lib/platformx/layout.rb +155 -0
- data/lib/platformx/mail.rb +43 -0
- data/lib/platformx/notify.rb +45 -0
- data/lib/platformx/omniauth_helpers.rb +16 -0
- data/lib/platformx/omniauth_routes.rb +64 -0
- data/lib/platformx/pdf.rb +0 -0
- data/lib/platformx/stripe.rb +65 -0
- data/lib/platformx/template.rb +16 -0
- data/lib/platformx/text.rb +32 -0
- data/lib/platformx/timeline.rb +55 -0
- data/lib/platformx/twitter.rb +47 -0
- data/lib/platformx/version.rb +3 -0
- data/platformx.gemspec +48 -0
- data/spec/layout_spec.rb +19 -0
- data/spec/spec_helper.rb +16 -0
- metadata +426 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ecc6db65af06220ba1cd3b0f66f47c1633ea305
|
4
|
+
data.tar.gz: db02e2eeea2580171a5164f6f0e1e6a604bcc259
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f3ce2902a20dec1c02b09cccc96216a9c97a5bd51b63874131f47d32d7345b8aa72526aab387c095c6eb9104ca920ae5bf0c603d8c4625529e184513c9695df
|
7
|
+
data.tar.gz: 9aa30f3e26d87900950f1e6094fcdf475c8eb39eeca51009c1dfe2e787053d65d7ac8e4b856218def26f6a92a80ba50c6f01800d0b9c79b0088d31828408ba63
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015 timmushen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Use by Permission only
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
8
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
10
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
11
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
12
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
13
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Platformx
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'platformx'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install platformx
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To use in Sinatra add
|
22
|
+
|
23
|
+
require 'platformx'
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Platformx.configuration do |config|
|
28
|
+
config.bugsnag_api_key = "string"
|
29
|
+
end
|
30
|
+
|
31
|
+
## Contributing
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
desc "Check into repo, build & install"
|
5
|
+
task :gbuild do
|
6
|
+
# Your code goes here
|
7
|
+
puts `git add -Av`
|
8
|
+
puts `git commit -m 'updated gem'`
|
9
|
+
puts `rake build`
|
10
|
+
puts `git push origin master`
|
11
|
+
puts `rake install`
|
12
|
+
end
|
13
|
+
|
14
|
+
# Default directory to look in is `/specs`
|
15
|
+
# Run with `rake spec`
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
17
|
+
# task.rspec_opts = ['--color', '--format']
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
data/lib/platformx.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require "platformx/version"
|
2
|
+
require "platformx/configuration"
|
3
|
+
require "platformx/auth"
|
4
|
+
require "platformx/form"
|
5
|
+
require "platformx/layout"
|
6
|
+
require "platformx/date"
|
7
|
+
require "platformx/notify"
|
8
|
+
require "platformx/mail"
|
9
|
+
require "platformx/stripe"
|
10
|
+
require "platformx/google_map"
|
11
|
+
require "platformx/instagram"
|
12
|
+
require "platformx/faker"
|
13
|
+
require "platformx/pdf"
|
14
|
+
require "platformx/text"
|
15
|
+
|
16
|
+
########################### Require Gems ############################
|
17
|
+
require "sinatra/base"
|
18
|
+
require "sinatra/contrib/all"
|
19
|
+
require "sinatra/partial"
|
20
|
+
require "sinatra/support"
|
21
|
+
require "sinatra/flash"
|
22
|
+
require "digest"
|
23
|
+
require "base64"
|
24
|
+
require "json"
|
25
|
+
require "pony"
|
26
|
+
require "json"
|
27
|
+
require "encrypted_cookie"
|
28
|
+
require "encryptor"
|
29
|
+
require "active_support/all"
|
30
|
+
require "stripe"
|
31
|
+
require "better_errors"
|
32
|
+
require "rack-protection"
|
33
|
+
require "rack-ssl-enforcer"
|
34
|
+
require "bugsnag"
|
35
|
+
require "slugify"
|
36
|
+
require "data_mapper"
|
37
|
+
require "securerandom"
|
38
|
+
require "geokit"
|
39
|
+
require "faker"
|
40
|
+
require "uuidtools"
|
41
|
+
require "net/ssh"
|
42
|
+
|
43
|
+
module Platformx
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_accessor :configuration
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.configuration
|
50
|
+
@configuration ||= Configuration.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.reset
|
54
|
+
@configuration = Configuration.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.configure
|
58
|
+
yield(configuration)
|
59
|
+
end
|
60
|
+
|
61
|
+
module Sinatra
|
62
|
+
|
63
|
+
def self.registered(app)
|
64
|
+
app.helpers Platformx::DateHelpers
|
65
|
+
app.helpers Platformx::StripeHelpers
|
66
|
+
app.helpers Platformx::AuthHelpers
|
67
|
+
app.helpers Platformx::FormHelpers
|
68
|
+
app.helpers Platformx::LayoutHelpers
|
69
|
+
app.helpers Platformx::NotifyHelpers
|
70
|
+
app.helpers Platformx::GooglemapHelpers
|
71
|
+
app.helpers Platformx::InstagramHelpers
|
72
|
+
app.helpers Platformx::FakerHelpers
|
73
|
+
app.helpers Platformx::TextHelpers
|
74
|
+
|
75
|
+
#BugSnag
|
76
|
+
if Platformx.configuration.bugsnag_api_key != ""
|
77
|
+
app.Bugsnag.configure do |config|
|
78
|
+
config.api_key = Platformx.configuration.bugsnag_api_key
|
79
|
+
end
|
80
|
+
app.use Bugsnag::Rack
|
81
|
+
app.enable :raise_errors
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# Configure Better Errors
|
86
|
+
if app.development?
|
87
|
+
app.use BetterErrors::Middleware
|
88
|
+
BetterErrors.application_root = __dir__
|
89
|
+
end
|
90
|
+
|
91
|
+
# Configure Rack Protection
|
92
|
+
if app.production?
|
93
|
+
app.use Rack::Protection
|
94
|
+
end
|
95
|
+
|
96
|
+
#require_relative 'platformx/omniauth_routes.rb'
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end # End Sinatra
|
102
|
+
end
|
103
|
+
#Register Helpers
|
104
|
+
Sinatra.register Platformx::Sinatra
|
105
|
+
Sinatra.register Sinatra::Numeric
|
106
|
+
Sinatra.register Sinatra::HtmlHelpers
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Platformx
|
2
|
+
module AuthHelpers
|
3
|
+
########################################################
|
4
|
+
#
|
5
|
+
# Start Helpers
|
6
|
+
#
|
7
|
+
########################################################
|
8
|
+
|
9
|
+
########################################################
|
10
|
+
#
|
11
|
+
# Admin Login
|
12
|
+
#
|
13
|
+
########################################################
|
14
|
+
|
15
|
+
def x_admin_authorized?
|
16
|
+
session[:admin_authorized]
|
17
|
+
end
|
18
|
+
|
19
|
+
def x_admin_authorize!
|
20
|
+
redirect '/admin/login' unless x_admin_authorized? || request.url.include?("/admin/login")
|
21
|
+
end
|
22
|
+
|
23
|
+
def x_admin_logout!
|
24
|
+
session[:admin_authorized] = false
|
25
|
+
session.clear
|
26
|
+
end
|
27
|
+
|
28
|
+
########################################################
|
29
|
+
#
|
30
|
+
# Login
|
31
|
+
#
|
32
|
+
########################################################
|
33
|
+
|
34
|
+
def x_authorized?
|
35
|
+
session[:authorized]
|
36
|
+
end
|
37
|
+
|
38
|
+
def x_authorize!
|
39
|
+
redirect '/login' unless x_authorized? || request.url.include?("/login") || request.url.include?("/auth")
|
40
|
+
end
|
41
|
+
|
42
|
+
def x_logout!
|
43
|
+
session[:authorized] = false
|
44
|
+
session.clear
|
45
|
+
end
|
46
|
+
|
47
|
+
########################################################
|
48
|
+
#
|
49
|
+
# Encyrption
|
50
|
+
#
|
51
|
+
########################################################
|
52
|
+
def x_encrypt(int = "")
|
53
|
+
str = int.to_s
|
54
|
+
#encrypted_value = Encryptor.encrypt(:value => str, :key => "=PeuMX7B4LQ#@jG*s;tYGdF")
|
55
|
+
return Base64.urlsafe_encode64(str)
|
56
|
+
end
|
57
|
+
|
58
|
+
def x_decrypt(str = "")
|
59
|
+
str = Base64.urlsafe_decode64(str)
|
60
|
+
#decrypted_value = Encryptor.decrypt(:value => str, :key => '=PeuMX7B4LQ#@jG*s;tYGdF')
|
61
|
+
return str.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def x_generate_password(len = "10")
|
65
|
+
random_password = Array.new(len).map { (65 + rand(58)).chr }.join
|
66
|
+
return random_password
|
67
|
+
end
|
68
|
+
########################################################
|
69
|
+
#
|
70
|
+
# End
|
71
|
+
#
|
72
|
+
########################################################
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Platformx
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :bugsnag_api_key
|
5
|
+
attr_accessor :mail_from
|
6
|
+
attr_accessor :mail_address
|
7
|
+
attr_accessor :mail_port
|
8
|
+
attr_accessor :mail_domain
|
9
|
+
attr_accessor :mail_user_name
|
10
|
+
attr_accessor :mail_password
|
11
|
+
attr_accessor :mail_authentication
|
12
|
+
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
#Example:
|
16
|
+
@bugsnag_api_key = ""
|
17
|
+
@mail_from = ""
|
18
|
+
@mail_address = "smtp.mailgun.org"
|
19
|
+
@mail_port = "587"
|
20
|
+
@mail_domain = "smtp.mailgun.org"
|
21
|
+
@mail_user_name = ""
|
22
|
+
@mail_password = ""
|
23
|
+
@mail_authentication = "plain"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# Platformx.configure do |config|
|
32
|
+
# config.access_key = ''
|
33
|
+
# config.secret_key = ''
|
34
|
+
# config.personal_key = ''
|
35
|
+
# end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Platformx
|
2
|
+
module DateHelpers
|
3
|
+
########################################################
|
4
|
+
#
|
5
|
+
# Start Helpers
|
6
|
+
#
|
7
|
+
########################################################
|
8
|
+
|
9
|
+
########################################################
|
10
|
+
#
|
11
|
+
# Time in words
|
12
|
+
#
|
13
|
+
########################################################
|
14
|
+
def x_time_in_words(date: "")
|
15
|
+
date = date.to_date
|
16
|
+
date = Date.parse(date, true) unless /Date.*/ =~ date.class.to_s
|
17
|
+
days = (date - Date.today).to_i
|
18
|
+
return 'Today' if days >= 0 and days < 1
|
19
|
+
return 'Tomorrow' if days >= 1 and days < 2
|
20
|
+
return 'Yesterday' if days >= -1 and days < 0
|
21
|
+
return "In #{days} days" if days.abs < 60 and days > 0
|
22
|
+
return "#{days.abs} days ago" if days.abs < 60 and days < 0
|
23
|
+
return date.strftime('%A, %B %e, %Y') if days.abs < 182
|
24
|
+
return date.strftime('%A, %B %e, %Y')
|
25
|
+
end
|
26
|
+
|
27
|
+
########################################################
|
28
|
+
#
|
29
|
+
# Returns relative time in words referencing the given date
|
30
|
+
# relative_time_ago(Time.now) => 'about a minute ago'
|
31
|
+
#
|
32
|
+
########################################################
|
33
|
+
def x_relative_time_ago(from_time: "")
|
34
|
+
distance_in_minutes = (((Time.now - from_time.to_time).abs)/60).round
|
35
|
+
case distance_in_minutes
|
36
|
+
when 0..1 then 'A minute ago'
|
37
|
+
when 2..44 then "#{distance_in_minutes} minutes ago"
|
38
|
+
when 45..89 then '1 hour ago'
|
39
|
+
when 90..1439 then "#{(distance_in_minutes.to_f / 60.0).round} hours ago"
|
40
|
+
when 1440..2439 then '1 day ago'
|
41
|
+
when 2440..2879 then '2 days ago'
|
42
|
+
when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago"
|
43
|
+
when 43200..86399 then 'About 1 month ago'
|
44
|
+
when 86400..525599 then "#{(distance_in_minutes / 43200).round} months ago"
|
45
|
+
when 525600..1051199 then 'About 1 year ago'
|
46
|
+
else "Over #{(distance_in_minutes / 525600).round} years ago"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def x_format_date(date: "", show_time: false, show_month: true)
|
51
|
+
|
52
|
+
|
53
|
+
if date.nil?
|
54
|
+
return ""
|
55
|
+
else
|
56
|
+
time = date.strftime("%A, %B %d, %Y")
|
57
|
+
|
58
|
+
if show_time == true
|
59
|
+
time = time + date.strftime(" %l:%M %p")
|
60
|
+
end
|
61
|
+
|
62
|
+
return time
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def x_format_datetime(date: "")
|
67
|
+
|
68
|
+
if date.nil?
|
69
|
+
return ""
|
70
|
+
else
|
71
|
+
time = date.strftime("%A, %B %d, %Y %l:%M %p")
|
72
|
+
return time
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def x_format_time(time: "")
|
77
|
+
|
78
|
+
if time.nil?
|
79
|
+
return ""
|
80
|
+
else
|
81
|
+
time = time.strftime("%l:%M %p")
|
82
|
+
return time
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def x_short_date(datevar: "")
|
87
|
+
return datevar.strftime("%A, %-m-%d-%y") unless datevar.nil?
|
88
|
+
end
|
89
|
+
|
90
|
+
########################################################
|
91
|
+
#
|
92
|
+
# End
|
93
|
+
#
|
94
|
+
########################################################
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Platformx
|
2
|
+
module FacebookHelpers
|
3
|
+
########################################################
|
4
|
+
#
|
5
|
+
# Start Helpers
|
6
|
+
#
|
7
|
+
########################################################
|
8
|
+
|
9
|
+
|
10
|
+
########################################################
|
11
|
+
#
|
12
|
+
# End
|
13
|
+
#
|
14
|
+
########################################################
|
15
|
+
end
|
16
|
+
end
|