flatspace 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46914819998d43536263cf564cee47c1df81cb4d
4
- data.tar.gz: f00fb2ee5907ac552426405cfeb87f15183d53f6
3
+ metadata.gz: 745030999ee0e42fc7e9d02da7a9d3dd0b6eeaca
4
+ data.tar.gz: b849a9298dafff66b21c039a9b3a1749027d976c
5
5
  SHA512:
6
- metadata.gz: f9df2332d67f9eae59285211f488a92575109bae921ef12ffa56d2bf61286e70af8f296ebba52dd4fd4f3a51414cf3079a1dd109387571eb700f5163328fdbd3
7
- data.tar.gz: b7dce46f30f8ccb8a2a1c1a31dd3d1bc7b30db1d9c84aefa7a4c04afe666e11875fd1c29eee3924ad28700c0bc74ae00f4e4ddc79c6e0aa9ac51ec7e5529c06c
6
+ metadata.gz: ab5fa685f869d71af604acefb3e3fdb2a2d0d681d81f0ce9ecd950b04b789973a95873a202645233ec24ec146b664037a8da92294653656e30da54d6a3b23af0
7
+ data.tar.gz: a70387c1a84e720fa014c29f64c47a3656f1a9587901244355d79659b67c5f65df1e5b5f82fc33f7db5b13e0d20bae879908b60634da5eddd673e5570b4266b8
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ Gemfile.lock
@@ -0,0 +1,3 @@
1
+ **Version 0.1.0** - *2017-01-05*
2
+
3
+ - Fixed gemspec issues
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rerun'
7
+ gem 'rb-fsevent'
8
+ gem 'terminal-notifier'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Fugroup
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # Flatspace ruby web app helpers
2
+ Request helpers for flat space ruby apps running Sinatra.
3
+
4
+ ### Installation
5
+ ```
6
+ gem install flatspace
7
+ ```
8
+ or add to your Gemfile.
9
+
10
+ ### Usage
11
+ ```ruby
12
+ # Include as helper in your Sinatra app
13
+ helpers Flatspace::Helpers::Request
14
+
15
+ # Login redirect unless session[:u] is set
16
+ login
17
+
18
+ # Password is valid?
19
+ password_valid?
20
+
21
+ # HTTP Basic auth authentication
22
+ protect!
23
+
24
+ # Check HTTP Basic authorization
25
+ authorized?
26
+
27
+ # Colorize input green or red
28
+ green('text')
29
+ red('text')
30
+
31
+ # Errors, use for request errors
32
+ e
33
+ e[:id]
34
+ e.any?
35
+
36
+ # Params
37
+ p
38
+ p[:i]
39
+ p[:i] = 'val'
40
+
41
+ # Flash
42
+ f
43
+ f[:i]
44
+ f[:i] = 'val'
45
+
46
+ # Session
47
+ s
48
+ s[:u]
49
+ s[:u] = 'val'
50
+
51
+ # Halt, stop and return
52
+ h(val)
53
+
54
+ # Go, redirect to path
55
+ go(path)
56
+
57
+ # Go with flash[:info]
58
+ go(path, :i => 'message')
59
+
60
+ # Go with flash[:error]
61
+ go(path, :e => 'error')
62
+
63
+ # Show erb view and use flash.now
64
+ now(:view)
65
+ now(:view, :i => 'message')
66
+ now(:view, :f => 'error')
67
+ ```
68
+
69
+ Created and maintained by [Fugroup Ltd.](https://www.fugroup.net) We are the creators of [CrowdfundHQ.](https://crowdfundhq.com)
70
+
71
+ `@authors: Vidar`
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:default, :development)
3
+
4
+ MODE = ENV['RACK_ENV'] || 'development'
5
+
6
+ require 'yaml'
7
+
8
+ require './lib/flatspace.rb'
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'flatspace'
3
+ s.version = '0.0.2'
4
+ s.date = '2017-01-05'
5
+ s.summary = "Ruby helpers for making flatspace apps"
6
+ s.description = "These helpers make it easy to make apps with Sinatra or other Rack based frameworks"
7
+ s.authors = ["Fugroup Limited"]
8
+ s.email = 'mail@fugroup.net'
9
+
10
+ s.add_runtime_dependency 'sinatra', '~> 1.4'
11
+ s.add_development_dependency 'futest', '~> 0'
12
+
13
+ s.homepage = 'https://github.com/fugroup/flatspace'
14
+ s.license = 'MIT'
15
+
16
+ s.require_paths = ['lib']
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ require 'sinatra'
2
+
1
3
  module Flatspace
2
4
 
3
5
  # # # # # #
@@ -7,6 +9,9 @@ module Flatspace
7
9
  # @license: MIT, contributions are welcome.
8
10
  # # # # # #
9
11
 
12
+ class << self; attr_accessor :mode, :debug; end
13
+ @mode = ENV['RACK_ENV'] || 'development'
14
+
10
15
  end
11
16
 
12
17
  require_relative 'flatspace/request'
@@ -0,0 +1,62 @@
1
+ # Request helpers.
2
+
3
+ module Flatspace
4
+ module Helpers
5
+ module Request
6
+
7
+ # Require login
8
+ def login
9
+ return if s[:u]
10
+ path = request.path.split('?')[0]
11
+ return if %w[/ /login /docs].find{|r| path.start_with?(r)}
12
+ redirect('/login')
13
+ end
14
+
15
+ # Password valid?
16
+ def password_valid?
17
+ @profile and (@profile[:md5] == Digest::MD5.hexdigest(p[:password] + @profile[:salt]))
18
+ end
19
+
20
+ # Basic auth
21
+ def protect!
22
+ return if authorized?
23
+ headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
24
+ halt 401, "Not authorized\n"
25
+ end
26
+
27
+ # Check if authorized
28
+ def authorized?
29
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
30
+ @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == ['admin', 'test54']
31
+ end
32
+
33
+ # Colorize input green or red
34
+ def green(text);"\e[33m#{text}\e[0m";end
35
+ def red(text);"\e[31m#{text}\e[0m";end
36
+
37
+ # Flash and halt short cuts
38
+ def p;@p||=params.strip;end
39
+ def f;flash;end
40
+ def s;session;end
41
+ def h(val);halt(val);end
42
+
43
+ # Redirect and optionally set flash
44
+ def go(path, options = {})
45
+ f[:i] = options[:i] if options[:i]
46
+ f[:e] = options[:e] if options[:e]
47
+ redirect(path)
48
+ end
49
+
50
+ # Like above, but sets flash.now and halts with template
51
+ def now(view, options = {})
52
+ f.now[:i] = options[:i] if options[:i]
53
+ f.now[:e] = options[:e] if options[:e]
54
+ h erb(view)
55
+ end
56
+
57
+ # Short cut for setting up errors
58
+ def e;@e ||= [];end
59
+
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -45,7 +45,15 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".gitignore"
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - config/boot.rb
54
+ - flatspace.gemspec
48
55
  - lib/flatspace.rb
56
+ - lib/flatspace/request.rb
49
57
  homepage: https://github.com/fugroup/flatspace
50
58
  licenses:
51
59
  - MIT
@@ -66,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
74
  version: '0'
67
75
  requirements: []
68
76
  rubyforge_project:
69
- rubygems_version: 2.5.1
77
+ rubygems_version: 2.6.8
70
78
  signing_key:
71
79
  specification_version: 4
72
- summary: Ruby helpers for making flat space apps
80
+ summary: Ruby helpers for making flatspace apps
73
81
  test_files: []