slick 0.16.3 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -8
- data/.slick +0 -0
- data/.travis.yml +3 -5
- data/LICENSE +20 -0
- data/README.md +3 -32
- data/Rakefile +1 -0
- data/config.rb +8 -0
- data/config.ru +4 -0
- data/exe/slick +8 -0
- data/lib/slick.rb +50 -3
- data/lib/slick/command.rb +29 -0
- data/lib/slick/commands/create_database.rb +9 -0
- data/lib/slick/commands/drop_database.rb +9 -0
- data/lib/slick/commands/init_database.rb +9 -0
- data/lib/slick/commands/list_commands.rb +14 -0
- data/lib/slick/commands/migrate_database.rb +9 -0
- data/lib/slick/commands/reset_database.rb +10 -0
- data/lib/slick/commands/start_console.rb +14 -0
- data/lib/slick/commands/start_server.rb +14 -0
- data/lib/slick/concern.rb +19 -0
- data/lib/slick/database.rb +168 -0
- data/lib/slick/database/abstract_row.rb +13 -0
- data/lib/slick/database/column.rb +64 -0
- data/lib/slick/database/migration.rb +36 -0
- data/lib/slick/database/migrator.rb +67 -0
- data/lib/slick/database/row.rb +127 -0
- data/lib/slick/database/table.rb +381 -0
- data/lib/slick/database/union.rb +86 -0
- data/lib/slick/helper.rb +24 -0
- data/lib/slick/helpers.rb +4 -0
- data/lib/slick/helpers/dir.rb +6 -0
- data/lib/slick/helpers/echo.rb +6 -0
- data/lib/slick/helpers/grab.rb +10 -0
- data/lib/slick/helpers/html_builder.rb +180 -0
- data/lib/slick/helpers/text_builder.rb +22 -0
- data/lib/slick/monkey_patches/html_escape.rb +8 -0
- data/lib/slick/monkey_patches/html_unescape.rb +8 -0
- data/lib/slick/monkey_patches/paramify.rb +11 -0
- data/lib/slick/monkey_patches/pluralize.rb +8 -0
- data/lib/slick/monkey_patches/require_all.rb +18 -0
- data/lib/slick/monkey_patches/singularize.rb +8 -0
- data/lib/slick/monkey_patches/url_encode.rb +8 -0
- data/lib/slick/monkey_patches/url_escape.rb +8 -0
- data/lib/slick/monkey_patches/url_unescape.rb +8 -0
- data/lib/slick/project.rb +53 -0
- data/lib/slick/project_watcher.rb +36 -0
- data/lib/slick/registry.rb +39 -0
- data/lib/slick/request.rb +6 -0
- data/lib/slick/resource_factories/config.rb +14 -0
- data/lib/slick/resource_factories/database.rb +6 -0
- data/lib/slick/resource_factories/database_schema_cache.rb +6 -0
- data/lib/slick/resource_factories/database_session_cache.rb +6 -0
- data/lib/slick/resource_factories/env.rb +14 -0
- data/lib/slick/resource_factories/environment.rb +6 -0
- data/lib/slick/resource_factories/file.rb +6 -0
- data/lib/slick/resource_factories/params.rb +6 -0
- data/lib/slick/resource_factories/project.rb +6 -0
- data/lib/slick/resource_factories/request.rb +6 -0
- data/lib/slick/resource_factories/response.rb +6 -0
- data/lib/slick/resource_factories/web.rb +11 -0
- data/lib/slick/resource_factory.rb +35 -0
- data/lib/slick/resource_provider.rb +51 -0
- data/lib/slick/response.rb +14 -0
- data/lib/slick/util.rb +72 -0
- data/lib/slick/util/inflections.rb +122 -0
- data/lib/slick/util/params_hash.rb +38 -0
- data/lib/slick/version.rb +1 -1
- data/lib/slick/web.rb +4 -0
- data/lib/slick/web/dir.rb +92 -0
- data/lib/slick/web/file.rb +66 -0
- data/lib/slick/web/file_interpreter.rb +24 -0
- data/lib/slick/web/file_interpreters/erb.rb +33 -0
- data/lib/slick/web/file_interpreters/js.rb +17 -0
- data/lib/slick/web/file_interpreters/rb.rb +14 -0
- data/lib/slick/web/file_interpreters/sass.rb +30 -0
- data/lib/slick/web/node.rb +35 -0
- data/lib/slick/workspace.rb +8 -0
- data/slick.gemspec +15 -4
- data/web/_layout.erb +13 -0
- data/web/index.erb +7 -0
- data/web/javascripts/index.js +2 -0
- data/web/stylesheets/index.scss +2 -0
- metadata +127 -11
- data/Gemfile.lock +0 -22
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 362f91bd15f9d273529c1ff20dac7958b8264e0a851d7daae500b6b19f351010
|
4
|
+
data.tar.gz: 421bb5ec00ddc73f9ccd2a72517828ecf67a577e31cf887fae9e8e1ad60e0540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a519ba7ab7539a00ffe0969242ba735d8c0fc49d181f09e3f9ff506b0c796ea8e98fae165f2421a666678c672d69f8f82abb68e27b3d9d9ea336c2f4e920d8c2
|
7
|
+
data.tar.gz: 1b77d2bae6a222dea6abd2cd1c07c6cf1233ec5c40d33d6f06c3eb39561b511896c50037e9e2188242b51ba0e15a3405bb18d0511a423a88022e42fdd871bd53
|
data/.gitignore
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/
|
4
|
-
/
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
/tmp/
|
1
|
+
|
2
|
+
node_modules/
|
3
|
+
pkg/
|
4
|
+
dist/
|
5
|
+
*-bundle.js*
|
6
|
+
.DS_Store
|
7
|
+
Gemfile.lock
|
data/.slick
ADDED
File without changes
|
data/.travis.yml
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2020 Jody Salt
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,35 +1,6 @@
|
|
1
|
-
# Slick
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/slick`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'slick'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
1
|
|
19
|
-
|
20
|
-
|
21
|
-
$ gem install slick
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
2
|
+
# Slick
|
32
3
|
|
33
|
-
|
4
|
+
An entrepreneurial web framework that allows small (or one-man) teams to be highly productive.
|
34
5
|
|
35
|
-
|
6
|
+
[![Build Status](https://travis-ci.com/blognami/slick.svg?branch=master)](https://travis-ci.com/blognami/slick)
|
data/Rakefile
CHANGED
data/config.rb
ADDED
data/config.ru
ADDED
data/exe/slick
ADDED
data/lib/slick.rb
CHANGED
@@ -1,6 +1,53 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
require "slick/monkey_patches/require_all"
|
2
3
|
|
3
4
|
module Slick
|
4
|
-
|
5
|
-
|
5
|
+
|
6
|
+
require_all("slick/monkey_patches")
|
7
|
+
require_all("slick")
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
include Slick::Helpers
|
12
|
+
|
13
|
+
def resource_provider
|
14
|
+
@resource_provider ||= ResourceProvider.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
resource_provider.reset do
|
19
|
+
resource_provider["env"] = env
|
20
|
+
|
21
|
+
if file = web.find_file(request.path)
|
22
|
+
file.render(params)
|
23
|
+
else
|
24
|
+
response.status = 404
|
25
|
+
response.set_header("Content-Type", "text/plain")
|
26
|
+
response.body = ["Not found"]
|
27
|
+
end
|
28
|
+
|
29
|
+
response.to_a
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
require "bundler"
|
38
|
+
|
39
|
+
begin
|
40
|
+
Bundler.require(:default, Slick.resource_provider["environment"].to_sym)
|
41
|
+
rescue Bundler::GemfileNotFound
|
42
|
+
# do nothing
|
43
|
+
end
|
44
|
+
|
45
|
+
project = Slick.resource_provider["project"]
|
46
|
+
|
47
|
+
if project.exist? && ENV['WATCH_PROJECT'] == 'true'
|
48
|
+
Slick::ProjectWatcher.watch
|
49
|
+
end
|
50
|
+
|
51
|
+
project.lib_names.reverse.each do |lib_name|
|
52
|
+
require_all(lib_name)
|
6
53
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require "slick/registry"
|
3
|
+
require "slick/helpers"
|
4
|
+
|
5
|
+
class Slick::Command
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
include Slick::Registry
|
10
|
+
|
11
|
+
def run(name = 'list-commands', *args)
|
12
|
+
create(name, *args).run
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
include Slick::Helpers
|
18
|
+
|
19
|
+
attr_accessor :args
|
20
|
+
|
21
|
+
def initialize(*args)
|
22
|
+
@args = args
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
puts "No such command \"#{self.class.name}\""
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require "slick/command"
|
3
|
+
|
4
|
+
Class.new(Slick::Command){ register "list-commands" }.define_method "run" do
|
5
|
+
|
6
|
+
puts ""
|
7
|
+
puts "The following commands are available:"
|
8
|
+
puts ""
|
9
|
+
Slick::Command.registered_classes.keys.sort.each do |name|
|
10
|
+
puts " * #{name}"
|
11
|
+
end
|
12
|
+
puts ""
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require "slick/command"
|
3
|
+
|
4
|
+
Class.new(Slick::Command){ register "start-console" }.define_method "run" do
|
5
|
+
|
6
|
+
require "irb"
|
7
|
+
IRB.setup nil
|
8
|
+
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
9
|
+
require "irb/ext/multi-irb"
|
10
|
+
workspace = Slick::Workspace.new
|
11
|
+
workspace.instance_eval{ undef :source }
|
12
|
+
IRB.irb nil, workspace
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require "slick/command"
|
3
|
+
require "rack"
|
4
|
+
|
5
|
+
Class.new(Slick::Command){ register "start-server" }.define_method "run" do
|
6
|
+
if ENV['WATCH_PROJECT'] == 'true'
|
7
|
+
Rack::Server.start({
|
8
|
+
:app => Slick,
|
9
|
+
:Port => 3000
|
10
|
+
})
|
11
|
+
else
|
12
|
+
system("WATCH_PROJECT=true bundle exec slick start-server")
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module Slick::Concern
|
3
|
+
|
4
|
+
def missing_method_calls
|
5
|
+
@missing_method_calls ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def included(_module)
|
9
|
+
missing_method_calls.each do |missing_method_call|
|
10
|
+
args, block = missing_method_call
|
11
|
+
_module.send *args, &block
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(*args, &block)
|
16
|
+
missing_method_calls << [args, block]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
|
2
|
+
require "mysql2"
|
3
|
+
|
4
|
+
class Slick::Database
|
5
|
+
|
6
|
+
def initialize(config = {})
|
7
|
+
@config = config.paramify
|
8
|
+
run("use ?", @config.name.to_sym) if exist?
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(*args)
|
12
|
+
options = (args.last.kind_of?(Hash) ? args.pop : {}).paramify
|
13
|
+
query = _prepare(args)
|
14
|
+
|
15
|
+
Slick.resource_provider["database_schema_cache"].clear if query.match(/\A\s*(create|drop|alter)/i)
|
16
|
+
Slick.resource_provider["database_session_cache"].clear if query.match(/\A\s*(create|drop|alter|insert|update)/i)
|
17
|
+
|
18
|
+
rows = if options.cache
|
19
|
+
Slick.resource_provider["database_#{options.cache}_cache"]["query:#{query}"] ||= _fetch_rows(query)
|
20
|
+
else
|
21
|
+
_fetch_rows(query)
|
22
|
+
end
|
23
|
+
|
24
|
+
rows.map do |row|
|
25
|
+
out = row.clone
|
26
|
+
if out['_type']
|
27
|
+
out = Slick::Database::Row.create(out.delete('_type'), self, out)
|
28
|
+
end
|
29
|
+
out
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def exist?
|
34
|
+
run("show databases", :cache => "schema").map{|row| row["Database"]}.include?(@config.name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
if !exist?
|
39
|
+
run("create database ?", @config.name.to_sym)
|
40
|
+
run("use ?", @config.name.to_sym)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def drop
|
45
|
+
run("drop database ?", @config.name.to_sym) if exist?
|
46
|
+
@using = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def tables
|
50
|
+
if exist?
|
51
|
+
out = {}
|
52
|
+
run("show tables", :cache => "schema").each do |row|
|
53
|
+
name = row.values[0]
|
54
|
+
out[name] = send(name)
|
55
|
+
end
|
56
|
+
out
|
57
|
+
else
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_table(name)
|
63
|
+
send(name).create
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_table(name)
|
67
|
+
send(name).drop
|
68
|
+
end
|
69
|
+
|
70
|
+
def current_schema_version
|
71
|
+
Migrator.new(self).current_schema_version
|
72
|
+
end
|
73
|
+
|
74
|
+
def latest_schema_version
|
75
|
+
Migrator.new(self).latest_schema_version
|
76
|
+
end
|
77
|
+
|
78
|
+
def migrate(*args)
|
79
|
+
Migrator.new(self).migrate(*args)
|
80
|
+
end
|
81
|
+
|
82
|
+
def method_missing(name, *args, &block)
|
83
|
+
if args.length == 0
|
84
|
+
if Union.registered_classes[name.to_s]
|
85
|
+
out = Union.create(name, self)
|
86
|
+
else
|
87
|
+
out = Table.create(name, self)
|
88
|
+
end
|
89
|
+
|
90
|
+
if block
|
91
|
+
if block.arity > 0
|
92
|
+
block.call(out)
|
93
|
+
else
|
94
|
+
out.instance_eval(&block)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
out
|
99
|
+
else
|
100
|
+
super
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def _prepare(*args)
|
107
|
+
out = []
|
108
|
+
args = _flatten(args)
|
109
|
+
while(args.length > 0)
|
110
|
+
out << args.shift.to_s.gsub(/\?/) { |match| _escape(args.shift) }
|
111
|
+
end
|
112
|
+
out.join(' ')
|
113
|
+
end
|
114
|
+
|
115
|
+
def _flatten(items, out = [])
|
116
|
+
items.each do |item|
|
117
|
+
if item.kind_of? Array
|
118
|
+
_flatten(item, out)
|
119
|
+
else
|
120
|
+
out << item
|
121
|
+
end
|
122
|
+
end
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
126
|
+
def _escape(value)
|
127
|
+
if value.kind_of?(Slick::Database::Table)
|
128
|
+
_escape_identifier(value.instance_eval{ @alias })
|
129
|
+
elsif value.kind_of?(Slick::Database::Column)
|
130
|
+
alias_identifier = value.instance_eval{ @table }.instance_eval{ @alias }
|
131
|
+
column_identifier = value.instance_eval{ @name }
|
132
|
+
"#{_escape_identifier(alias_identifier)}.#{_escape_identifier(column_identifier)}"
|
133
|
+
elsif value.kind_of?(Symbol)
|
134
|
+
_escape_identifier(value)
|
135
|
+
elsif value.kind_of?(Numeric)
|
136
|
+
value
|
137
|
+
elsif value.kind_of?(NilClass)
|
138
|
+
"null"
|
139
|
+
else
|
140
|
+
"'#{_client.escape(value)}'"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def _escape_identifier(value)
|
145
|
+
"`#{value.to_s.gsub(/`/, '')}`"
|
146
|
+
end
|
147
|
+
|
148
|
+
def _fetch_rows(query)
|
149
|
+
puts ""
|
150
|
+
puts "Query: #{query}"
|
151
|
+
puts ""
|
152
|
+
|
153
|
+
out = []
|
154
|
+
result = _client.query(query)
|
155
|
+
result.each{|row| out << row} if result
|
156
|
+
out
|
157
|
+
end
|
158
|
+
|
159
|
+
def _client
|
160
|
+
@_client ||= Mysql2::Client.new({
|
161
|
+
:host => @config.host || '127.0.0.1',
|
162
|
+
:port => @config.port || 3306,
|
163
|
+
:username => @config.username || 'root',
|
164
|
+
:password => @config.password || ''
|
165
|
+
})
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|