tiltd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/tiltd +5 -0
- data/examples/angular/index.haml +23 -0
- data/examples/jquery/app.js.coffee +2 -0
- data/examples/jquery/index.haml +19 -0
- data/lib/tiltd/application.rb +19 -0
- data/lib/tiltd/content.rb +29 -0
- data/lib/tiltd/version.rb +3 -0
- data/lib/tiltd.rb +8 -0
- data/spec/application_spec.rb +30 -0
- data/spec/content_spec.rb +55 -0
- data/spec/spec_helper.rb +2 -0
- data/tiltd.gemspec +30 -0
- metadata +204 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Josh Nussbaum
|
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
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Tiltd
|
2
|
+
|
3
|
+
A daemon for [Tilt](http://github.com/rtomayko/tilt)
|
4
|
+
|
5
|
+
Tilt supports many common template languages such as haml, coffee script and sass.
|
6
|
+
|
7
|
+
This gem makes it easy to use these template languages without a lot of setup.
|
8
|
+
|
9
|
+
For example if you want to test haml, just create a `index.haml` and run `tiltd` in the same directory.
|
10
|
+
|
11
|
+
For demos, check out the `examples` folder
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
$ gem install tiltd
|
16
|
+
|
17
|
+
## Example Usage
|
18
|
+
|
19
|
+
$ cd some-dir
|
20
|
+
$ echo '%h1 hello world' > index.haml
|
21
|
+
$ echo -e 'body\n\tcolor: blue' > style.css.sass
|
22
|
+
$ tiltd
|
23
|
+
|
24
|
+
index.haml can be found at http://localhost:8080/
|
25
|
+
style.css.sass is at http://localhost:8080/style.css
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/tiltd
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title Angular Scratchpad
|
5
|
+
%script{src: "//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"}
|
6
|
+
|
7
|
+
:sass
|
8
|
+
body
|
9
|
+
background: #f1f1f1
|
10
|
+
|
11
|
+
:coffeescript
|
12
|
+
app = angular.module('app', [])
|
13
|
+
|
14
|
+
app.controller 'SampleController', ($scope) ->
|
15
|
+
$scope.name = 'World'
|
16
|
+
|
17
|
+
%body{ng: {app: 'app'}}
|
18
|
+
#example{ng: {controller: 'SampleController'}}
|
19
|
+
%p
|
20
|
+
%label Name:
|
21
|
+
%input{ng: {model: 'name'}}
|
22
|
+
|
23
|
+
%p Hello {{name}}!
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title jQuery Example
|
5
|
+
%script{src: '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'}
|
6
|
+
%script{src: '/app.js'}
|
7
|
+
:sass
|
8
|
+
h1
|
9
|
+
color: purple
|
10
|
+
:coffeescript
|
11
|
+
jQuery ->
|
12
|
+
$('body').append('<div>Hello from JS in page<div>')
|
13
|
+
%body
|
14
|
+
%h1 jQuery Example
|
15
|
+
%p
|
16
|
+
run
|
17
|
+
%code
|
18
|
+
tiltd
|
19
|
+
to execute
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tiltd
|
2
|
+
class Application
|
3
|
+
def call(env)
|
4
|
+
request = Rack::Request.new(env)
|
5
|
+
headers = {}
|
6
|
+
|
7
|
+
if content = Content.locate(request.path_info)
|
8
|
+
headers['Content-Type'] = content.mime_type
|
9
|
+
code = 200
|
10
|
+
body = content.body
|
11
|
+
el
|
12
|
+
code = 404
|
13
|
+
body = ''
|
14
|
+
end
|
15
|
+
|
16
|
+
[ code, headers, [body] ]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Tiltd
|
2
|
+
class Content
|
3
|
+
def self.find(relative)
|
4
|
+
relative = relative.gsub(%r{^/}, '')
|
5
|
+
path = Dir.glob(relative + '.*').first
|
6
|
+
path if path && File.file?(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.locate(path)
|
10
|
+
actual = find(path)
|
11
|
+
actual = find(File.join(path, "index")) unless actual
|
12
|
+
|
13
|
+
new(actual) if actual
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(path)
|
17
|
+
@template_class = Tilt[path]
|
18
|
+
@template = @template_class.new(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def mime_type
|
22
|
+
@template_class.default_mime_type
|
23
|
+
end
|
24
|
+
|
25
|
+
def body
|
26
|
+
@template.render
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/tiltd.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tiltd::Application do
|
4
|
+
context "#call" do
|
5
|
+
let(:app) { Tiltd::Application.new }
|
6
|
+
let(:request) { stub(path_info: '/foo/other') }
|
7
|
+
let(:response) { app.call(:env) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Rack::Request.should_receive(:new).with(:env).and_return(request)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "content found" do
|
14
|
+
let(:content) { stub(body: 'content', mime_type: 'text/css') }
|
15
|
+
before { Tiltd::Content.should_receive(:locate).with('/foo/other').and_return(content)}
|
16
|
+
|
17
|
+
specify { response[0].should == 200 }
|
18
|
+
specify { response[1]['Content-Type'].should == 'text/css' }
|
19
|
+
specify { response[2].should == ['content']}
|
20
|
+
end
|
21
|
+
|
22
|
+
context "content not found" do
|
23
|
+
before { Tiltd::Content.should_receive(:locate).with('/foo/other').and_return(nil) }
|
24
|
+
|
25
|
+
specify { response[0].should == 404 }
|
26
|
+
specify { response[1].should == {} }
|
27
|
+
specify { response[2].should == ['']}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tiltd::Content do
|
4
|
+
context "#locate" do
|
5
|
+
subject { Tiltd::Content.locate('/foo/other')}
|
6
|
+
|
7
|
+
context "found" do
|
8
|
+
before do
|
9
|
+
Dir.should_receive(:glob).with('foo/other.*').and_return(['foo/other.haml'])
|
10
|
+
File.should_receive(:file?).with('foo/other.haml').and_return(true)
|
11
|
+
Tiltd::Content.should_receive(:new).with('foo/other.haml').and_return(:content)
|
12
|
+
end
|
13
|
+
|
14
|
+
specify { should == :content}
|
15
|
+
end
|
16
|
+
|
17
|
+
context "not found" do
|
18
|
+
before do
|
19
|
+
Dir.should_receive(:glob).with('foo/other.*').and_return([])
|
20
|
+
end
|
21
|
+
|
22
|
+
context "index exists" do
|
23
|
+
before do
|
24
|
+
Dir.should_receive(:glob).with('foo/other/index.*').and_return(['foo/other/index.haml'])
|
25
|
+
File.should_receive(:file?).with('foo/other/index.haml').and_return(true)
|
26
|
+
Tiltd::Content.should_receive(:new).with('foo/other/index.haml').and_return(:content)
|
27
|
+
end
|
28
|
+
specify { should == :content}
|
29
|
+
end
|
30
|
+
|
31
|
+
context "index missing" do
|
32
|
+
before do
|
33
|
+
Dir.should_receive(:glob).with('foo/other/index.*').and_return([])
|
34
|
+
Tiltd::Content.should_not_receive(:new)
|
35
|
+
end
|
36
|
+
specify { should be_nil}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "located" do
|
42
|
+
let(:template) { stub(:template_class, render: 'example content')}
|
43
|
+
let(:template_class) { mock(:template_class, default_mime_type: 'text/css')}
|
44
|
+
|
45
|
+
before do
|
46
|
+
Tilt.should_receive(:[]).with('foo/other.haml').and_return(template_class)
|
47
|
+
template_class.should_receive(:new).with('foo/other.haml').and_return(template)
|
48
|
+
end
|
49
|
+
|
50
|
+
subject { Tiltd::Content.new('foo/other.haml') }
|
51
|
+
|
52
|
+
its(:mime_type) { should == 'text/css' }
|
53
|
+
its(:body) { should == 'example content' }
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tiltd.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tiltd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tiltd"
|
8
|
+
spec.version = Tiltd::VERSION
|
9
|
+
spec.authors = ["Josh Nussbaum"]
|
10
|
+
spec.email = ["joshnuss@gmail.com"]
|
11
|
+
spec.description = "Serve static files with rack and tilt"
|
12
|
+
spec.summary = "A simple rack server for serving common template extensions"
|
13
|
+
spec.homepage = "http://github.com/joshnuss/tiltd"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'rack'
|
22
|
+
spec.add_dependency 'tilt'
|
23
|
+
spec.add_dependency 'sass'
|
24
|
+
spec.add_dependency 'coffee-script'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "guard-rspec"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiltd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Nussbaum
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: tilt
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sass
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
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: coffee-script
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
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
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Serve static files with rack and tilt
|
143
|
+
email:
|
144
|
+
- joshnuss@gmail.com
|
145
|
+
executables:
|
146
|
+
- tiltd
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- .gitignore
|
151
|
+
- .rspec
|
152
|
+
- .travis.yml
|
153
|
+
- Gemfile
|
154
|
+
- Guardfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/tiltd
|
159
|
+
- examples/angular/index.haml
|
160
|
+
- examples/jquery/app.js.coffee
|
161
|
+
- examples/jquery/index.haml
|
162
|
+
- lib/tiltd.rb
|
163
|
+
- lib/tiltd/application.rb
|
164
|
+
- lib/tiltd/content.rb
|
165
|
+
- lib/tiltd/version.rb
|
166
|
+
- spec/application_spec.rb
|
167
|
+
- spec/content_spec.rb
|
168
|
+
- spec/spec_helper.rb
|
169
|
+
- tiltd.gemspec
|
170
|
+
homepage: http://github.com/joshnuss/tiltd
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
hash: 1036037427
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
188
|
+
requirements:
|
189
|
+
- - ! '>='
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
segments:
|
193
|
+
- 0
|
194
|
+
hash: 1036037427
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 1.8.24
|
198
|
+
signing_key:
|
199
|
+
specification_version: 3
|
200
|
+
summary: A simple rack server for serving common template extensions
|
201
|
+
test_files:
|
202
|
+
- spec/application_spec.rb
|
203
|
+
- spec/content_spec.rb
|
204
|
+
- spec/spec_helper.rb
|