silicon 0.2.0 → 0.3.0

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: adab41a6ed0b0a061fa8342724d6c7ddea1ec9ce
4
- data.tar.gz: bee0524057d03b79906ea0d162963082f9a949fd
3
+ metadata.gz: b42a17f2843d05d79a364238d2acab60af7b58fb
4
+ data.tar.gz: 3ef558e06e125ce333da1076ecf95e07deed709b
5
5
  SHA512:
6
- metadata.gz: f8d7ea151bab27929bb6bce0ba34ce56b54bfa9c7d5a5b73bab7122db39e351cfbec2241f617db8c60816bda171844f9955d7980f1a1ab383dfaec796ff91731
7
- data.tar.gz: 800c81254ae7a6ee8aea32e56eb3ace062a71d9e215a37c18851a7460584dc3f41727b88aa4634e3dd6df49edba2af3479f36be9bab8ecc2a7629017402086af
6
+ metadata.gz: 6090adf8bb5518c4da8239908592d7be26aa35f7ae3af6c2b9c0d8ac2d2bb586ea5a99c9a2ac9e289820046c03400022d34a79d1b6090ca341c489c4258eeeeb
7
+ data.tar.gz: a9892ea638f31505e4df44368e26bee167c93ee040bdff42f70b2f58b8e01f6a1836f6308d57362b31c13b3c63154721ae2541d5bb39595211b6df727baefcb5
data/README.md CHANGED
@@ -347,13 +347,6 @@ Or install it yourself as:
347
347
 
348
348
  ## Development
349
349
 
350
- Before making any contributions please make sure you are agree:
351
-
352
- * 3 lines of code is better than 100 for the same functionality implementation, 0 lines is the best.
353
- * Keep initial idea as simple as it possible. Plugins for additional functionality are more preferable.
354
- * Do not use comments for obvious code; if your code is not obvious then try to make it obvious -
355
- extract method, variable, perform more steps to make it more clear.
356
-
357
350
  Usual, but always helpful steps:
358
351
 
359
352
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/silicon/app.rb CHANGED
@@ -15,6 +15,8 @@ require 'silicon/routing/routing'
15
15
 
16
16
  module Silicon
17
17
  class App
18
+ attr_reader :routes
19
+
18
20
  def initialize(container = Hypo::Container.new)
19
21
  @container = container
20
22
 
@@ -43,7 +45,8 @@ module Silicon
43
45
 
44
46
  def register_dependencies
45
47
  instances = {
46
- config_file_path: 'silicon.yaml'
48
+ config_file_path: 'silicon.yml',
49
+ silicon_env: ENV['SILICON_ENV'] || 'development'
47
50
  }
48
51
 
49
52
  instances.keys.each do |name|
@@ -83,8 +86,8 @@ module Silicon
83
86
  end
84
87
 
85
88
  def parse_routes
86
- routes = @route_parser.parse
87
- @route_matcher = Routing::Matcher.new(routes)
89
+ @routes = @route_parser.parse
90
+ @route_matcher = Routing::Matcher.new(@routes)
88
91
  end
89
92
  end
90
93
  end
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'terminal-table'
2
3
 
3
4
  module Silicon
4
5
  class CLI < Thor
@@ -8,15 +9,49 @@ module Silicon
8
9
  File.dirname(__FILE__)
9
10
  end
10
11
 
11
- desc 'new NAME', 'create new Silicon application'
12
+ desc 'new NAME', 'Create new Silicon application'
12
13
  def new(name)
13
- copy_file 'templates/app.rb', "#{name}/app/app.rb"
14
- copy_file 'templates/app.routes', "#{name}/app/app.routes"
14
+ copy_file 'templates/app/app.rb', "#{name}/app/app.rb"
15
+ copy_file 'templates/app/app.routes', "#{name}/app/app.routes"
15
16
  copy_file 'templates/silicon.yml', "#{name}/silicon.yml"
16
17
  copy_file 'templates/config.ru', "#{name}/config.ru"
17
18
  copy_file 'templates/views/show_welcome.json.jbuilder', "#{name}/app/views/show_welcome.json.jbuilder"
18
19
  copy_file 'templates/actions/common/handle_errors.rb', "#{name}/app/actions/common/handle_errors.rb"
20
+ copy_file 'templates/Gemfile', "#{name}/Gemfile"
19
21
  template 'templates/actions/welcome.tt', "#{name}/app/actions/welcome.rb", {app_name: name}
22
+
23
+ inside name do
24
+ run 'bundle'
25
+ end
26
+ end
27
+
28
+ desc 'routes', 'Show Silicon application routes'
29
+ def routes
30
+ require './app/app'
31
+ app = App.new
32
+
33
+ headings = ['HTTP Verb', 'Path', 'Action Chain']
34
+ rows = app.routes.map do |route|
35
+ indent = ''
36
+ commands = []
37
+ route.commands.each_with_index do |c, index|
38
+ indent += ' ' if c.sequential? && index > 0
39
+
40
+ prefix = '->' if c.sequential?
41
+ prefix = '=>' if c.parallel?
42
+ prefix = '=*' if c.async?
43
+
44
+ commands << "#{indent} #{prefix} #{c.name}"
45
+ end
46
+
47
+
48
+ commands = commands.join("\n")
49
+ [route.http_verb, route.path, commands]
50
+ end
51
+
52
+ table = Terminal::Table.new(headings: headings, rows: rows)
53
+ table.style = {all_separators: true}
54
+ puts table
20
55
  end
21
56
  end
22
57
  end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack-cors'
4
+ gem 'silicon'
@@ -1,8 +1,17 @@
1
1
  require 'rack'
2
- require './app'
2
+ require 'rack/cors'
3
+ require './app/app'
3
4
 
