cubic 0.1.0
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/Gemfile +4 -0
- data/README.md +141 -0
- data/Rakefile +6 -0
- data/lib/cubic.rb +29 -0
- data/lib/cubic/application.rb +61 -0
- data/lib/cubic/application/configurator.rb +16 -0
- data/lib/cubic/application/controller.rb +48 -0
- data/lib/cubic/application/logable.rb +19 -0
- data/lib/cubic/core_extensions.rb +1 -0
- data/lib/cubic/core_extensions/string.rb +1 -0
- data/lib/cubic/core_extensions/string/parse.rb +17 -0
- data/lib/cubic/engine.rb +49 -0
- data/lib/cubic/generator.rb +42 -0
- data/lib/cubic/generators/app.rb +68 -0
- data/lib/cubic/generators/base.rb +34 -0
- data/lib/cubic/generators/config.rb +67 -0
- data/lib/cubic/generators/controller.rb +64 -0
- data/lib/cubic/generators/gemfile.rb +23 -0
- data/lib/cubic/generators/migrations.rb +24 -0
- data/lib/cubic/generators/model.rb +64 -0
- data/lib/cubic/generators/templates/Rakefile +14 -0
- data/lib/cubic/generators/templates/application.haml +8 -0
- data/lib/cubic/generators/templates/application.rb +14 -0
- data/lib/cubic/generators/templates/boot.rb +4 -0
- data/lib/cubic/generators/templates/config.ru +7 -0
- data/lib/cubic/generators/templates/cubic +6 -0
- data/lib/cubic/generators/templates/database.rb +2 -0
- data/lib/cubic/generators/templates/sitemap.rb +42 -0
- data/lib/cubic/generators/view.rb +27 -0
- data/lib/cubic/middleware/static.rb +34 -0
- data/lib/cubic/render.rb +67 -0
- data/lib/cubic/response.rb +15 -0
- data/lib/cubic/router.rb +85 -0
- data/lib/cubic/version.rb +3 -0
- metadata +180 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Cubic
|
4
|
+
module Generator
|
5
|
+
# View fulfils the V in the MVC pattern. The html documents generated by
|
6
|
+
# the View generator will sit in your app/views directory, waiting
|
7
|
+
# to be served by your application.
|
8
|
+
class View < Base
|
9
|
+
include FileUtils
|
10
|
+
|
11
|
+
# Creates a hash that will be used for file generation purposes
|
12
|
+
def design(dir, action)
|
13
|
+
@files << { directory: "#{Config[:root_path]}/app/views/#{dir}",
|
14
|
+
path: "/app/views/#{dir}/#{action}.#{Config[:html_type]}",
|
15
|
+
content: "%p Coming to you from in #{dir}/#{action}" }
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate
|
19
|
+
@files.each do |info|
|
20
|
+
mkdir_p(info[:directory]) unless Dir.exist?(info[:directory])
|
21
|
+
path = File.join(Config[:root_path], info[:path])
|
22
|
+
File.open(path, 'w') { |f| f.write(info[:content]) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rack/file'
|
2
|
+
require 'rack/utils'
|
3
|
+
|
4
|
+
module Cubic
|
5
|
+
# Replaces the Rack::Static module as was unreliable for
|
6
|
+
# this application.
|
7
|
+
class Static
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if valid_route(env['PATH_INFO'])
|
11
|
+
@file.call(env)
|
12
|
+
else
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(app, options = {})
|
18
|
+
@app = app
|
19
|
+
@url = options[:url]
|
20
|
+
root = options[:root] || Dir.pwd
|
21
|
+
|
22
|
+
@file = Rack::File.new(root)
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_route(path)
|
26
|
+
if @url.is_a? Array
|
27
|
+
ar = @url.map { |u| path.include?(u) ? true : false }
|
28
|
+
ar.include? true
|
29
|
+
else
|
30
|
+
path.include?(@url) ? true : false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/cubic/render.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Cubic
|
4
|
+
# Render template is responsible for serving up files from the views directory.
|
5
|
+
class Render
|
6
|
+
include Logable
|
7
|
+
attr_accessor :params
|
8
|
+
attr_reader :template
|
9
|
+
|
10
|
+
def initialize(params, block)
|
11
|
+
@params = params
|
12
|
+
instance_exec(&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def render(render_method, path)
|
18
|
+
send(render_method, path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def redirect(url, status = 302)
|
22
|
+
redir = proc do |response|
|
23
|
+
response.redirect(url, status)
|
24
|
+
end
|
25
|
+
|
26
|
+
build_response(redir)
|
27
|
+
end
|
28
|
+
|
29
|
+
def html(path)
|
30
|
+
build_response(read_file(path, 'html'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def json(hash)
|
34
|
+
build_response(JSON.generate(hash), 200, 'content-type' => 'application/json')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create a response that will satisfy Rack::Response
|
38
|
+
def build_response(body, status = 200, headers = {})
|
39
|
+
@template = { body: body, status: status, headers: headers }
|
40
|
+
end
|
41
|
+
|
42
|
+
def haml(path)
|
43
|
+
haml = Haml::Engine.new(read_file(path, 'haml'))
|
44
|
+
build_response(application_view { haml.render(self) })
|
45
|
+
end
|
46
|
+
|
47
|
+
def erb(path)
|
48
|
+
build_response(ERB.new(read_file(path, 'erb')).result(binding))
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_file(path, template_engine)
|
52
|
+
File.read(File.join(view_path, "#{path}.#{template_engine}"))
|
53
|
+
end
|
54
|
+
|
55
|
+
# To keep things dry, application_view inserts HTML from a rendered
|
56
|
+
# view into the app/views/layout/application.haml file.
|
57
|
+
def application_view(&block)
|
58
|
+
template = read_file('layout/application', 'haml')
|
59
|
+
Haml::Engine.new(template).render(self, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the absolute path to the applications views directory.
|
63
|
+
def view_path
|
64
|
+
File.join(APP_PATH, 'app/views')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Handles how to create Rack::Response
|
2
|
+
class Response < Rack::Response
|
3
|
+
|
4
|
+
def initialize(content)
|
5
|
+
if content[:body].respond_to?(:call)
|
6
|
+
return super('content', &content[:body])
|
7
|
+
end
|
8
|
+
|
9
|
+
body = content[:body] || ''
|
10
|
+
status = content[:status] || 200
|
11
|
+
headers = content[:headers] || {}
|
12
|
+
|
13
|
+
super(body, status, headers)
|
14
|
+
end
|
15
|
+
end
|
data/lib/cubic/router.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module Cubic
|
2
|
+
String.include CoreExtensions::Parse
|
3
|
+
|
4
|
+
# Handles whether or not the path, given by Rack::Request,
|
5
|
+
# matches any of the routes defined within the application.
|
6
|
+
class Router
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# Stores all of the routes for the application.
|
10
|
+
def routes
|
11
|
+
@route ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
# Adds a route to the routes array.
|
15
|
+
def set_route(http_method, route, block)
|
16
|
+
routes << { http_method: http_method, route: route, block: block }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Searches url against defined routes. If none are found, we check
|
20
|
+
# if the url fits the pattern of a route containing variables.
|
21
|
+
def search(http, url)
|
22
|
+
url = root_path?(url)
|
23
|
+
route = routes.find { |i| i[:http_method] == http && i[:route] == url }
|
24
|
+
route ? route : check_variable_routes(url, http)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Stores parameters created when variable_route? finds a match.
|
28
|
+
def params
|
29
|
+
@param ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def root_path?(url)
|
35
|
+
url == '/' ? 'index' : url
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates a hash of parameters from variables supplied in the url
|
39
|
+
# and merges them into the params hash given by Rack::Request.
|
40
|
+
def create_param(key, value)
|
41
|
+
return params[to_symbole(key)] = value.to_i if value.integer?
|
42
|
+
params[to_symbole(key)] = value
|
43
|
+
end
|
44
|
+
|
45
|
+
# Turns a string preceeded by a colon into a symbole.
|
46
|
+
# ':id'.to_sym would result in ::id, so we must remove
|
47
|
+
# any colons first.
|
48
|
+
def to_symbole(string)
|
49
|
+
string.delete(':').to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
# Checks all routes that may have a variable; e.g. /post/:variable
|
53
|
+
def check_variable_routes(url, http)
|
54
|
+
routes.find do |i|
|
55
|
+
i[:http_method] == http && variable_route?(i[:route], url)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# variable_route? compares all routes against the url again,
|
60
|
+
# but allows the url to fit into a 'variable route' if
|
61
|
+
# one is found that matches the url pattern.
|
62
|
+
def variable_route?(route, url)
|
63
|
+
route = route.split('/').reject(&:empty?)
|
64
|
+
url = url.split('/').reject(&:empty?)
|
65
|
+
|
66
|
+
after = route.zip(url).map do |r, u|
|
67
|
+
r.nil? || u.nil? ? false : route_parser(r, u)
|
68
|
+
end
|
69
|
+
|
70
|
+
after.include?(false) ? false : true
|
71
|
+
end
|
72
|
+
|
73
|
+
# Checks if route can be turned into a variable.
|
74
|
+
def route_parser(route, url)
|
75
|
+
if route.include?(':')
|
76
|
+
create_param(route, url)
|
77
|
+
elsif route == url
|
78
|
+
true
|
79
|
+
else
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cubic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Pfeil
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.8'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.8.3
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.8'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.8.3
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: sequel
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '4.36'
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '4.36'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: bundler
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.12'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '1.12'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rake
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '10.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '10.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: capybara
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.7'
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.7.1
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.7'
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 2.7.1
|
115
|
+
description: Small framework built with a focus on quick app generation.
|
116
|
+
email: mathiaspfeil@yahoo.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/cubic.rb
|
125
|
+
- lib/cubic/application.rb
|
126
|
+
- lib/cubic/application/configurator.rb
|
127
|
+
- lib/cubic/application/controller.rb
|
128
|
+
- lib/cubic/application/logable.rb
|
129
|
+
- lib/cubic/core_extensions.rb
|
130
|
+
- lib/cubic/core_extensions/string.rb
|
131
|
+
- lib/cubic/core_extensions/string/parse.rb
|
132
|
+
- lib/cubic/engine.rb
|
133
|
+
- lib/cubic/generator.rb
|
134
|
+
- lib/cubic/generators/app.rb
|
135
|
+
- lib/cubic/generators/base.rb
|
136
|
+
- lib/cubic/generators/config.rb
|
137
|
+
- lib/cubic/generators/controller.rb
|
138
|
+
- lib/cubic/generators/gemfile.rb
|
139
|
+
- lib/cubic/generators/migrations.rb
|
140
|
+
- lib/cubic/generators/model.rb
|
141
|
+
- lib/cubic/generators/templates/Rakefile
|
142
|
+
- lib/cubic/generators/templates/application.haml
|
143
|
+
- lib/cubic/generators/templates/application.rb
|
144
|
+
- lib/cubic/generators/templates/boot.rb
|
145
|
+
- lib/cubic/generators/templates/config.ru
|
146
|
+
- lib/cubic/generators/templates/cubic
|
147
|
+
- lib/cubic/generators/templates/database.rb
|
148
|
+
- lib/cubic/generators/templates/sitemap.rb
|
149
|
+
- lib/cubic/generators/view.rb
|
150
|
+
- lib/cubic/middleware/static.rb
|
151
|
+
- lib/cubic/render.rb
|
152
|
+
- lib/cubic/response.rb
|
153
|
+
- lib/cubic/router.rb
|
154
|
+
- lib/cubic/version.rb
|
155
|
+
homepage: https://github.com/Scootin/cubic
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata:
|
159
|
+
allowed_push_host: https://rubygems.org
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.4.5.1
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Small framework built with a focus on quick app generation.
|
180
|
+
test_files: []
|