soar_sc_views 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bbfcb76896e86fd9d54afde4b557350bf2b3dc8
4
+ data.tar.gz: 140eb4ca2b02792306301882191b354ca1237cb1
5
+ SHA512:
6
+ metadata.gz: 7d40d26c8babc87bb766886e26dac24e435b56905c9d6f11dac407f4eaf32143fc2d716a5c88dab5c927d8487c778b0c160821bfb1de48bd9c3e56d83c5e6d59
7
+ data.tar.gz: 56a33c50ccf016831b063ef5c3f689f1c7e8a4eabb8240737ce23404c134080955cb92c47189b211d9d6af2a592de22d11ea6af42dbd954fd930d7848d40eb76
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_sc_views
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_sc_views.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ernst Van Graan
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # SoarScViews
2
+
3
+ This library contains a collection of soar_sc views and view loaders. Views and loaders are provided in the SoarSc::Web::Views namespace.
4
+
5
+ Views must provide the following API:
6
+
7
+ ```ruby
8
+ module SoarSc
9
+ module Web
10
+ module Views
11
+ module TheView
12
+ def self.render(http_code, body)
13
+ [http_code, {"Content-Type" => "content-type-here"}, [body]]
14
+ end
15
+
16
+ def self.not_found
17
+ [404, {}, ["404 - Not found"]]
18
+ end
19
+
20
+ def self.not_authenticated
21
+ [401, {}, ["401 - Not authenticated"]]
22
+ end
23
+
24
+ def self.not_authorized
25
+ [403, {}, [" 403 - Not authorized"]]
26
+ end
27
+
28
+ def self.not_valid(errors)
29
+ [400, {"Content-Type" => "content-type-here"} , errors]
30
+ end
31
+
32
+ def self.error(ex)
33
+ body = exception_handling
34
+ [500, {"Content-Type" => "content-type-here"}, [body]]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ ```
41
+
42
+ Loaders must provide the following API:
43
+
44
+ ```ruby
45
+ module SoarSc
46
+ module Web
47
+ module Views
48
+ module TheLoader
49
+ def self.load(view, data)
50
+ render_the_view_with_the_data
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ Add this line to your application's Gemfile:
62
+
63
+ ```ruby
64
+ gem 'soar_sc_views'
65
+ ```
66
+
67
+ And then execute:
68
+
69
+ $ bundle
70
+
71
+ Or install it yourself as:
72
+
73
+ $ gem install soar_sc_views
74
+
75
+ ## Usage
76
+
77
+
78
+
79
+ ## Contributing
80
+
81
+ Please send feedback and comments to the author at:
82
+
83
+ Ernst van Graan <ernst.van.graan@hetzner.co.za>
84
+
85
+ This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
90
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_sc_views"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require "soar_sc_views/version"
2
+ require "soar_sc_views/default"
3
+ require "soar_sc_views/erb_loader"
4
+ require "soar_sc_views/haml_loader"
5
+ require "soar_sc_views/html_loader"
6
+ require "soar_sc_views/json"
7
+ require "soar_sc_views/xml"
8
+
9
+ module SoarScViews
10
+ end
11
+
12
+
@@ -0,0 +1,36 @@
1
+ require 'jsender'
2
+
3
+ module SoarSc
4
+ module Web
5
+ module Views
6
+ module Default
7
+ include Jsender
8
+
9
+ def self.render(http_code, body)
10
+ [http_code, {"Content-Type" => "text/html"}, [body]]
11
+ end
12
+
13
+ def self.not_found
14
+ [404, {}, ["404 - Not found"]]
15
+ end
16
+
17
+ def self.not_authenticated
18
+ [401, {}, ["401 - Not authenticated"]]
19
+ end
20
+
21
+ def self.not_authorized
22
+ [403, {}, [" 403 - Not authorized"]]
23
+ end
24
+
25
+ def self.not_valid(errors)
26
+ [400, {"Content-Type" => "application/json"} , errors]
27
+ end
28
+
29
+ def self.error(ex)
30
+ body = ex.is_a?(Exception) ? ex.message : ex.to_s
31
+ [500, {"Content-Type" => "text/html"}, [body]]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require 'erb'
2
+
3
+ module SoarSc
4
+ module Web
5
+ module Views
6
+ module ERBLoader
7
+
8
+ class ERBNamespace
9
+ def initialize(hash)
10
+ hash.each do |k, v|
11
+ singleton_class.send(:define_method, k) { v }
12
+ end
13
+ end
14
+
15
+ def get_binding
16
+ binding
17
+ end
18
+ end
19
+
20
+ def self.load(view, data)
21
+ page = File.read("#{Dir.pwd}/lib/web/views/#{view}.erb.html")
22
+ ns = ERBNamespace.new(data)
23
+ ERB.new(page).result(ns.get_binding)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'haml'
2
+
3
+ module SoarSc
4
+ module Web
5
+ module Views
6
+ module HamlLoader
7
+ def self.load(view, data)
8
+ page = File.read("#{Dir.pwd}/lib/web/views/#{view}.haml")
9
+ Haml::Engine.new(page).render(Object.new, data)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module SoarSc
2
+ module Web
3
+ module Views
4
+ module HtmlLoader
5
+ def self.render(view)
6
+ body = File.read("#{Dir.pwd}/lib/web/views/#{view}.html")
7
+ [200, {"Content-Type" => "text/html"}, [body]]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+
3
+ module SoarSc
4
+ module Web
5
+ module Views
6
+ module JSON
7
+ def self.render(http_code, body)
8
+ data = SoarSc::Web::Views::JSON::is_json?(body) ? body : ::JSON.generate(body)
9
+ [http_code, {"Content-Type" => "application/json"}, [data]]
10
+ end
11
+
12
+ def self.not_found
13
+ [404, {}, []]
14
+ end
15
+
16
+ def self.error
17
+ body = ex.message
18
+ [500, {"Content-Type" => "application/json"}, [::JSON.generate(body)]]
19
+ end
20
+
21
+ def self.is_json?(data)
22
+ begin
23
+ ::JSON.parse(data)
24
+ return true
25
+ rescue => ex
26
+ return false
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module SoarScViews
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ module SoarSc
2
+ module Web
3
+ module Views
4
+ module XML
5
+ def self.render(http_code, body)
6
+ [http_code, {"Content-Type" => "application/xml"}, [body]]
7
+ end
8
+
9
+ def self.not_found
10
+ [404, "", []]
11
+ end
12
+
13
+ def self.error
14
+ body = ex.message
15
+ [500, {"Content-Type" => "application/xml"}, [body]]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_sc_views/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_sc_views"
8
+ spec.version = SoarScViews::VERSION
9
+ spec.authors = ["Ernst Van Graan"]
10
+ spec.email = ["ernst.van.graan@hetzner.co.za"]
11
+
12
+ spec.summary = %q{collection of soar_sc views}
13
+ spec.description = %q{collection of soar_sc views}
14
+ spec.homepage = "https://github.com/hetznerZA/soar_sc_views"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'jsender', "~> 0.2.0"
31
+ spec.add_dependency "haml", "~> 4.0.7"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.12"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "byebug"
37
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_sc_views
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ernst Van Graan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jsender
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: collection of soar_sc views
98
+ email:
99
+ - ernst.van.graan@hetzner.co.za
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/soar_sc_views.rb
116
+ - lib/soar_sc_views/default.rb
117
+ - lib/soar_sc_views/erb_loader.rb
118
+ - lib/soar_sc_views/haml_loader.rb
119
+ - lib/soar_sc_views/html_loader.rb
120
+ - lib/soar_sc_views/json.rb
121
+ - lib/soar_sc_views/version.rb
122
+ - lib/soar_sc_views/xml.rb
123
+ - soar_sc_views.gemspec
124
+ homepage: https://github.com/hetznerZA/soar_sc_views
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.5.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: collection of soar_sc views
148
+ test_files: []