mont 0.0.0 → 0.1.1

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +4 -2
  4. data/README.md +4 -4
  5. data/Rakefile +3 -3
  6. data/bin/mont +4 -0
  7. data/lib/mont/my_mont.rb +11 -0
  8. data/lib/mont/version.rb +1 -1
  9. data/lib/mont.rb +19 -3
  10. data/mont.gemspec +5 -3
  11. data/new_app_files/Gemfile +6 -0
  12. data/new_app_files/Gemfile.lock +44 -0
  13. data/new_app_files/app/views/errors.html.erb +12 -0
  14. data/new_app_files/lib/db_connection.rb +77 -0
  15. data/new_app_files/lib/exception_catcher.rb +38 -0
  16. data/new_app_files/lib/router.rb +60 -0
  17. data/new_app_files/lib/server.rb +29 -0
  18. data/new_app_files/lib/static_assets.rb +18 -0
  19. metadata +44 -24
  20. data/views/cats_controller/index.html.erb +0 -3
  21. data/views/cats_controller/new.html.erb +0 -11
  22. data/views/dogs_controller/index.html.erb +0 -8
  23. data/views/dogs_controller/new.html.erb +0 -21
  24. data/views/dogs_controller/show.html.erb +0 -1
  25. data/views/my_controller/counting_show.html.erb +0 -1
  26. data/views/my_controller/show.html.erb +0 -1
  27. /data/lib/{mont/templates/rescue.html.erb → cli.rb} +0 -0
  28. /data/{lib/mont → new_app_files/app/controllers}/controller_base.rb +0 -0
  29. /data/{lib/mont → new_app_files/app/controllers}/flash.rb +0 -0
  30. /data/{lib/mont → new_app_files/app/controllers}/session.rb +0 -0
  31. /data/{lib/mont → new_app_files/config/lib}/router.rb +0 -0
  32. /data/{lib/mont → new_app_files/config/lib}/show_exceptions.rb +0 -0
  33. /data/{lib/mont → new_app_files/config/lib}/static.rb +0 -0
  34. /data/{lib/mont → new_app_files}/config/server.rb +0 -0
  35. /data/{views/dummy_controller/index.html.erb → new_app_files/templates/rescue.html.erb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d630ceeb262a34ec2e009f9a2f2f79c4ac67456
4
- data.tar.gz: c39a7d6f9efc9cbeef14c4bed7bfc53504ccb105
3
+ metadata.gz: cd4059725d70c9459669f5b227a93994c8df59a9
4
+ data.tar.gz: e2a2ad1052b5cd88f3dbe299f936f1d539ddbbd5
5
5
  SHA512:
6
- metadata.gz: 0e90c9e88cecf750d0008b197514f21969bd86d48497b2cf6a26c9db42e8fd686aa7340b0c9cc9cfa3edeab98b3808f3bb3f747e731558d8027343665baeb7ab
7
- data.tar.gz: 17eed143838572ad48b06f81c665b0978f59764c8d902b0189eabe471f131f4b1673892727e5f3b89217ba3c30a9c05a9a9e942d5cdffe173cccc6688adbdcfe
6
+ metadata.gz: f709d654e059b88de17dc5eb1e3e0157aaa0c59afb57797b5ecdb32ddcc62437c0558f9e32f5e67935e89c9916aefc8e8120e10d991dd275c28a3f25ee39b14a
7
+ data.tar.gz: 6edbc64db00b1ee2cbf66d9e358f90ecdf9ee43dca5ce762f0ef8e61f3900a4ee9ad22208df27e8f28666218d0b34a7a65410c5d8d1b0b88ded32a50d84f520d
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  /spec/reports/
12
12
  /tmp/
13
13
  gem-readme.md
14
+ .rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mont (0.0.0)
4
+ mont (0.1.1)
5
+ thor
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -31,6 +32,7 @@ GEM
31
32
  rspec-mocks (3.1.3)
32
33
  rspec-support (~> 3.1.0)
33
34
  rspec-support (3.1.2)
35
+ thor (0.19.1)
34
36
  thread_safe (0.3.5)
35
37
  tzinfo (1.2.2)
36
38
  thread_safe (~> 0.1)
@@ -45,7 +47,7 @@ DEPENDENCIES
45
47
  mont!
46
48
  rack (< 2.0)
47
49
  rake (~> 10.0)
48
- rspec (~> 3.1.0)
50
+ rspec
49
51
 
50
52
  BUNDLED WITH
51
53
  1.12.5
data/README.md CHANGED
@@ -49,10 +49,10 @@ app
49
49
  └─── public
50
50
  ├── doge
51
51
  | └── much-wow.jpg
52
- └── summer
53
- └── june
54
- ├── sandle.png
55
- └── italian-ice.jpg
52
+ └── music
53
+ └── Darude
54
+ ├── Sandstorm.mp3
55
+ └── Rush.mp3
56
56
  ```
57
57
  Including contents in your app/public and it will automatically be served as a static assets.
58
58
 
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
- # require "rake/testtask"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
3
5
  task :default => :spec
4
6
 
5
7
  # Rake::TestTask.new do |t|
@@ -7,5 +9,3 @@ task :default => :spec
7
9
  # t.test_files = FileList["test/**/*_test.rb"]
8
10
  # t.verbose = true
9
11
  # end
10
- #
11
- # task :default => :test
data/bin/mont ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mont'
3
+
4
+ Mont::MyCLI.start(ARGV)
@@ -0,0 +1,11 @@
1
+ module Mont
2
+ end
3
+
4
+ module Mont::CLI
5
+ class MyMont < Thor
6
+ desc "new", "Generates a new Mont application."
7
+ def new
8
+ puts "Greetings!"
9
+ end
10
+ end
11
+ end
data/lib/mont/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mont
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/mont.rb CHANGED
@@ -1,6 +1,22 @@
1
- require "mont/version"
1
+ require 'mont/version'
2
+ require 'thor'
3
+ require 'mont/my_mont'
2
4
 
3
5
  module Mont
4
- # Your code goes here...
5
-
6
+ class MyCLI < Thor
7
+ desc "new", "'new' will generate a new Mont application in your working directory.'"
8
+
9
+ def new(app_name)
10
+ g = Generator.new
11
+ g.directory "../new_app_files", "./#{app_name.chomp}"
12
+ end
13
+ end
14
+ end
15
+
16
+ class Generator < Thor
17
+ include Thor::Actions
18
+
19
+ def self.source_root
20
+ File.dirname(__FILE__)
21
+ end
6
22
  end
data/mont.gemspec CHANGED
@@ -23,14 +23,16 @@ Gem::Specification.new do |spec|
23
23
  # end
24
24
 
25
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) }
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency 'thor'
31
+
30
32
  spec.add_development_dependency "bundler", "~> 1.12"
31
33
  spec.add_development_dependency "rake", "~> 10.0"
32
34
  spec.add_development_dependency "rack", "< 2.0"
33
35
  spec.add_development_dependency "byebug"
34
- spec.add_development_dependency "rspec", "~> 3.1.0"
36
+ spec.add_development_dependency "rspec"
35
37
  spec.add_development_dependency "activesupport", "< 5.0"
36
38
  end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack'
4
+ gem "activesupport"
5
+ gem 'byebug'
6
+ gem 'sqlite3'
@@ -0,0 +1,44 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.4)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ byebug (8.2.2)
11
+ diff-lcs (1.2.5)
12
+ i18n (0.6.11)
13
+ json (1.8.1)
14
+ minitest (5.4.0)
15
+ rack (1.6.4)
16
+ rspec (3.1.0)
17
+ rspec-core (~> 3.1.0)
18
+ rspec-expectations (~> 3.1.0)
19
+ rspec-mocks (~> 3.1.0)
20
+ rspec-core (3.1.7)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-expectations (3.1.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.1.0)
25
+ rspec-mocks (3.1.3)
26
+ rspec-support (~> 3.1.0)
27
+ rspec-support (3.1.2)
28
+ sqlite3 (1.3.11)
29
+ thread_safe (0.3.4)
30
+ tzinfo (1.2.1)
31
+ thread_safe (~> 0.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ activesupport
38
+ byebug
39
+ rack
40
+ rspec (~> 3.1.0)
41
+ sqlite3
42
+
43
+ BUNDLED WITH
44
+ 1.11.2
@@ -0,0 +1,12 @@
1
+ <h2>Error Message</h2>
2
+ <p><%= @message %></p>
3
+
4
+ <h2>Stack Trace</h2>
5
+ <ul>
6
+ <% @backtrace.each do |trace| %>
7
+ <li><%= trace %></li>
8
+ <% end %>
9
+ </ul>
10
+
11
+ <h3>Preview of Problematic Code</h3>
12
+ <p><%= @preview %></p>
@@ -0,0 +1,77 @@
1
+ require 'sqlite3'
2
+ require 'find'
3
+
4
+ PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
5
+ ROOT_FOLDER = File.dirname(__FILE__)
6
+
7
+ class DBConnection
8
+ def self.open(db_file_name)
9
+ @db = SQLite3::Database.new(db_file_name)
10
+ @db.results_as_hash = true
11
+ @db.type_translation = true
12
+
13
+ @db
14
+ end
15
+
16
+ def self.reset
17
+ sql_file = nil
18
+ db_file = nil
19
+
20
+ Find.find(ROOT_FOLDER) do |path|
21
+ if path =~ /.*\.db$/
22
+ db_file = path
23
+ elsif path =~ /.*\.sql$/
24
+ sql_file = path
25
+ end
26
+ end
27
+
28
+ commands = [
29
+ "rm '#{db_file}'",
30
+ "cat '#{sql_file}' | sqlite3 '#{db_file}'"
31
+ ]
32
+
33
+ commands.each { |command| `#{command}` }
34
+
35
+ Find.find(ROOT_FOLDER) do |path|
36
+ if path =~ /.*\.db$/
37
+ db_file = path
38
+ break
39
+ end
40
+ end
41
+
42
+ DBConnection.open(db_file)
43
+ end
44
+
45
+ def self.instance
46
+ reset if @db.nil?
47
+
48
+ @db
49
+ end
50
+
51
+ def self.execute(*args)
52
+ print_query(*args)
53
+ instance.execute(*args)
54
+ end
55
+
56
+ def self.execute2(*args)
57
+ print_query(*args)
58
+ instance.execute2(*args)
59
+ end
60
+
61
+ def self.last_insert_row_id
62
+ instance.last_insert_row_id
63
+ end
64
+
65
+ private
66
+
67
+ def self.print_query(query, *interpolation_args)
68
+ return unless PRINT_QUERIES
69
+
70
+ puts '--------------------'
71
+ puts query
72
+ unless interpolation_args.empty?
73
+ puts "interpolate: #{interpolation_args.inspect}"
74
+ end
75
+ puts '--------------------'
76
+ end
77
+ end
@@ -0,0 +1,38 @@
1
+ class ExceptionCatcher
2
+ attr_reader :app
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ begin
9
+ app.call(env)
10
+
11
+ rescue Exception => e
12
+ @backtrace = e.backtrace
13
+ @message = e.message
14
+ @preview = get_code_preview(@backtrace.first)
15
+
16
+ @res = Rack::Response.new
17
+ render_errors
18
+ @res.finish
19
+ end
20
+ end
21
+
22
+ private
23
+ def get_code_preview(code_backtrace)
24
+ match_data = /(.+\.rb):(\d+)/.match(code_backtrace)
25
+ file_path = match_data[1]
26
+ line_number = match_data[2].to_i
27
+ IO.readlines("#{file_path}")[line_number - 1]
28
+ end
29
+
30
+ def render_errors
31
+ path = "../app/views/errors.html.erb"
32
+ erb_file = File.read(path)
33
+ template = ERB.new(erb_file)
34
+
35
+ @res['Content-Type'] = 'text/html'
36
+ @res.write(template.result(binding))
37
+ end
38
+ end
@@ -0,0 +1,60 @@
1
+ class Route
2
+ attr_reader :pattern, :http_method, :controller_class, :action_name
3
+
4
+ def initialize(pattern, http_method, controller_class, action_name)
5
+ @pattern = pattern
6
+ @http_method = http_method
7
+ @controller_class = controller_class
8
+ @action_name = action_name
9
+ end
10
+
11
+ def matches?(req)
12
+ path = req.path
13
+ method = req.request_method.downcase
14
+ method == @http_method.downcase.to_s && path =~ @pattern
15
+ end
16
+
17
+ def run(req, res)
18
+ regex = Regexp.new(@pattern)
19
+ match_data = regex.match(req.path)
20
+ route_params = {}
21
+ match_data.names.each { |name| route_params[name] = match_data[name] }
22
+ @controller_class.new(req, res, route_params).invoke_action(@action_name)
23
+ end
24
+ end
25
+
26
+ class Router
27
+ attr_reader :routes
28
+
29
+ def initialize
30
+ @routes = []
31
+ end
32
+
33
+ def add_route(pattern, method, controller_class, action_name)
34
+ @routes << Route.new(pattern, method, controller_class, action_name)
35
+ end
36
+
37
+ def draw(&proc)
38
+ self.instance_eval(&proc)
39
+ end
40
+
41
+ [:get, :post, :put, :delete].each do |http_method|
42
+ define_method(http_method) do |pattern, controller_class, action_name|
43
+ add_route(pattern, http_method.to_s, controller_class, action_name)
44
+ end
45
+ end
46
+
47
+ def match(req)
48
+ @routes.find { |route| route.matches?(req) }
49
+ end
50
+
51
+ def run(req, res)
52
+ matching_route = match(req)
53
+ if matching_route
54
+ matching_route.run(req, res)
55
+ else
56
+ res.status = 404
57
+ res.write("No matching route found.")
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ require 'rack'
2
+ require_relative 'router'
3
+ require_relative 'exception_catcher'
4
+ require_relative 'static_assets'
5
+ require_relative '../app/controllers/controller_base'
6
+
7
+ router = Router.new
8
+ router.draw do
9
+ #specify the routes for your application here.
10
+ end
11
+
12
+ app = Proc.new do |env|
13
+ req = Rack::Request.new(env)
14
+ res = Rack::Response.new
15
+ router.run(req, res)
16
+ res.finish
17
+ end
18
+
19
+ middleware_stack = Rack::Builder.new do
20
+ #place your middleware here.
21
+ use ExceptionCatcher
22
+ use StaticAssets
23
+ run app
24
+ end.to_app
25
+
26
+ Rack::Server.start(
27
+ app: middleware_stack,
28
+ Port: 3000
29
+ )
@@ -0,0 +1,18 @@
1
+ class StaticAssets
2
+ attr_reader :app
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ req = Rack::Request.new(env)
9
+ match_data = /(\/public\/.+)/.match(req.path)
10
+ if match_data
11
+ res = Rack::Response.new
12
+ res.write(File.read("../app/#{match_data[1]}"))
13
+ res.finish
14
+ else
15
+ app.call(env)
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mac Siri
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +84,16 @@ dependencies:
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 3.1.0
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 3.1.0
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: activesupport
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +111,10 @@ dependencies:
97
111
  description: This is still WIP
98
112
  email:
99
113
  - krairit.siri@gmail.com
100
- executables: []
114
+ executables:
115
+ - console
116
+ - mont
117
+ - setup
101
118
  extensions: []
102
119
  extra_rdoc_files: []
103
120
  files:
@@ -108,26 +125,29 @@ files:
108
125
  - README.md
109
126
  - Rakefile
110
127
  - bin/console
128
+ - bin/mont
111
129
  - bin/setup
130
+ - lib/cli.rb
112
131
  - lib/mont.rb
113
- - lib/mont/config/server.rb
114
- - lib/mont/controller_base.rb
115
- - lib/mont/flash.rb
116
- - lib/mont/router.rb
117
- - lib/mont/session.rb
118
- - lib/mont/show_exceptions.rb
119
- - lib/mont/static.rb
120
- - lib/mont/templates/rescue.html.erb
132
+ - lib/mont/my_mont.rb
121
133
  - lib/mont/version.rb
122
134
  - mont.gemspec
123
- - views/cats_controller/index.html.erb
124
- - views/cats_controller/new.html.erb
125
- - views/dogs_controller/index.html.erb
126
- - views/dogs_controller/new.html.erb
127
- - views/dogs_controller/show.html.erb
128
- - views/dummy_controller/index.html.erb
129
- - views/my_controller/counting_show.html.erb
130
- - views/my_controller/show.html.erb
135
+ - new_app_files/Gemfile
136
+ - new_app_files/Gemfile.lock
137
+ - new_app_files/app/controllers/controller_base.rb
138
+ - new_app_files/app/controllers/flash.rb
139
+ - new_app_files/app/controllers/session.rb
140
+ - new_app_files/app/views/errors.html.erb
141
+ - new_app_files/config/lib/router.rb
142
+ - new_app_files/config/lib/show_exceptions.rb
143
+ - new_app_files/config/lib/static.rb
144
+ - new_app_files/config/server.rb
145
+ - new_app_files/lib/db_connection.rb
146
+ - new_app_files/lib/exception_catcher.rb
147
+ - new_app_files/lib/router.rb
148
+ - new_app_files/lib/server.rb
149
+ - new_app_files/lib/static_assets.rb
150
+ - new_app_files/templates/rescue.html.erb
131
151
  homepage: https://github.com/maestromac/Mont
132
152
  licenses:
133
153
  - MIT
@@ -1,3 +0,0 @@
1
- <h1>ALL THE CATS</h1>
2
- <pre><%= @cats.to_s %></pre>
3
- <a href="/cats/new">New cat!</a>
@@ -1,11 +0,0 @@
1
- <form action="/cats" method="POST">
2
- <label>Name
3
- <input type="text" name="cat[name]" value="<%= @cat.name %>">
4
- </label>
5
-
6
- <label>Owner
7
- <input type="text" name="cat[owner]" value="<%= @cat.owner %>">
8
- </label>
9
-
10
- <input type="submit">
11
- </form>
@@ -1,8 +0,0 @@
1
- <h1>ALL THE DOGS</h1>
2
-
3
- <% if flash[:notice] %>
4
- Notice: <%= flash[:notice] %>
5
- <% end %>
6
-
7
- <pre>Dog Data: <%= @dogs.to_s %></pre>
8
- <a href="/dogs/new">New Dog!</a>
@@ -1,21 +0,0 @@
1
- <% if flash[:errors] %>
2
- <% flash[:errors].each do |error| %>
3
- <%= error %>
4
- <% end %>
5
- <% end %>
6
-
7
- <form action="/dogs" method="POST">
8
- <label>Name
9
- <input type="text" name="dog[name]" value="<%= @dog.name %>">
10
- </label>
11
-
12
- <!-- <label>Form Authenticity Token
13
- <input type="text" name="authenticity_token" value="<%= # form_authenticity_token %>">
14
- </label> -->
15
-
16
- <label>Owner
17
- <input type="text" name="dog[owner]" value="<%= @dog.owner %>">
18
- </label>
19
-
20
- <input type="submit">
21
- </form>
@@ -1 +0,0 @@
1
- <%= link_to "all dogs", dogs_path %>
@@ -1 +0,0 @@
1
- <%= session["count"] %>
@@ -1 +0,0 @@
1
- <%= (1..10).to_a.join(", ") %>
File without changes
File without changes
File without changes
File without changes