vitrine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +36 -0
- data/Rakefile +38 -0
- data/bin/vitrine +5 -0
- data/lib/version.rb +3 -0
- data/lib/vitrine.rb +142 -0
- data/test/helper.rb +18 -0
- data/test/test_vitrine.rb +7 -0
- metadata +157 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'sinatra', '~> 1.4', require: 'sinatra/base'
|
7
|
+
gem 'coffee-script', '~> 2.2'
|
8
|
+
gem 'sass', '~> 3'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", "~> 1.0"
|
15
|
+
gem "jeweler", "~> 1.8.7"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Julik Tarkhanov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= vitrine
|
2
|
+
|
3
|
+
Is a very small, simple web server one-liner for modern web-apps, a bit in the style of
|
4
|
+
lineman, serve and such. Does three things:
|
5
|
+
|
6
|
+
* Assumes two directories exist in the tree you are using - "views" and "public"
|
7
|
+
* Takes a single line ('vitrine') and starts on the default port (4000)
|
8
|
+
* Converts .coffee to .js on the fly using ExecJS. Link to your .coffee files as if they were .js
|
9
|
+
"script.js" will automatically pick up "script.coffee", compile it and serve it to the browser
|
10
|
+
* Converts .scss to .css on the fly using Sass. Link to your .scss files as if they were .css
|
11
|
+
"styles.css" will automatically pick up "styles.scss", compile it and serve it to the browser
|
12
|
+
|
13
|
+
CoffeeScript and SASS will be served right from your "public" directory, if there are no stylesheets
|
14
|
+
with the same names. Templates from "views" will be used for pages that do not exist in HTML form.
|
15
|
+
|
16
|
+
If you have errors in your CoffeeScript that prevent it from compiling you will get an error in your browser
|
17
|
+
console. If you have CSS errors that prevent the SASS stylesheets from compiling you will get an error message
|
18
|
+
in front of your body element.
|
19
|
+
|
20
|
+
Vitrine will not do any minification, packaging or baking at this point - it's meant to be like a display case.
|
21
|
+
|
22
|
+
== Contributing to vitrine
|
23
|
+
|
24
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
25
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
26
|
+
* Fork the project.
|
27
|
+
* Start a feature/bugfix branch.
|
28
|
+
* Commit and push until you are happy with your contribution.
|
29
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
30
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
31
|
+
|
32
|
+
== Copyright
|
33
|
+
|
34
|
+
Copyright (c) 2013 Julik Tarkhanov. See LICENSE.txt for
|
35
|
+
further details.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require File.dirname(__FILE__) + '/lib/version'
|
15
|
+
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
+
gem.name = "vitrine"
|
20
|
+
gem.version = Vitrine::VERSION
|
21
|
+
gem.homepage = "http://github.com/julik/vitrine"
|
22
|
+
gem.license = "MIT"
|
23
|
+
gem.summary = %Q{ Quickie micro-app preview server }
|
24
|
+
gem.description = %Q{ Serves ERB templates with live CoffeeScript and SASS }
|
25
|
+
gem.email = "me@julik.nl"
|
26
|
+
gem.authors = ["Julik Tarkhanov"]
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
task :default => :test
|
data/bin/vitrine
ADDED
data/lib/version.rb
ADDED
data/lib/vitrine.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
|
4
|
+
require_relative 'version'
|
5
|
+
|
6
|
+
module Vitrine
|
7
|
+
DEFAULTS = { root: Dir.getwd, port: 4000, host: '127.0.0.1' }
|
8
|
+
|
9
|
+
def self.check_dirs_present!
|
10
|
+
views = DEFAULTS[:root] + '/views'
|
11
|
+
unless File.exist?(views) and File.dir?(views)
|
12
|
+
$stderr.puts "WARNING: `views' directory not found under the current tree, you might want to create it"
|
13
|
+
end
|
14
|
+
|
15
|
+
public = DEFAULTS[:root] + '/public'
|
16
|
+
unless File.exist?(views) and File.dir?(views)
|
17
|
+
$stderr.puts "ERROR: `public' directory not found under the current tree, you might want to create it"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Will compile all SCSS and CoffeeScript, and also crawl the template tree and generate
|
23
|
+
# HTML for all of the files in the template tree. The resulting files will be copied to
|
24
|
+
# a directory of the build.
|
25
|
+
# def self.build!
|
26
|
+
|
27
|
+
# Run the server, largely stolen from Serve
|
28
|
+
def self.run(options = DEFAULTS)
|
29
|
+
check_dirs_present!
|
30
|
+
|
31
|
+
app = Rack::Builder.new do
|
32
|
+
use Rack::CommonLogger
|
33
|
+
use Rack::ShowStatus
|
34
|
+
use Rack::ShowExceptions
|
35
|
+
|
36
|
+
vitrine = Vitrine::App.new
|
37
|
+
vitrine.settings.set :root, options[:root]
|
38
|
+
run vitrine
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
# Try Thin
|
43
|
+
thin = Rack::Handler.get('thin')
|
44
|
+
thin.run app, :Port => options[:port], :Host => options[:address] do |server|
|
45
|
+
puts "Thin #{Thin::VERSION::STRING} available at http://#{options[:address]}:#{options[:port]}"
|
46
|
+
end
|
47
|
+
rescue LoadError
|
48
|
+
begin
|
49
|
+
# Then Mongrel
|
50
|
+
mongrel = Rack::Handler.get('mongrel')
|
51
|
+
mongrel.run app, :Port => options[:port], :Host => options[:address] do |server|
|
52
|
+
puts "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at http://#{options[:address]}:#{options[:port]}"
|
53
|
+
end
|
54
|
+
rescue LoadError
|
55
|
+
# Then WEBrick
|
56
|
+
puts "Install Mongrel or Thin for better performance."
|
57
|
+
webrick = Rack::Handler.get('webrick')
|
58
|
+
webrick.run app, :Port => options[:port], :Host => options[:address] do |server|
|
59
|
+
trap("INT") { server.shutdown }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# A little idiosyncrastic asset server.
|
67
|
+
# Does very simple things:
|
68
|
+
# * sensible detector for default pages (they render from Sinatra view templates)
|
69
|
+
# * automatic compilation of CoffeeScript and SASS assets - just request them with .js and .css
|
70
|
+
# and Vitrine will find them and compile them for you on the spot
|
71
|
+
class Vitrine::App < Sinatra::Base
|
72
|
+
set :static, true
|
73
|
+
set :show_exceptions, false
|
74
|
+
set :raise_errors, true
|
75
|
+
set :root, File.expand_path(File.dirname(__FILE__))
|
76
|
+
set :views, lambda { File.join(settings.root, "views") }
|
77
|
+
|
78
|
+
# Use Rack::TryStatic to attempt to load files from public first
|
79
|
+
# require 'rack/contrib/try_static'
|
80
|
+
# use Rack::TryStatic,
|
81
|
+
# :root => (settings.root + '/public'),
|
82
|
+
# :urls => %w(/), :try => %w(.html index.html /index.html)
|
83
|
+
|
84
|
+
# For extensionless things try to pick out the related templates
|
85
|
+
# from the views directory, and render them with a default layout
|
86
|
+
get /^([^\.]+)$/ do | extensionless_path |
|
87
|
+
# Find the related view
|
88
|
+
specific_view = extensionless_path + ".*"
|
89
|
+
view_index = extensionless_path + "/index.*"
|
90
|
+
|
91
|
+
# Glob for all the possibilites
|
92
|
+
possibilites = [specific_view, view_index].map do | pattern |
|
93
|
+
Dir.glob(File.join(settings.views, pattern))
|
94
|
+
end.flatten.reject do | e |
|
95
|
+
e =~ /\.DS_Store/ # except DS_Store
|
96
|
+
end.reject do | e |
|
97
|
+
e =~ /(\.+)$/ # and except directory self-links
|
98
|
+
end
|
99
|
+
|
100
|
+
# Try the first template that has been found
|
101
|
+
template_path = possibilites.shift
|
102
|
+
|
103
|
+
# If nothing is found just bail
|
104
|
+
unless template_path
|
105
|
+
raise "No template for either #{specific_view.inspect} or #{view_index.inspect}"
|
106
|
+
end
|
107
|
+
|
108
|
+
# Auto-pick the template engine out of the extension
|
109
|
+
template_engine = File.extname(template_path).gsub(/^\./, '')
|
110
|
+
render(template_engine, File.read(template_path), :layout => :layout)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Try to find SCSS replacement for missing CSS
|
114
|
+
get /(.+)\.css/ do | basename |
|
115
|
+
begin
|
116
|
+
content_type 'text/css', :charset => 'utf-8'
|
117
|
+
scss_source_path = File.join(settings.root, 'public', "#{basename}.scss")
|
118
|
+
Sass.compile_file(scss_source_path)
|
119
|
+
rescue Errno::ENOENT # Missing SCSS
|
120
|
+
halt 404, "No such CSS or SCSS file found"
|
121
|
+
rescue Exception => e # CSS syntax error or something alike
|
122
|
+
# use smart CSS to inject an error message into the document
|
123
|
+
'body:before { color: red; font-size: 2em; content: %s }' % [e.class,
|
124
|
+
"\n", "--> ", e.message].join.inspect
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Try to find CoffeeScript replacement for missing JS
|
129
|
+
get /(.+)\.js/ do | basename |
|
130
|
+
# If this file is not found resort back to a coffeescript
|
131
|
+
begin
|
132
|
+
coffee_source = File.read(File.join(settings.root, 'public', "#{basename}.coffee"))
|
133
|
+
content_type 'text/javascript', :charset => 'utf-8'
|
134
|
+
CoffeeScript.compile(coffee_source)
|
135
|
+
rescue Errno::ENOENT # Missing CoffeeScript
|
136
|
+
halt 404, "No such JS file and could not find a .coffee replacement"
|
137
|
+
rescue Exception => e # CS syntax error or something alike
|
138
|
+
# inject it into the document
|
139
|
+
'console.error(%s)' % [e.class, "\n", "--> ", e.message].join.inspect
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'vitrine'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vitrine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Julik Tarkhanov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.4'
|
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.4'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: coffee-script
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.2'
|
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.2'
|
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: '3'
|
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: '3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
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: '3.12'
|
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.0'
|
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.0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: jeweler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.7
|
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: 1.8.7
|
110
|
+
description: ! ' Serves ERB templates with live CoffeeScript and SASS '
|
111
|
+
email: me@julik.nl
|
112
|
+
executables:
|
113
|
+
- vitrine
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.rdoc
|
118
|
+
files:
|
119
|
+
- .document
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.rdoc
|
123
|
+
- Rakefile
|
124
|
+
- bin/vitrine
|
125
|
+
- lib/version.rb
|
126
|
+
- lib/vitrine.rb
|
127
|
+
- test/helper.rb
|
128
|
+
- test/test_vitrine.rb
|
129
|
+
homepage: http://github.com/julik/vitrine
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
hash: -4508609861442629778
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.25
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Quickie micro-app preview server
|
157
|
+
test_files: []
|