noodles 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +10 -0
- data/Gemfile +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +9 -1
- data/Rakefile +10 -0
- data/bin/noodles +2 -0
- data/cli/noodles_cli.rb +92 -0
- data/cli/template/.gitignore +0 -0
- data/cli/template/Gemfile +6 -0
- data/cli/template/app/controllers/.keep +0 -0
- data/cli/template/app/handlers/.keep +0 -0
- data/cli/template/app/templates/.keep +0 -0
- data/cli/template/app/views/.keep +0 -0
- data/cli/template/config.ru +12 -0
- data/cli/template/config/application.rb +7 -0
- data/cli/template/config/router.rb +2 -0
- data/cli/template/config/secrets.yml +7 -0
- data/cli/template/config/setup.rb +3 -0
- data/cli/template/public/css/.keep +0 -0
- data/cli/template/public/images/.keep +0 -0
- data/cli/template/public/js/.keep +0 -0
- data/lib/noodles.rb +51 -3
- data/lib/noodles/application.rb +23 -0
- data/lib/noodles/cache.rb +6 -0
- data/lib/noodles/dependencies.rb +12 -0
- data/lib/noodles/environment.rb +47 -0
- data/lib/noodles/http/application.rb +34 -0
- data/lib/noodles/http/controller.rb +106 -0
- data/lib/noodles/http/errors/no_router_error.rb +9 -0
- data/lib/noodles/http/router.rb +81 -0
- data/lib/noodles/http/view.rb +6 -0
- data/lib/noodles/utils.rb +8 -0
- data/lib/noodles/version.rb +1 -1
- data/lib/noodles/websocket/application.rb +14 -0
- data/lib/noodles/websocket/channel.rb +22 -0
- data/lib/noodles/websocket/handler.rb +47 -0
- data/lib/noodles/websocket/routing.rb +12 -0
- data/noodles.gemspec +22 -6
- data/test/secrets.yml +11 -0
- data/test/templates/current_user_temp.erb +1 -0
- data/test/templates/current_user_temp.haml +1 -0
- data/test/templates/current_user_temp.slim +1 -0
- data/test/templates/index.haml +2 -0
- data/test/templates/index.slim +2 -0
- data/test/templates/layout.haml +3 -0
- data/test/templates/show.erb +1 -0
- data/test/templates/with_variables.erb +2 -0
- data/test/templates/with_variables.haml +2 -0
- data/test/templates/with_variables.slim +2 -0
- data/test/test_application.rb +299 -0
- data/test/test_cache.rb +66 -0
- data/test/test_environment.rb +24 -0
- data/test/test_helper.rb +10 -0
- data/test/test_secrets.rb +24 -0
- metadata +271 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a896063e69e7bb35bc1e1cf23c8100d421d408d6
|
4
|
+
data.tar.gz: 1282c8f3b37bef8dddada044f10f81ff8f6a1472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a6721974b100c1904f77b019f41e5452066aa6cfc3fa0801da3ad62338899d90efe0cc7fb0a3cd4b9bb2b2f06cc50fdc7056b7d4229b07a63da6636c9c082f
|
7
|
+
data.tar.gz: 68039d453bc0109a1d6cc1da5f766f13e6635f15f16af2f6c77f4dc1c252d9e65691cf342ba1684ddf6ecd635b31e3f7fd860fbab002de1d69ff0c12b84655ad
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.1
|
6
|
+
services:
|
7
|
+
- memcached
|
8
|
+
env:
|
9
|
+
global:
|
10
|
+
secure: BGfmqUck2al6tPwv0KQKwbdBKLPIUEkxy1bn3vm55H/n/NwZR4zBE1ZO6HmX22BILrGtFIxxOPKg8+OIV+vk9u0MJNnzuze+G1M9h8zLgYpzRT8ZJtxItJXc6/1Ps2KXjY1seyk22B9oPYq+ZwGbnqb1FQrz0ZsU3WtG7yjoTaI=
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
# Noodles
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/DamirSvrtan/noodles.svg?branch=master)](https://travis-ci.org/DamirSvrtan/noodles)
|
4
|
+
[![Dependency Status](https://gemnasium.com/DamirSvrtan/noodles.svg)](https://gemnasium.com/DamirSvrtan/noodles)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/DamirSvrtan/noodles.png)](https://codeclimate.com/github/DamirSvrtan/noodles)
|
6
|
+
|
3
7
|
TODO: Write a gem description
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
11
|
+
Start memcached:
|
12
|
+
|
13
|
+
memcached -l localhost
|
14
|
+
|
7
15
|
Add this line to your application's Gemfile:
|
8
16
|
|
9
17
|
gem 'noodles'
|
@@ -22,7 +30,7 @@ TODO: Write usage instructions here
|
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
25
|
-
1. Fork it
|
33
|
+
1. Fork it ( http://github.com/<my-github-username>/noodles/fork )
|
26
34
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
35
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
36
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/bin/noodles
ADDED
data/cli/noodles_cli.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'pry'
|
3
|
+
require 'find'
|
4
|
+
require 'irb'
|
5
|
+
require 'colorize'
|
6
|
+
|
7
|
+
class NoodlesCLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
desc "new app_name", "creates a boilerplate Noodles folder structure"
|
11
|
+
def new(app_name)
|
12
|
+
template_path = Pathname.new File.expand_path('../template', __FILE__)
|
13
|
+
|
14
|
+
all_paths = Find.find(template_path).map {|path| Pathname.new(path)}
|
15
|
+
all_paths = all_paths[1..-1] # remove '.'
|
16
|
+
|
17
|
+
create_dir(app_name)
|
18
|
+
|
19
|
+
all_paths.each do |abs_path|
|
20
|
+
rel_path = abs_path.relative_path_from(template_path).to_s
|
21
|
+
rel_path = File.join app_name, rel_path
|
22
|
+
create_file_or_dir(abs_path, rel_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
bundle_install(app_name)
|
26
|
+
git_init(app_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "start", "start the server"
|
30
|
+
option :port, aliases: :p
|
31
|
+
def start
|
32
|
+
if File.exist?('config.ru')
|
33
|
+
basic_command = "thin -R config.ru start"
|
34
|
+
basic_command << " -p #{options[:port]}" if options[:port]
|
35
|
+
run basic_command, verbose: false
|
36
|
+
else
|
37
|
+
puts "No config.ru file present."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "console", "starts the interactive console"
|
42
|
+
def console
|
43
|
+
init_path = File.expand_path "config/init.rb"
|
44
|
+
if File.exist?(init_path)
|
45
|
+
require init_path
|
46
|
+
Pry.start
|
47
|
+
else
|
48
|
+
puts "No config/init.rb file present."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def create_file_or_dir(abs_path, rel_path)
|
55
|
+
if abs_path.directory?
|
56
|
+
create_dir(rel_path)
|
57
|
+
else
|
58
|
+
create_file(abs_path, rel_path)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_dir(rel_path)
|
63
|
+
FileUtils.mkdir(rel_path)
|
64
|
+
echo(:mkdir, rel_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_file(abs_path, rel_path)
|
68
|
+
File.open(rel_path, 'w') {|file| file.write(File.read(abs_path))}
|
69
|
+
echo(:create, rel_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def echo(action, subject)
|
73
|
+
line = "#{adjust(action).colorize(:green).bold} #{subject}"
|
74
|
+
puts line
|
75
|
+
end
|
76
|
+
|
77
|
+
def adjust(action)
|
78
|
+
action.to_s.rjust(8, " ")
|
79
|
+
end
|
80
|
+
|
81
|
+
def bundle_install(app_name)
|
82
|
+
echo(:run, 'bundle install')
|
83
|
+
run "cd #{app_name} && bundle install", verbose: false
|
84
|
+
end
|
85
|
+
|
86
|
+
def git_init(app_name)
|
87
|
+
unless `which git`.empty?
|
88
|
+
echo(:run, 'git init')
|
89
|
+
run "cd #{app_name} && git init", verbose: false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require './config/application'
|
2
|
+
require './config/router'
|
3
|
+
require 'better_errors'
|
4
|
+
|
5
|
+
use Rack::Session::Cookie, :secret => 'abc123'
|
6
|
+
use BetterErrors::Middleware if Noodles.env.development?
|
7
|
+
use Rack::CommonLogger, $stdout
|
8
|
+
use Rack::ContentType
|
9
|
+
use Rack::MethodOverride
|
10
|
+
use Rack::Static, urls: ["/css", "/images", "/js", "/favicon.ico"], root: "public"
|
11
|
+
|
12
|
+
run Noodles.application
|
File without changes
|
File without changes
|
File without changes
|
data/lib/noodles.rb
CHANGED
@@ -1,5 +1,53 @@
|
|
1
|
-
require "noodles/
|
1
|
+
# require "noodles/dependencies"
|
2
|
+
require 'noodles/version'
|
3
|
+
require 'noodles/utils'
|
4
|
+
require 'noodles/application'
|
5
|
+
require 'noodles/environment'
|
6
|
+
require 'noodles/cache'
|
7
|
+
require 'multi_json'
|
2
8
|
|
3
9
|
module Noodles
|
4
|
-
|
5
|
-
|
10
|
+
class << self
|
11
|
+
def env
|
12
|
+
Environment
|
13
|
+
end
|
14
|
+
|
15
|
+
def application
|
16
|
+
return @@application if defined? @@application
|
17
|
+
@@application = Noodles::Application.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def http_app
|
21
|
+
return @@http_app if defined? @@http_app
|
22
|
+
@@http_app = application.http_app
|
23
|
+
end
|
24
|
+
|
25
|
+
def websocket_app
|
26
|
+
return @@websocket_app if defined? @@websocket_app
|
27
|
+
@@websocket_app = application.websocket_app
|
28
|
+
end
|
29
|
+
|
30
|
+
def secrets
|
31
|
+
rendered_string = Erubis::Eruby.new(File.read(secrets_path)).result
|
32
|
+
secrets_hash = YAML.load(rendered_string)[Noodles.env.to_s]
|
33
|
+
OpenStruct.new(secrets_hash)
|
34
|
+
end
|
35
|
+
|
36
|
+
def secrets_path
|
37
|
+
File.join('config', 'secrets.yml')
|
38
|
+
end
|
39
|
+
|
40
|
+
def cache
|
41
|
+
return @@cache if defined? @@cache
|
42
|
+
namespace = cache_store_name || 'noodle_app'
|
43
|
+
options = { namespace: namespace, compress: true }
|
44
|
+
@@cache = Cache.new('localhost:11211', options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup
|
48
|
+
yield self
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_accessor :cache_store_name
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "noodles/http/application"
|
2
|
+
require "noodles/websocket/application"
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Noodles
|
6
|
+
class Application
|
7
|
+
|
8
|
+
attr_reader :http_app, :websocket_app
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@http_app = Noodles::Http::Application.new
|
12
|
+
@websocket_app = Noodles::Websocket::Application.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if env['HTTP_UPGRADE'] == "websocket"
|
17
|
+
@websocket_app.call(env)
|
18
|
+
else
|
19
|
+
@http_app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Noodles
|
2
|
+
module Environment
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def development?
|
6
|
+
environment.to_s == 'development'
|
7
|
+
end
|
8
|
+
|
9
|
+
def production?
|
10
|
+
environment.to_s == 'production'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test?
|
14
|
+
environment.to_s == 'test'
|
15
|
+
end
|
16
|
+
|
17
|
+
def environment?
|
18
|
+
environment
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
environment
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_sym
|
26
|
+
environment.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
case other
|
31
|
+
when String
|
32
|
+
environment.to_s == other
|
33
|
+
when Symbol
|
34
|
+
environment.to_sym == other
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def environment
|
43
|
+
ENV['RACK_ENV'] || 'development'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "noodles/http/router"
|
2
|
+
require "noodles/http/controller"
|
3
|
+
require "noodles/http/errors/no_router_error"
|
4
|
+
|
5
|
+
module Noodles
|
6
|
+
module Http
|
7
|
+
class Application
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if rack_app = get_rack_app(env)
|
11
|
+
rack_app.call(env)
|
12
|
+
else
|
13
|
+
response_not_found
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def routes(&block)
|
18
|
+
@router ||= Router.new
|
19
|
+
@router.instance_eval(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_rack_app(env)
|
25
|
+
raise NoRouterError.new if @router.nil?
|
26
|
+
@router.find_by_url(env['REQUEST_METHOD'], env['PATH_INFO'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def response_not_found
|
30
|
+
[404, {'Content-Type' => 'text/html'}, ["<h1>404</h1>"]]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'noodles/http/view'
|
2
|
+
require 'tilt/erubis'
|
3
|
+
require 'tilt/haml'
|
4
|
+
require 'slim'
|
5
|
+
|
6
|
+
module Noodles
|
7
|
+
module Http
|
8
|
+
class Controller
|
9
|
+
|
10
|
+
attr_reader :env, :request, :response, :session
|
11
|
+
|
12
|
+
def initialize(env)
|
13
|
+
@env = env
|
14
|
+
@routing_params = {}
|
15
|
+
@request = Rack::Request.new(env)
|
16
|
+
@response = Rack::Response.new([], 200, {'Content-Type' => 'text/html'})
|
17
|
+
@session = @env['rack.session']
|
18
|
+
end
|
19
|
+
|
20
|
+
def text(textual_response)
|
21
|
+
@response['Content-Type'] = 'text/plain'
|
22
|
+
@response.body = [textual_response]
|
23
|
+
end
|
24
|
+
|
25
|
+
def html(template_name)
|
26
|
+
@response.body = [read_file(template_name, :html)]
|
27
|
+
end
|
28
|
+
|
29
|
+
def json(jsonized_response)
|
30
|
+
@response['Content-Type'] = 'application/json'
|
31
|
+
unless jsonized_response.is_a? String
|
32
|
+
jsonized_response = jsonized_response.to_json
|
33
|
+
end
|
34
|
+
@response.body = [jsonized_response]
|
35
|
+
end
|
36
|
+
|
37
|
+
[:erb, :haml, :slim].each do |template_engine|
|
38
|
+
define_method template_engine do |template_name|
|
39
|
+
filename = get_rendering_path(template_name, template_engine)
|
40
|
+
@response.body = [Tilt.new(filename).render(map_instance_variables_to_object)]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def params
|
45
|
+
request.params.merge @routing_params
|
46
|
+
end
|
47
|
+
|
48
|
+
def redirect(redirect_path, status=302)
|
49
|
+
@response.body = []
|
50
|
+
@response['Location'] = redirect_path
|
51
|
+
@response.status = status
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :redirect_to, :redirect
|
55
|
+
|
56
|
+
def self.action(action, routing_params)
|
57
|
+
proc { |e| self.new(e).dispatch(action, routing_params) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def dispatch(action, routing_params)
|
61
|
+
@routing_params = routing_params
|
62
|
+
self.send(action)
|
63
|
+
@response.finish
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.view(view)
|
67
|
+
@@view = view
|
68
|
+
end
|
69
|
+
|
70
|
+
def view_clazz
|
71
|
+
if defined? @@view
|
72
|
+
@@view
|
73
|
+
else
|
74
|
+
View
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def read_file(template_name, template_type)
|
81
|
+
File.read get_rendering_path(template_name, template_type)
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_rendering_path(template_name, template_type)
|
85
|
+
File.join 'app', 'templates', controller_name, "#{template_name}.#{template_type}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def controller_name
|
89
|
+
klass = self.class.to_s.gsub /Controller$/, ""
|
90
|
+
Noodles.to_underscore klass
|
91
|
+
end
|
92
|
+
|
93
|
+
def mapped_instance_variables
|
94
|
+
Hash[self.instance_variables.map {|var| [var, self.instance_variable_get(var)]}]
|
95
|
+
end
|
96
|
+
|
97
|
+
def map_instance_variables_to_object
|
98
|
+
new_object = view_clazz.new
|
99
|
+
mapped_instance_variables.each do |k,v|
|
100
|
+
new_object.instance_variable_set k, v
|
101
|
+
end
|
102
|
+
new_object
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|