webmachine-sprockets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+ gemspec :path => '../sprockets'
5
+
6
+ gem 'rake'
7
+ gem 'awesome_print'
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ webmachine-sprockets
2
+ ====================
3
+
4
+ Webmachine for Ruby: Sprockets integration
5
+
6
+ > Sprockets is a Ruby library for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets, as well as a powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass, SCSS and LESS.
7
+
8
+ [github.com/sstephenson/sprockets](https://github.com/sstephenson/sprockets)
9
+
10
+ > webmachine-ruby is a port of Webmachine, which is written in Erlang. The goal of both projects is to expose interesting parts of the HTTP protocol to your application in a declarative way. This means that you are less concerned with handling requests directly and more with describing the behavior of the resources that make up your application. Webmachine is not a web framework per se, but more of a toolkit for building HTTP-friendly applications. For example, it does not provide a templating engine or a persistence layer; those choices are up to you.
11
+
12
+ [github.com/seancribbs/webmachine-ruby](https://github.com/seancribbs/webmachine-ruby)
13
+
14
+
15
+ Usage
16
+ -----
17
+
18
+ ```ruby
19
+ require 'webmachine'
20
+ require 'webmachine/sprockets'
21
+
22
+ MyApp = Webmachine::Application.new do |app|
23
+ sprockets = Sprockets::Environment.new
24
+ sprockets.append_path 'app/assets/javascripts'
25
+
26
+ resource = Webmachine::Sprockets.resource_for(sprockets)
27
+ app.add_route [ 'assets', '*' ], resource
28
+ end
29
+ ```
30
+
31
+
32
+ Contributing
33
+ ------------
34
+
35
+ 1. Fork at [github.com/lgierth/webmachine-sprockets](https://github.com/lgierth/webmachine-sprockets)
36
+ 2. Create a branch and add your commits
37
+ 4. Open a Pull Request
38
+
39
+ You can also open an issue for discussion first, if you like.
40
+
41
+
42
+ License
43
+ -------
44
+
45
+ webmachine-sprockets is subject to an MIT-style license (see LICENSE file).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.libs << Gem.loaded_specs['sprockets'].gem_dir + '/test'
8
+ end
@@ -0,0 +1,50 @@
1
+ Enumerator = Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
2
+
3
+ module Webmachine
4
+ module Sprockets
5
+ class Resource < ::Webmachine::Resource
6
+ class << self
7
+ attr_accessor :sprockets
8
+ end
9
+
10
+ def initialize
11
+ @rack_response = call_sprockets(rack_env)
12
+ end
13
+
14
+ def finish_request
15
+ response.code = @rack_response[0]
16
+ response.headers.clear
17
+ response.headers.merge!(@rack_response[1])
18
+ response.body = Enumerator.new(@rack_response[2]).to_a.join
19
+ end
20
+
21
+ private
22
+
23
+ def call_sprockets(env)
24
+ self.class.sprockets.call(env)
25
+ end
26
+
27
+ def rack_env
28
+ env = {
29
+ 'PATH_INFO' => '/' + logical_path,
30
+ 'QUERY_STRING' => query_string
31
+ }
32
+ request.headers.each {|key, value| env[cgi_key(key)] = value }
33
+ env
34
+ end
35
+
36
+ def cgi_key(key)
37
+ key = key.upcase.gsub('-', '_')
38
+ key =~ /^Content-(Type|Length)$/ ? key : 'HTTP_' + key
39
+ end
40
+
41
+ def logical_path
42
+ request.path_tokens.join("/")
43
+ end
44
+
45
+ def query_string
46
+ request.uri.query.to_s
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ module Webmachine
2
+ module Sprockets
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'webmachine'
2
+ require 'sprockets'
3
+
4
+ require 'webmachine/sprockets/resource'
5
+ require 'webmachine/sprockets/version'
6
+
7
+ module Webmachine
8
+ module Sprockets
9
+ def self.resource_for(sprockets)
10
+ Resource.dup.tap {|r| r.sprockets = sprockets }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'webmachine'
2
+ require 'webmachine/adapters/rack'
3
+ require 'webmachine/sprockets'
4
+
5
+ require 'test_server'
6
+
7
+ class TestServer
8
+ def webmachine_app(env)
9
+ Webmachine::Application.new do |app|
10
+ assets = Webmachine::Sprockets.resource_for(env)
11
+ app.add_route [ 'assets', '*' ], assets
12
+
13
+ index = Webmachine::Sprockets.resource_for(env.index)
14
+ app.add_route [ 'cached', 'javascripts', '*' ], index
15
+ end
16
+ end
17
+
18
+ def default_app
19
+ Webmachine::Adapters::Rack.new(nil, webmachine_app(@env).dispatcher)
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'webmachine/sprockets/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'webmachine-sprockets'
7
+ s.version = Webmachine::Sprockets::VERSION
8
+ s.date = Date.today.to_s
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Lars Gierth']
11
+ s.email = ['lars.gierth@gmail.com']
12
+ s.homepage = 'https://github.com/lgierth/webmachine-sprockets'
13
+ s.summary = %q{Webmachine for Ruby: Sprockets integration}
14
+ s.description = s.summary
15
+
16
+ s.add_dependency 'webmachine', '~> 1.0'
17
+ s.add_dependency 'sprockets', '~> 2.0'
18
+
19
+ s.add_development_dependency 'rspec'
20
+ s.add_development_dependency 'rack'
21
+
22
+ s.files = `git ls-files`.split("\n") - ['.gitignore', '.travis.yml']
23
+ s.test_files = `git ls-files -- test/*`.split("\n")
24
+ s.require_paths = ['lib']
25
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webmachine-sprockets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lars Gierth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: webmachine
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sprockets
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! 'Webmachine for Ruby: Sprockets integration'
79
+ email:
80
+ - lars.gierth@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - Gemfile
86
+ - README.md
87
+ - Rakefile
88
+ - lib/webmachine/sprockets.rb
89
+ - lib/webmachine/sprockets/resource.rb
90
+ - lib/webmachine/sprockets/version.rb
91
+ - test/test_integration.rb
92
+ - webmachine-sprockets.gemspec
93
+ homepage: https://github.com/lgierth/webmachine-sprockets
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: ! 'Webmachine for Ruby: Sprockets integration'
117
+ test_files:
118
+ - test/test_integration.rb
119
+ has_rdoc: