socks 0.1.8.beta → 0.1.9.beta

Sign up to get free protection for your applications and to get access to all the features.
data/lib/socks.rb CHANGED
@@ -1,12 +1,15 @@
1
- #Dir.glob(File.dirname(__FILE__) + '/socks/*.rb', &method(:require))
2
1
  require "socks/version"
3
- require "socks/base_controller"
4
- require "socks/templates"
5
- require "socks/content_helpers"
6
-
7
- ## Tasks
8
- #require File.expand_path("../socks/tasks.rb", __FILE__)
9
- #require File.expand_path("../socks/rake_tasks.rb", __FILE__)
2
+ require "socks/config"
3
+ require "socks/router"
10
4
 
11
5
  module Socks
6
+
7
+ def self.config
8
+ @config ||= Configuration.new
9
+ end
10
+
11
+ def self.configure(attr = {}, &block)
12
+ config.configure attr, &block
13
+ end
14
+
12
15
  end
@@ -0,0 +1,32 @@
1
+ # Allows configuration of your main app using
2
+ # Socks.configure do |config|
3
+ # ...
4
+ # end
5
+ #
6
+
7
+ module Socks
8
+ class Config
9
+
10
+ DEFAULT_CONFIG = {
11
+ option1: 'foo',
12
+ option2: 'bar'
13
+ }
14
+
15
+ attr_accessor :option1, :option2
16
+
17
+ def initialize(attr = {}, &block)
18
+ configure(DEFAULT_CONFIG.merge(attr), &block)
19
+ end
20
+
21
+ def configure(attr = {})
22
+ attr.each_pair do |attr, value|
23
+ self.send("#{attr}=", value)
24
+ end
25
+
26
+ yield self if block_given?
27
+
28
+ self
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'socks/router_helpers'
2
+
3
+ module Socks
4
+ class Router
5
+ include Socks::RouterHelpers
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # General helpers for the Socks router
2
+
3
+ module Socks
4
+ module RouterHelpers
5
+ def txt(str)
6
+ return [200, {'Content-type' => 'text/plain'}, ["#{str}"]]
7
+ end
8
+ end
9
+ end
data/lib/socks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Socks
2
- VERSION = "0.1.8.beta"
2
+ VERSION = "0.1.9.beta"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.beta
4
+ version: 0.1.9.beta
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-30 00:00:00.000000000 Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -142,28 +142,15 @@ dependencies:
142
142
  description: An in-development web framework using Rack.
143
143
  email:
144
144
  - beakr@ninjanizr.com
145
- executables:
146
- - socks
145
+ executables: []
147
146
  extensions: []
148
147
  extra_rdoc_files: []
149
148
  files:
150
- - .gitignore
151
- - .travis.yml
152
- - CHANGELOG
153
- - Gemfile
154
- - Guardfile
155
- - LICENSE
156
- - README.md
157
- - Rakefile
158
- - TODO.md
159
- - bin/socks
160
149
  - lib/socks.rb
161
- - lib/socks/base_controller.rb
162
- - lib/socks/content_helpers.rb
163
- - lib/socks/templates.rb
164
150
  - lib/socks/version.rb
165
- - skel/config_ru
166
- - socks.gemspec
151
+ - lib/socks/config.rb
152
+ - lib/socks/router.rb
153
+ - lib/socks/router_helpers.rb
167
154
  homepage: ''
168
155
  licenses: []
169
156
  post_install_message:
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- notifications:
6
- recipients:
7
- - main@seven7.flowdock.com
8
- - beakr@ninjanizr.com
9
- on_success: always
10
- on_failure: always
data/CHANGELOG DELETED
@@ -1,19 +0,0 @@
1
- - 0.1.8.beta
2
- * Setup RSpec as default test framework
3
- * Get simple RSpec tests using Rack operating
4
-
5
- - 0.0.8.beta
6
- * Bug fixes
7
- * Cleanup
8
-
9
- - 0.0.7.beta
10
- * Got server running
11
- * Cleaned up app structure
12
-
13
- - 0.0.5.alpha
14
- * Executable created
15
- * README creation and testing
16
- * Bundler setup for dependency management
17
-
18
- - 0.0.1.alpha
19
- * Initial Creation
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Guardfile DELETED
@@ -1,19 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec', :version => 2, :cli => "--color --format documentation" do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
-
9
- # Rails example
10
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
- # Capybara request specs
17
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
- end
19
-
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Chris Clarke
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,95 +0,0 @@
1
- # Socks
2
- [![Build Status](https://secure.travis-ci.org/Beakr/socks.png)](http://travis-ci.org/Beakr/socks)
3
-
4
- [![Dependency Status](https://gemnasium.com/Beakr/socks.png)](https://gemnasium.com/Beakr/socks)
5
-
6
- Socks is a web framework and Ruby library supported by Rack for making complex or very simple webapps fast.
7
-
8
- ## Why Socks?
9
-
10
- Socks is as simple as [Sinatra](), yet as complex/powerful as [Rails](). The goal is to be able to write a simple app quickly, and still retain enough power to keep complex/powerful apps going.
11
-
12
- ## Installation
13
-
14
- Choose the one that fits your need:
15
-
16
- ```sh
17
- $ gem install socks --pre # General, global install + command-line app
18
- ```
19
-
20
- ```ruby
21
- gem 'socks' # For Gemfiles
22
-
23
- gem.add_dependency "socks" # For your Gemspec
24
- ```
25
- ## Quick Start
26
-
27
- First, create a new Socks app using:
28
-
29
- ```sh
30
- $ socks new myapp
31
- $ cd myapp
32
- ```
33
-
34
- Next, go to `config/router.rb` and paste in the following between the `Router = HttpROuter.new do ... end` statement:
35
-
36
- ```ruby
37
- get('/') { |env| [200, {'Content-type' => 'text/plain'}, ['This is my first Socks app!']] }
38
- ```
39
-
40
- Afterward, use:
41
-
42
- ```sh
43
- $ socks start
44
- ```
45
-
46
- To spin up a web server on `localhost:4000`.
47
-
48
- Take a look, you should see the following text appear in your web browser:
49
-
50
- This is my first Socks app!
51
-
52
- ## Adding tests for Socks apps
53
-
54
- Socks comes with built-in support for RSpec matchers and DSL. It also comes with a built-in `spec_helper.rb` in the `spec/`directory.
55
-
56
- Paste in the following to test the simple Socks app in the quickstart:
57
-
58
- ```ruby
59
- require 'spec_helper'
60
- require File.expand_path("../../config/router.rb", __FILE__)
61
-
62
- describe Myapp::Router do
63
- let(:request) { Rack::MockRequest.new(Myapp::Router) }
64
-
65
- it 'returns something at /' do
66
- request.get('/').should == "This is my first Socks app!"
67
- end
68
-
69
- end
70
- end
71
- ```
72
-
73
- ## Contributing
74
-
75
- 1. Fork it
76
- 2. Create your feature branch `(git checkout -b my-new-feature)`
77
- 3. Commit your changes `(git commit -am 'Added some feature')`
78
- 4. Push to the branch `(git push origin my-new-feature)`
79
- 5. Create new Pull Request
80
-
81
- ## License
82
-
83
- See LICENSE (MIT).
84
-
85
- [More on MIT »](http://www.opensource.org/licenses/MIT)
86
-
87
- ## TODO
88
-
89
- See TODO.md
90
-
91
- ## Thanks
92
-
93
- I'd like to thank [Sickill](https://github.com/sickill) for his amazing Rack web framework tutorial. Without it, it would be a much harder time getting Socks to work!
94
-
95
- ### *Thanks for using Socks!*
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require "rspec/core/rake_task"
4
-
5
- task :default => [ :spec ]
6
- task :test => [ :spec ]
7
-
8
- desc 'Run RSpec tests'
9
- RSpec::Core::RakeTask.new
data/TODO.md DELETED
@@ -1,6 +0,0 @@
1
- TODO
2
- ====
3
-
4
- * Add templates for erb, markdown, possibly HAML, etc.
5
- * Add assets with CSS or SASS support and Javascript and possibly Coffeescript
6
- support
data/bin/socks DELETED
@@ -1,203 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'commander/import'
5
- require 'socks'
6
- require 'fileutils'
7
-
8
- program :version, Socks::VERSION
9
- program :description, 'A Ruby-Rack-based microframework'
10
-
11
- default_command :about
12
-
13
- command :new do |c|
14
- c.syntax = 'socks new [options]'
15
- c.summary = 'Create a new Socks app'
16
- c.description = 'Use Rack and other utilities to make a new Socks app from scratch'
17
- c.action do |args, opt|
18
-
19
- # Pull out the first arg in args[]
20
- app = args[0]
21
-
22
- # -------------------------------------------------------------------------
23
- # File Contents |
24
- # -------------------------------------------------------------------------
25
-
26
- config_ru = "# config.ru is used for running rack-based applications. Please do not edit this file without proper understanding of Rack
27
- # or some bad things may happen.
28
-
29
-
30
- # Bundler setup
31
- require \"bundler/setup\"
32
- Bundler.setup
33
-
34
- # http_router
35
- require File.expand_path(\"../config/router.rb\", __FILE__)
36
-
37
- # Controllers
38
- Dir[\"../app/controllers\" + \"*.rb\"].each do |file|
39
- require file
40
- end
41
-
42
- # Used so Rack can automatically get updated to file contents without
43
- # a ten second cooldown
44
- use Rack::Reloader, 0
45
-
46
- # Used to run your router (app!)
47
- # Go to config/router.rb to declare routes
48
- run #{app.capitalize}::Router"
49
-
50
- gemfile = "# List dependencies for your app in your Gemfile, then run the `bundle` command
51
-
52
- source \"http://rubygems.org\"
53
-
54
- # Socks itself!
55
- gem \"socks\", \"~> #{Socks::VERSION}\"
56
-
57
- # Rack HTTP
58
- gem \"rack\"
59
-
60
- # Startup your server with thin
61
- gem \"thin\"
62
-
63
- # Or use Foreman
64
- gem \"foreman\"
65
-
66
- # Use HttpRouter for routes (required)
67
- gem \"http_router\"
68
-
69
- # Use Warden for authentication
70
- # gem \"warden\"
71
-
72
- group :development, :test do
73
- # Use RSpec for tests
74
- gem \"rspec\"
75
- end"
76
-
77
- rakefile = "# Socks generates many helpful Rake tasks for you!
78
- require \"socks\"
79
- Socks::Tasks.install"
80
-
81
- gitignore = ".DS_Store"
82
-
83
- procfile = "web: bundle exec rackup config.ru -p 4000"
84
-
85
- app_template = "require \"socks\""
86
-
87
- router_template = "# Declare the paths to your routes here.
88
- require \"http_router\"
89
- module #{app.capitalize}
90
- Router = HttpRouter.new do
91
- # See what you can do at https://github.com/joshbuddy/http_router
92
- end
93
- end
94
- "
95
-
96
- ########################
97
- # Spec-helper template #
98
- ########################
99
-
100
- spec_helper = "# Default helpers for your specs are added here
101
- require \"rspec\"
102
- require \"rack\"
103
- "
104
-
105
- dotrspec = "--color
106
- --format documentation"
107
-
108
-
109
- # -------------------------------------------------------------------------
110
- # Creation |
111
- # -------------------------------------------------------------------------
112
-
113
- FileUtils.mkdir app
114
- FileUtils.cd app
115
- FileUtils.mkdir %w( app config spec )
116
- FileUtils.mkdir %w( app/controllers app/views ) # Sub-dirs
117
- FileUtils.touch %w( spec/spec_helper.rb .rspec ) # Spec file(s)
118
-
119
- # -------------------------------------------------------------------------
120
- # File Initialization |
121
- # -------------------------------------------------------------------------
122
-
123
-
124
- system("echo '#{config_ru}' >> config.ru")
125
- system("echo '#{gemfile}' >> Gemfile")
126
- system("echo '#{rakefile}' >> Rakefile")
127
-
128
- system("echo '#{gitignore}' >> .gitignore")
129
- system("echo '#{procfile}' >> Procfile")
130
-
131
- system("echo '#{app_template}' >> #{app}.rb")
132
-
133
- system("echo '#{router_template}' >> config/router.rb")
134
-
135
- system("echo '#{spec_helper}' >> spec/spec_helper.rb")
136
- system("echo '#{dotrspec}' >> .rspec")
137
-
138
- system("bundle")
139
-
140
- end
141
- end
142
-
143
- command :controller do |c|
144
- c.syntax = 'socks controller [options]'
145
- c.description = 'Create a template for something'
146
- c.action do |args, options|
147
- cont = args[0]
148
-
149
- cont_template = "# Specify pages in the controller
150
-
151
- # e.g.
152
- #
153
- # def index
154
- # \"This is a socks app!\"
155
- # end
156
- #
157
-
158
- class #{cont.capitalize}Controller < Socks::BaseController
159
- # ...
160
- end
161
- "
162
-
163
- FileUtils.touch "app/controllers/#{cont}_controller.rb"
164
- system("echo '#{cont_template}' >> app/controllers/#{cont}_controller.rb")
165
-
166
- end
167
- end
168
-
169
- command :start do |c|
170
- c.syntax = 'socks start [options]'
171
- c.description = 'Startup a Rack server'
172
- c.action do |args, options|
173
- system('foreman start') # Startup server including code in lib/ that runs on port 4000
174
- notify "Socks server is up"
175
- end
176
- end
177
-
178
- command :test do |c|
179
- c.syntax = 'socks test [options]'
180
- c.description = 'Run tests with RSpec'
181
- c.action do |args, options|
182
- system('rspec .')
183
- end
184
- end
185
-
186
- command :version do |c|
187
- c.syntax = 'socks version [options]'
188
- c.description = 'Display the current version (altertative to --version)'
189
- c.action do |args, options|
190
- Socks::VERSION
191
- end
192
- end
193
-
194
- command :about do |c|
195
- c.syntax = 'socks about [options]'
196
- c.action do |args, options|
197
- system("echo \"\e[32m Usage: socks new APP_NAME\"")
198
- end
199
- end
200
-
201
- # -------------------------------------------------------------------------
202
- # Helpers |
203
- # -------------------------------------------------------------------------
@@ -1,20 +0,0 @@
1
- require 'rack'
2
-
3
- module Socks
4
- class BaseController
5
- def call(env)
6
- @request = Rack::Request.new(env)
7
- @response = Rack::Response.new
8
- resp_text = self.send(env['x-rack.action-name'])
9
- @response.write(resp_text)
10
- @respone.finish
11
- end
12
-
13
- def self.action(name)
14
- lambda do |env|
15
- env['x-rack.action-name'] = name
16
- self.new.call(env)
17
- end
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- # Content helpers are used for small responses with Rack (usually in router.rb) for rendering pure text, or HTML.
2
-
3
- module Socks
4
- class ContentHelpers
5
-
6
- # A pure text formatting
7
- def txt(str)
8
- [200, {'Content-type' => 'text/plain'}, ["#{str}"]]
9
- end
10
-
11
- def html(str)
12
- [200, {'Content-type' => 'text/html'}, ["#{str}"]]
13
- end
14
-
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- require 'erb'
2
-
3
- module Socks
4
- class Templates
5
- def erb(temp)
6
- path = File.expand_path("../../views/#{temp}.erb", __FILE__)
7
- ERB.new(temp).result(binding)
8
- end
9
- end
10
- end
data/skel/config_ru DELETED
@@ -1,17 +0,0 @@
1
- # config.ru is used for running rack-based applications. Please do not edit this file without proper understanding of Rack
2
- # or some bad things may happen.
3
-
4
- require \"#{app}\"
5
-
6
- # Bundler setup
7
- require 'bundler'
8
- Bundler.setup
9
- Bundler.require
10
-
11
- # Used so Rack can automatically get updated to file contents without
12
- # a ten second cooldown
13
- use Rack::Reloader, 0
14
-
15
- # Used for automatically getting stylesheet and javascript data into
16
- # your markup templates, as well as running the app.
17
- run Rack::Cascade.new([Rack::File.new('assets'), #{app.capitalize}])
data/socks.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/socks/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Chris Clarke"]
6
- gem.email = ["beakr@ninjanizr.com"]
7
- gem.description = %q{An in-development web framework using Rack.}
8
- gem.summary = %q{A WIP web microframework for Ruby using Rack.}
9
- gem.homepage = ""
10
-
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "socks"
15
- gem.require_paths = ["lib"]
16
- gem.version = Socks::VERSION
17
-
18
- gem.add_dependency "rack" # Rack HTTP
19
- gem.add_dependency "http_router"
20
- gem.add_dependency "commander" # For command-line app
21
- gem.add_dependency "rspec" # Default testing framework
22
-
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "guard"
25
- gem.add_development_dependency "bundler"
26
- gem.add_development_dependency "debugger"
27
- end