vitrine 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +2 -0
  2. data/README.rdoc +36 -14
  3. data/lib/version.rb +1 -1
  4. data/lib/vitrine.rb +29 -14
  5. data/vitrine.gemspec +8 -2
  6. metadata +35 -3
data/Gemfile CHANGED
@@ -6,6 +6,8 @@ source "http://rubygems.org"
6
6
  gem 'sinatra', '~> 1.4', require: 'sinatra/base'
7
7
  gem 'coffee-script', '~> 2.2'
8
8
  gem 'sass', '~> 3'
9
+ gem 'guard'
10
+ gem 'rack-livereload'
9
11
 
10
12
  # Add dependencies to develop your gem here.
11
13
  # Include everything needed to run rake, tests, features, etc.
data/README.rdoc CHANGED
@@ -1,24 +1,46 @@
1
1
  = vitrine
2
2
 
3
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:
4
+ lineman, serve and such.
5
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
6
+ == Core idea of Vitrine
12
7
 
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.
8
+ You want a server that will automatically wrap your CoffeeScript and SASS assets, and allow
9
+ some rudimentary templating. This is practically enough for putting together MVP prototypes,
10
+ especially as far as single-page apps go.
15
11
 
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.
12
+ == How it works.
19
13
 
20
- Vitrine will not do any minification, packaging or baking at this point - it's meant to be like a display case.
21
- If you have a file called 'layout.erb' (or any other extension) it is going to be used as layout, but you can also do without it.
14
+ Vitrine assumes that there are two directories under the current tree:
15
+ * "public" - for the JS, for CSS and SCSS and in general all the static files server straight out
16
+ * "views" - for the templates
17
+
18
+ == Automatic compilation of assets
19
+
20
+ From there on, any .scss file you shove into the "public" directory can be referenced as ".css" -
21
+ Vitrine will automatically compile it via SASS. Same thing applies to CoffeeScript - put .coffee
22
+ files in "public", and reference them as .js files.
23
+
24
+ Both of the above work as passthrough URLs - if you have real JS in there the files will be served
25
+ as static assets. Also, once you compile the site for deployment your links won't go stale.
26
+
27
+ Vitrine will try to show you sensible errors if your SCSS or CoffeeScript fail to compile.
28
+
29
+ == Automatic template pickup
30
+
31
+ If you have "views" available, Vitrine will try to pick up any usable file for any URL without extensions.
32
+ From there on, it's going to try to render it with the automatically picked template engine using the
33
+ standard Sinatra facilities.
34
+
35
+ == Automatic reload via Guard
36
+
37
+ If your project already has a Guardfile, Vitrine will inject live-reloading hooks into your HTML using
38
+ rack-livereload, so you won't need browser extensions at all.
39
+
40
+ == Packaging and baking
41
+
42
+ At this point the best way to bake a Vitrine site is to crawl it externally, but we are going to implement
43
+ baking at some point.
22
44
 
23
45
  == Contributing to vitrine
24
46
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vitrine
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/vitrine.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'sinatra/base'
2
2
  require 'coffee-script'
3
3
  require 'sass'
4
+ require 'pathname'
4
5
 
5
6
  require_relative 'version'
6
7
 
@@ -20,20 +21,23 @@ module Vitrine
20
21
  end
21
22
  end
22
23
 
23
- # Will compile all SCSS and CoffeeScript, and also crawl the template tree and generate
24
- # HTML for all of the files in the template tree. The resulting files will be copied to
25
- # a directory of the build.
26
- # def self.build!
27
-
28
24
  # Run the server, largely stolen from Serve
29
25
  def self.run(options = DEFAULTS)
30
26
  check_dirs_present!
31
27
 
32
28
  app = Rack::Builder.new do
33
- use Rack::CommonLogger
34
29
  use Rack::ShowStatus
35
30
  use Rack::ShowExceptions
36
31
 
32
+ guardfile_path = options[:root] + '/Guardfile'
33
+ if File.exist?(guardfile_path)
34
+ $stderr.puts "Attaching LiveReload via Guardfile at #{guardfile_path.inspect}"
35
+ # Assume livereload is engaged
36
+ use Rack::LiveReload
37
+ else
38
+ $stderr.puts "No Guardfile found, so there won't be any livereload injection"
39
+ end
40
+
37
41
  vitrine = Vitrine::App.new
38
42
  vitrine.settings.set :root, options[:root]
39
43
  run vitrine
@@ -64,6 +68,8 @@ module Vitrine
64
68
  end
65
69
  end
66
70
 
71
+ require 'rack-livereload'
72
+
67
73
  # A little idiosyncrastic asset server.
68
74
  # Does very simple things:
69
75
  # * sensible detector for default pages (they render from Sinatra view templates)