4
5
  use Rack::Parser, :content_types => {
5
6
  'application/json' => Proc.new { |body| ::MultiJson.decode body }
6
7
  }
7
8
 
9
+ use Rack::Cors do
10
+ # Setup your CORS policy
11
+ end
12
+
13
+ if ENV['SILICON_ENV'] == 'development' || ENV['SILICON_ENV'] == ''
14
+ use Rack::Reloader
15
+ end
16
+
8
17
  run App.new
@@ -1,11 +1,18 @@
1
1
  module Silicon
2
2
  class DependencyLoader
3
- def initialize(container, type_loader)
3
+ def initialize(container, type_loader, silicon_env)
4
4
  @container = container
5
+ @type_loader = type_loader
5
6
  @types = type_loader.load_types
7
+ @silicon_env = silicon_env
6
8
  end
7
9
 
8
10
  def load_components
11
+ if @silicon_env == 'development'
12
+ # every time reload types in development mode
13
+ @types = @type_loader.load_types
14
+ end
15
+
9
16
  @types.each do |type|
10
17
  @container.register(type).using_lifetime(:scope).bound_to(:silicon_request)
11
18
  end
@@ -1,4 +1,4 @@
1
- require 'silicon/routing/route'
1
+ require 'silicon/routing/route'
2
2
 
3
3
  module Silicon
4
4
  module Routing
@@ -14,7 +14,7 @@ module Silicon
14
14
  result = []
15
15
 
16
16
  node = sections.node
17
- restore_hierarchy(node, nil,node.to_hash)
17
+ restore_hierarchy(node, nil, node.to_hash)
18
18
 
19
19
  @route_params.each do |route|
20
20
  if route[:actions]
@@ -8,7 +8,7 @@ module Silicon
8
8
  end
9
9
 
10
10
  def match(path, http_method)
11
- segments = path.split('/')
11
+ segments = path.split('/').concat(['/'])
12
12
  params = {}
13
13
  matched = nil
14
14
 
@@ -6,12 +6,16 @@ module Silicon
6
6
 
7
7
  def initialize(hash)
8
8
  @http_verb = hash[:http_verb]
9
- @path = hash[:path].sub('.', '')
9
+
10
+ @path = hash[:path].sub('.', '/').sub('//', '/')
11
+
10
12
  @params = hash[:params]
11
13
  @commands = hash[:commands]
12
14
  @view = hash[:view]
13
15
  @http_status = hash[:http_status]
14
- @segments = @path.split('/')
16
+
17
+ @segments = @path.split('/').concat(['/'])
18
+
15
19
  @catch = hash[:catch]
16
20
  end
17
21
  end
@@ -1,11 +1,18 @@
1
1
  module Silicon
2
2
  class TemplateRegistry
3
- def initialize(template_loader, silicon_config)
3
+ def initialize(template_loader, silicon_config, silicon_env)
4
+ @template_loader = template_loader
4
5
  @templates = template_loader.load_templates
5
6
  @config = silicon_config
7
+ @silicon_env = silicon_env
6
8
  end
7
9
 
8
10
  def get(name, type)
11
+ if @silicon_env == 'development'
12
+ # every time reload templates in development mode
13
+ @templates = @template_loader.load_templates
14
+ end
15
+
9
16
  directory = @config[:path][:views]
10
17
  template_path = File.join(directory, name + ".#{type}")
11
18
  match = @templates.keys.find{|k| k.include? template_path}
@@ -1,3 +1,3 @@
1
1
  module Silicon
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/silicon.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['vova.kalinkin@gmail.com']
11
11
 
12
12
  spec.summary = 'Silicon is a minimalistic web API framework.'
13
- spec.description = 'The philosophy of Silicon is to provide minimum' \
13
+ spec.description = 'The philosophy of Silicon is to provide minimalistic' \
14
14
  ' middleware between your model and API client.'
15
15
 
16
16
  spec.homepage = 'https://github.com/cylon-v/silicon'
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'treetop', '~> 1.6.8'
37
37
  spec.add_dependency 'jbuilder', '~> 2.7.0'
38
38
  spec.add_dependency 'rack-parser', '~> 0.7.0'
39
+ spec.add_dependency 'terminal-table', '~> 1.8.0'
39
40
 
40
41
  spec.add_development_dependency 'bundler', '~> 1.15'
41
42
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-05 00:00:00.000000000 Z
11
+ date: 2018-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypo
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.7.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: terminal-table
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,8 +178,8 @@ dependencies:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0.15'
167
- description: The philosophy of Silicon is to provide minimum middleware between your
168
- model and API client.
181
+ description: The philosophy of Silicon is to provide minimalistic middleware between
182
+ your model and API client.
169
183
  email:
170
184
  - vova.kalinkin@gmail.com
171
185
  executables:
@@ -194,10 +208,11 @@ files:
194
208
  - lib/silicon/errors/view_engine_error.rb
195
209
  - lib/silicon/extensions/hash.rb
196
210
  - lib/silicon/generators/cli.rb
211
+ - lib/silicon/generators/templates/Gemfile
197
212
  - lib/silicon/generators/templates/actions/common/handle_errors.rb
198
213
  - lib/silicon/generators/templates/actions/welcome.tt
199
- - lib/silicon/generators/templates/app.rb
200
- - lib/silicon/generators/templates/app.routes
214
+ - lib/silicon/generators/templates/app/app.rb
215
+ - lib/silicon/generators/templates/app/app.routes
201
216
  - lib/silicon/generators/templates/config.ru
202
217
  - lib/silicon/generators/templates/silicon.yml
203
218
  - lib/silicon/generators/templates/views/show_welcome.json.jbuilder