slick 0.16.3 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -8
  3. data/.slick +0 -0
  4. data/.travis.yml +3 -5
  5. data/LICENSE +20 -0
  6. data/README.md +3 -32
  7. data/Rakefile +1 -0
  8. data/config.rb +8 -0
  9. data/config.ru +4 -0
  10. data/exe/slick +8 -0
  11. data/lib/slick.rb +50 -3
  12. data/lib/slick/command.rb +29 -0
  13. data/lib/slick/commands/create_database.rb +9 -0
  14. data/lib/slick/commands/drop_database.rb +9 -0
  15. data/lib/slick/commands/init_database.rb +9 -0
  16. data/lib/slick/commands/list_commands.rb +14 -0
  17. data/lib/slick/commands/migrate_database.rb +9 -0
  18. data/lib/slick/commands/reset_database.rb +10 -0
  19. data/lib/slick/commands/start_console.rb +14 -0
  20. data/lib/slick/commands/start_server.rb +14 -0
  21. data/lib/slick/concern.rb +19 -0
  22. data/lib/slick/database.rb +168 -0
  23. data/lib/slick/database/abstract_row.rb +13 -0
  24. data/lib/slick/database/column.rb +64 -0
  25. data/lib/slick/database/migration.rb +36 -0
  26. data/lib/slick/database/migrator.rb +67 -0
  27. data/lib/slick/database/row.rb +127 -0
  28. data/lib/slick/database/table.rb +381 -0
  29. data/lib/slick/database/union.rb +86 -0
  30. data/lib/slick/helper.rb +24 -0
  31. data/lib/slick/helpers.rb +4 -0
  32. data/lib/slick/helpers/dir.rb +6 -0
  33. data/lib/slick/helpers/echo.rb +6 -0
  34. data/lib/slick/helpers/grab.rb +10 -0
  35. data/lib/slick/helpers/html_builder.rb +180 -0
  36. data/lib/slick/helpers/text_builder.rb +22 -0
  37. data/lib/slick/monkey_patches/html_escape.rb +8 -0
  38. data/lib/slick/monkey_patches/html_unescape.rb +8 -0
  39. data/lib/slick/monkey_patches/paramify.rb +11 -0
  40. data/lib/slick/monkey_patches/pluralize.rb +8 -0
  41. data/lib/slick/monkey_patches/require_all.rb +18 -0
  42. data/lib/slick/monkey_patches/singularize.rb +8 -0
  43. data/lib/slick/monkey_patches/url_encode.rb +8 -0
  44. data/lib/slick/monkey_patches/url_escape.rb +8 -0
  45. data/lib/slick/monkey_patches/url_unescape.rb +8 -0
  46. data/lib/slick/project.rb +53 -0
  47. data/lib/slick/project_watcher.rb +36 -0
  48. data/lib/slick/registry.rb +39 -0
  49. data/lib/slick/request.rb +6 -0
  50. data/lib/slick/resource_factories/config.rb +14 -0
  51. data/lib/slick/resource_factories/database.rb +6 -0
  52. data/lib/slick/resource_factories/database_schema_cache.rb +6 -0
  53. data/lib/slick/resource_factories/database_session_cache.rb +6 -0
  54. data/lib/slick/resource_factories/env.rb +14 -0
  55. data/lib/slick/resource_factories/environment.rb +6 -0
  56. data/lib/slick/resource_factories/file.rb +6 -0
  57. data/lib/slick/resource_factories/params.rb +6 -0
  58. data/lib/slick/resource_factories/project.rb +6 -0
  59. data/lib/slick/resource_factories/request.rb +6 -0
  60. data/lib/slick/resource_factories/response.rb +6 -0
  61. data/lib/slick/resource_factories/web.rb +11 -0
  62. data/lib/slick/resource_factory.rb +35 -0
  63. data/lib/slick/resource_provider.rb +51 -0
  64. data/lib/slick/response.rb +14 -0
  65. data/lib/slick/util.rb +72 -0
  66. data/lib/slick/util/inflections.rb +122 -0
  67. data/lib/slick/util/params_hash.rb +38 -0
  68. data/lib/slick/version.rb +1 -1
  69. data/lib/slick/web.rb +4 -0
  70. data/lib/slick/web/dir.rb +92 -0
  71. data/lib/slick/web/file.rb +66 -0
  72. data/lib/slick/web/file_interpreter.rb +24 -0
  73. data/lib/slick/web/file_interpreters/erb.rb +33 -0
  74. data/lib/slick/web/file_interpreters/js.rb +17 -0
  75. data/lib/slick/web/file_interpreters/rb.rb +14 -0
  76. data/lib/slick/web/file_interpreters/sass.rb +30 -0
  77. data/lib/slick/web/node.rb +35 -0
  78. data/lib/slick/workspace.rb +8 -0
  79. data/slick.gemspec +15 -4
  80. data/web/_layout.erb +13 -0
  81. data/web/index.erb +7 -0
  82. data/web/javascripts/index.js +2 -0
  83. data/web/stylesheets/index.scss +2 -0
  84. metadata +127 -11
  85. data/Gemfile.lock +0 -22
  86. data/bin/console +0 -14
  87. data/bin/setup +0 -8
@@ -0,0 +1,86 @@
1
+
2
+ require "slick/registry"
3
+
4
+ class Slick::Database::Union
5
+
6
+ class << self
7
+
8
+ include Slick::Registry
9
+
10
+ def register(name, *args)
11
+ super
12
+ Class.new(Slick::Helper){ register name }.define_method "call" do |*args, &block|
13
+ database.send(self.class.name, *args, &block)
14
+ end
15
+ end
16
+
17
+ def table_classes
18
+ @table_classes ||= []
19
+ end
20
+
21
+ end
22
+
23
+ def initialize(database, collections = nil)
24
+ @database = database
25
+ @tables = []
26
+ (collections || self.class.table_classes.map{|table_class| table_class.new(@database)}).each do |table|
27
+ if table.kind_of?(Slick::Database::Union)
28
+ @tables.concat(table.instance_variable_get(:@tables))
29
+ elsif table.kind_of?(Slick::Database::Table)
30
+ @tables << table
31
+ end
32
+ end
33
+ end
34
+
35
+ def +(collection)
36
+ Slick::Database::Union.new(@database, @tables.clone.push(collection))
37
+ end
38
+
39
+ def all(options = {})
40
+ @database.run(_generate_select_sql(options), options)
41
+ end
42
+
43
+ def each(options = {}, &block)
44
+ @database.run(_generate_select_sql(options), options).each(&block)
45
+ end
46
+
47
+ def explain(options = {})
48
+ @database.send(:_prepare, _generate_select_sql(options))
49
+ end
50
+
51
+ def inspect
52
+ all
53
+ end
54
+
55
+ def method_missing(*args, &block)
56
+ Slick::Database::Union.new(@database, @tables.map{|table| table.send(*args, &block)})
57
+ end
58
+
59
+ private
60
+
61
+ def _generate_select_sql(options = {})
62
+ out = []
63
+ @tables.each do |table|
64
+ out << 'union all' if out.count > 0
65
+ out << table.send(:_generate_select_sql, {
66
+ :column_names => _column_names,
67
+ :order_by => nil,
68
+ :limit => nil
69
+ })
70
+ end
71
+ out
72
+ end
73
+
74
+ def _column_names
75
+ @_column_names ||= begin
76
+ out = []
77
+ @tables.each do |table|
78
+ table.columns.keys.each do |column_name|
79
+ out << column_name if !out.include?(table)
80
+ end
81
+ end
82
+ out
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,24 @@
1
+
2
+ require "slick/registry"
3
+ require "slick/helpers"
4
+
5
+ class Slick::Helper
6
+
7
+ class << self
8
+
9
+ include Slick::Registry
10
+
11
+ def register(name)
12
+ super
13
+ Slick::Helpers.class_eval("def #{name}(*args, &block); ::Slick::Helper.create(\"#{name}\").call(*args, &block); end")
14
+ end
15
+
16
+ end
17
+
18
+ include Slick::Helpers
19
+
20
+ def call(*args, &block)
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module Slick::Helpers
3
+
4
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require "slick/helpers"
3
+
4
+ Slick::Helpers.define_method :dir do
5
+ file && file.parent
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require "slick/helpers"
3
+
4
+ Slick::Helpers.define_method :echo do |stringable|
5
+ response.body << stringable.to_s
6
+ end
@@ -0,0 +1,10 @@
1
+
2
+ require "slick/helpers"
3
+
4
+ Slick::Helpers.define_method :grab do |&block|
5
+ previous_response = Slick.resource_provider["response"]
6
+ out = Slick.resource_provider["response"] = Slick::ResourceFactory.create("response").create
7
+ block.call
8
+ Slick.resource_provider["response"] = previous_response
9
+ out
10
+ end
@@ -0,0 +1,180 @@
1
+
2
+ require "slick/helpers"
3
+
4
+ module Slick::Helpers
5
+
6
+ def text(stringable)
7
+ echo stringable.html_escape
8
+ end
9
+
10
+ SELF_CLOSING_TAGS = [
11
+ 'area',
12
+ 'base',
13
+ 'br',
14
+ 'embed',
15
+ 'hr',
16
+ 'iframe',
17
+ 'img',
18
+ 'input',
19
+ 'link',
20
+ 'meta',
21
+ 'param',
22
+ 'source',
23
+ 'track'
24
+ ]
25
+
26
+ TEXT_ONLY_TAGS = [
27
+ 'script',
28
+ 'style'
29
+ ]
30
+
31
+ def html_tag(name, *args, &block)
32
+ name = name.to_s.downcase
33
+ echo "<#{name.html_escape}"
34
+ if args.last.kind_of?(Hash)
35
+ attributes = args.pop
36
+ attributes.each do |name, value|
37
+ echo " #{name.html_escape}=\"#{value.html_escape}\""
38
+ end
39
+ end
40
+ echo ">"
41
+ if !SELF_CLOSING_TAGS.include?(name)
42
+ if args.first
43
+ content = args.shift
44
+ if TEXT_ONLY_TAGS.include?(name)
45
+ echo content
46
+ else
47
+ text content
48
+ end
49
+ end
50
+ block.call if block
51
+ echo "</#{name.html_escape}>"
52
+ end
53
+ nil
54
+ end
55
+
56
+ TAGS = [
57
+ "html",
58
+ "a",
59
+ "abbr",
60
+ "address",
61
+ "area",
62
+ "article",
63
+ "aside",
64
+ "audio",
65
+ "b",
66
+ "base",
67
+ "bdi",
68
+ "bdo",
69
+ "blockquote",
70
+ "body",
71
+ "br",
72
+ "button",
73
+ "canvas",
74
+ "caption",
75
+ "cite",
76
+ "code",
77
+ "col",
78
+ "colgroup",
79
+ "content",
80
+ "data",
81
+ "datalist",
82
+ "dd",
83
+ "del",
84
+ "details",
85
+ "dfn",
86
+ "dialog",
87
+ "div",
88
+ "dl",
89
+ "dt",
90
+ "em",
91
+ "embed",
92
+ "fieldset",
93
+ "figcaption",
94
+ "figure",
95
+ "footer",
96
+ "form",
97
+ "h1",
98
+ "h2",
99
+ "h3",
100
+ "h4",
101
+ "h5",
102
+ "h6",
103
+ "head",
104
+ "header",
105
+ "hr",
106
+ "html",
107
+ "i",
108
+ "iframe",
109
+ "img",
110
+ "input",
111
+ "ins",
112
+ "kbd",
113
+ "keygen",
114
+ "label",
115
+ "legend",
116
+ "li",
117
+ "link",
118
+ "main",
119
+ "map",
120
+ "mark",
121
+ "menu",
122
+ "menuitem",
123
+ "meta",
124
+ "meter",
125
+ "nav",
126
+ "noscript",
127
+ "object",
128
+ "ol",
129
+ "optgroup",
130
+ "option",
131
+ "output",
132
+ "p",
133
+ "param",
134
+ "picture",
135
+ "pre",
136
+ "progress",
137
+ "q",
138
+ "rp",
139
+ "rt",
140
+ "rtc",
141
+ "ruby",
142
+ "s",
143
+ "samp",
144
+ "script",
145
+ "section",
146
+ "select",
147
+ "shadow",
148
+ "slot",
149
+ "small",
150
+ "source",
151
+ "span",
152
+ "strong",
153
+ "style",
154
+ "sub",
155
+ "summary",
156
+ "sup",
157
+ "table",
158
+ "tbody",
159
+ "td",
160
+ "template",
161
+ "textarea",
162
+ "tfoot",
163
+ "th",
164
+ "thead",
165
+ "time",
166
+ "title",
167
+ "tr",
168
+ "track",
169
+ "u",
170
+ "ul",
171
+ "var",
172
+ "video",
173
+ "wbr"
174
+ ]
175
+
176
+ TAGS.each do |name|
177
+ class_eval("def #{name}(*args, &block); html_tag(\"#{name}\", *args, &block); end")
178
+ end
179
+
180
+ end
@@ -0,0 +1,22 @@
1
+
2
+ require "slick/helpers"
3
+
4
+ module Slick::Helpers
5
+
6
+ def line(stringable = "")
7
+ if response.body.length > 0
8
+ echo "\n#{stringable}"
9
+ else
10
+ echo stringable
11
+ end
12
+ nil
13
+ end
14
+
15
+ def indent(&block)
16
+ grab(&block).to_s.split(/\n/).each do |stringable|
17
+ line " #{stringable}"
18
+ end
19
+ nil
20
+ end
21
+
22
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def html_escape
5
+ Slick::Util.html_escape(self)
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def html_unescape
5
+ Slick::Util.html_unescape(self)
6
+ end
7
+
8
+ end
@@ -0,0 +1,11 @@
1
+
2
+
3
+ require_all "slick/util"
4
+
5
+ class Object
6
+
7
+ def paramify
8
+ Slick::Util.paramify(self)
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def pluralize
5
+ Slick::Util.pluralize(to_s)
6
+ end
7
+
8
+ end
@@ -0,0 +1,18 @@
1
+
2
+ module Kernel
3
+
4
+ def require_all(path)
5
+ $LOAD_PATH.each do |current_load_path|
6
+ candidate_path = "#{current_load_path}/#{path}"
7
+ require path if File.exist?("#{candidate_path}.rb") || File.exist?("#{candidate_path}.ruby")
8
+
9
+ if Dir.exist?(candidate_path)
10
+ Dir.open(candidate_path).sort.each do |item|
11
+ item = item.sub(/(\.[^\.]+)$/, '')
12
+ require_all("#{path}/#{item}") if item != '..' && item != '.'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def singularize
5
+ Slick::Util.singularize(to_s)
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def url_encode
5
+ Slick::Util.url_encode(self)
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def url_escape
5
+ Slick::Util.url_escape(self)
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Object
3
+
4
+ def url_unescape
5
+ Slick::Util.url_unescape(self)
6
+ end
7
+
8
+ end