@@ -76,15 +82,21 @@ class Vitrine::App < Sinatra::Base
76
82
  set :root, File.expand_path(File.dirname(__FILE__))
77
83
  set :views, lambda { File.join(settings.root, "views") }
78
84
 
79
- # Use Rack::TryStatic to attempt to load files from public first
80
- # require 'rack/contrib/try_static'
81
- # use Rack::TryStatic,
82
- # :root => (settings.root + '/public'),
83
- # :urls => %w(/), :try => %w(.html index.html /index.html)
85
+
84
86
 
85
87
  # For extensionless things try to pick out the related templates
86
88
  # from the views directory, and render them with a default layout
87
89
  get /^([^\.]+)$/ do | extensionless_path |
90
+ render_template(extensionless_path)
91
+ end
92
+
93
+
94
+ # Allow "fake" form submits
95
+ post /^([^\.]+)$/ do | extensionless_path |
96
+ render_template(extensionless_path)
97
+ end
98
+
99
+ def render_template(extensionless_path)
88
100
  # Find the related view
89
101
  specific_view = extensionless_path + ".*"
90
102
  view_index = extensionless_path + "/index.*"
@@ -109,14 +121,17 @@ class Vitrine::App < Sinatra::Base
109
121
  # If nothing is found just bail
110
122
  unless template_path
111
123
  err = possible_globs.map{|e| e.inspect }.join(', ')
112
- raise "No template found - tried #{er}"
124
+ raise "No template found - tried #{err}"
113
125
  end
114
126
 
115
- $stderr.puts "Rendering via template #{template_path.inspect}"
127
+ relative_path = Pathname.new(template_path).relative_path_from(Pathname.new(settings.views))
128
+
129
+ $stderr.puts "-> #{extensionless_path.inspect} : Rendering via template #{relative_path.to_s.inspect}"
116
130
 
131
+ locals = {}
117
132
  # Auto-pick the template engine out of the extension
118
133
  template_engine = File.extname(template_path).gsub(/^\./, '')
119
- render(template_engine, File.read(template_path), :layout => get_layout)
134
+ render(template_engine, File.read(template_path), :layout => get_layout, :locals => locals)
120
135
  end
121
136
 
122
137
  def get_layout
data/vitrine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "vitrine"
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
12
- s.date = "2013-11-05"
12
+ s.date = "2013-11-08"
13
13
  s.description = " Serves ERB templates with live CoffeeScript and SASS "
14
14
  s.email = "me@julik.nl"
15
15
  s.executables = ["vitrine"]
@@ -43,6 +43,8 @@ Gem::Specification.new do |s|
43
43
  s.add_runtime_dependency(%q<sinatra>, ["~> 1.4"])
44
44
  s.add_runtime_dependency(%q<coffee-script>, ["~> 2.2"])
45
45
  s.add_runtime_dependency(%q<sass>, ["~> 3"])
46
+ s.add_runtime_dependency(%q<guard>, [">= 0"])
47
+ s.add_runtime_dependency(%q<rack-livereload>, [">= 0"])
46
48
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
49
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
48
50
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
@@ -50,6 +52,8 @@ Gem::Specification.new do |s|
50
52
  s.add_dependency(%q<sinatra>, ["~> 1.4"])
51
53
  s.add_dependency(%q<coffee-script>, ["~> 2.2"])
52
54
  s.add_dependency(%q<sass>, ["~> 3"])
55
+ s.add_dependency(%q<guard>, [">= 0"])
56
+ s.add_dependency(%q<rack-livereload>, [">= 0"])
53
57
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
58
  s.add_dependency(%q<bundler>, ["~> 1.0"])
55
59
  s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
@@ -58,6 +62,8 @@ Gem::Specification.new do |s|
58
62
  s.add_dependency(%q<sinatra>, ["~> 1.4"])
59
63
  s.add_dependency(%q<coffee-script>, ["~> 2.2"])
60
64
  s.add_dependency(%q<sass>, ["~> 3"])
65
+ s.add_dependency(%q<guard>, [">= 0"])
66
+ s.add_dependency(%q<rack-livereload>, [">= 0"])
61
67
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
68
  s.add_dependency(%q<bundler>, ["~> 1.0"])
63
69
  s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitrine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
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: 2013-11-05 00:00:00.000000000 Z
12
+ date: 2013-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard
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: rack-livereload
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  - !ruby/object:Gem::Dependency
63
95
  name: rdoc
64
96
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
174
  version: '0'
143
175
  segments:
144
176
  - 0
145
- hash: -735079750998949370
177
+ hash: 3964899950062154621
146
178
  required_rubygems_version: !ruby/object:Gem::Requirement
147
179
  none: false
148
180
  requirements: