work-bench 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/work_bench/application.rb +1 -1
- data/lib/work_bench/dynamic_handler.rb +44 -0
- data/lib/work_bench/version.rb +1 -1
- data/lib/work_bench.rb +1 -1
- data/spec/dynamic_handler_spec.rb +47 -0
- data/spec/fixtures/project/Gemfile +3 -0
- data/spec/fixtures/project/haml/data.js1 +1 -0
- data/spec/fixtures/project/haml/index.haml +10 -0
- data/spec/fixtures/project/haml/index.html +1 -0
- data/spec/fixtures/project/public/css/style.css +68 -0
- data/spec/fixtures/project/public/js/jquery.js +9300 -0
- data/spec/fixtures/project/public/js/scripts.js +0 -0
- data/spec/fixtures/project/sass/_normalize.scss +2 -0
- data/spec/fixtures/project/sass/style.sass +2 -0
- metadata +46 -26
- data/lib/work_bench/server.rb +0 -30
@@ -35,7 +35,7 @@ module Workbench
|
|
35
35
|
use Sass::Plugin::Rack
|
36
36
|
use Rack::StaticCache, :urls => [ '/css', '/js', '/img', '/favicon.ico' ], :root => './public', :versioning => false
|
37
37
|
|
38
|
-
run Workbench::
|
38
|
+
run Workbench::DynamicHandler.new path
|
39
39
|
}.to_app
|
40
40
|
end
|
41
41
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Workbench
|
3
|
+
|
4
|
+
# Класс для обработки запросов к нестатическим файлам
|
5
|
+
class DynamicHandler
|
6
|
+
|
7
|
+
# @param [String] path текущий каталог
|
8
|
+
def initialize path
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
# Вызывается на каждый нестатический запрос
|
13
|
+
def call(env)
|
14
|
+
req = Rack::Request.new(env)
|
15
|
+
filename = File.join(@path, 'haml', resolve_file(req.path))
|
16
|
+
file_ext = File.extname(filename)
|
17
|
+
if File.exists?(filename) && '.haml' != file_ext
|
18
|
+
Rack::File.new(File.join(@path, 'haml')).call(env)
|
19
|
+
else
|
20
|
+
if File.exists? filename
|
21
|
+
[ 200, {'Content-Type' => 'text/html'}, [Workbench::HamlRenderer.render(filename)] ]
|
22
|
+
else
|
23
|
+
[ 404, {'Content-Type' => 'text/html'}, ['File not found: '+req.path] ]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Переопределяет запрос
|
31
|
+
#
|
32
|
+
# @param [String] filename файл,который нужно переопределить
|
33
|
+
def resolve_file filename
|
34
|
+
filename = '/' == filename ? '/index.haml' : filename
|
35
|
+
file_ext = File.extname(filename)
|
36
|
+
if ['.html', '.htm', ''].include? file_ext
|
37
|
+
filename = File.join(File.dirname(filename), File.basename(filename, file_ext) + '.haml')
|
38
|
+
end unless File.exists? File.join(@path, 'haml', filename)
|
39
|
+
filename
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/work_bench/version.rb
CHANGED
data/lib/work_bench.rb
CHANGED
@@ -3,7 +3,7 @@ require 'work_bench/dependencies'
|
|
3
3
|
require 'work_bench/js_libs'
|
4
4
|
require 'work_bench/application'
|
5
5
|
require 'work_bench/cli'
|
6
|
-
require 'work_bench/
|
6
|
+
require 'work_bench/dynamic_handler'
|
7
7
|
require 'work_bench/haml_renderer'
|
8
8
|
require 'work_bench/haml_helpers'
|
9
9
|
require 'work_bench/exporter'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Workbench::DynamicHandler do
|
5
|
+
|
6
|
+
before do
|
7
|
+
root = File.dirname(__FILE__) + '/fixtures/project'
|
8
|
+
@server = Workbench::DynamicHandler.new root
|
9
|
+
end
|
10
|
+
|
11
|
+
it '/data.js => /data.js if exists' do
|
12
|
+
@server.instance_eval {
|
13
|
+
resolve_file('/data.js').should == '/data.js'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it '/index.html => /index.html if exists' do
|
18
|
+
@server.instance_eval {
|
19
|
+
resolve_file('/index.html').should == '/index.html'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it '/ => /index.haml' do
|
24
|
+
@server.instance_eval {
|
25
|
+
resolve_file('/').should == '/index.haml'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it '/index => /index.haml' do
|
30
|
+
@server.instance_eval {
|
31
|
+
resolve_file('/index').should == '/index.haml'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it '/test.html => /test.haml if file not exists' do
|
36
|
+
@server.instance_eval {
|
37
|
+
resolve_file('/test.html').should == '/test.haml'
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
it '/index.htm => /index.haml' do
|
42
|
+
@server.instance_eval {
|
43
|
+
resolve_file('/index.htm').should == '/index.haml'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
!!! Strict
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
5
|
+
%title Example project
|
6
|
+
%script{:src => "/js/jquery.js", :type => "text/javascript"}
|
7
|
+
%script{:src => "/js/scripts.js", :type => "text/javascript"}
|
8
|
+
%link{:href => "/css/style.css", :media => "all", :rel => "stylesheet", :type => "text/css"}
|
9
|
+
%body
|
10
|
+
%h1 Hi there!
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello!
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/* normalize.css 2011-07-06T20:20 UTC //github.com/jonathantneal/normalize.css */
|
2
|
+
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section { display: block; }
|
3
|
+
|
4
|
+
html { cursor: default; font-size: 100%; overflow-y: scroll; -webkit-tap-highlight-color: transparent; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }
|
5
|
+
|
6
|
+
body, form, input, button, select, textarea { font-size: 100%; margin: 0; }
|
7
|
+
|
8
|
+
a, a:active, a:hover { outline: none; }
|
9
|
+
|
10
|
+
a:focus { outline: thin dotted; }
|
11
|
+
|
12
|
+
abbr { _border-bottom: expression(this.title ? '1px dotted':'none'); }
|
13
|
+
|
14
|
+
abbr[title] { border-bottom: 1px dotted; }
|
15
|
+
|
16
|
+
b, strong { font-weight: bold; }
|
17
|
+
|
18
|
+
dfn { font-style: italic; }
|
19
|
+
|
20
|
+
mark { background: #FF0; color: #000; }
|
21
|
+
|
22
|
+
pre, code, kbd, samp { font-family: monospace,monospace; _font-family: 'courier new',monospace; font-size: 1em; }
|
23
|
+
|
24
|
+
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
|
25
|
+
|
26
|
+
q { quotes: none; }
|
27
|
+
|
28
|
+
q:before, q:after { content: ''; content: none; }
|
29
|
+
|
30
|
+
small, sub, sup { font-size: 75%; }
|
31
|
+
|
32
|
+
sub, sup { line-height: 0; position: relative; vertical-align: baseline; }
|
33
|
+
|
34
|
+
sup { top: -0.5em; }
|
35
|
+
|
36
|
+
sub { bottom: -0.25em; }
|
37
|
+
|
38
|
+
nav ul { list-style: none; }
|
39
|
+
|
40
|
+
audio[controls], canvas, video { display: inline-block; *display: inline; }
|
41
|
+
|
42
|
+
audio { display: none; _display: expression(this.controls ? 'inline':'none'); *zoom: 1; }
|
43
|
+
|
44
|
+
audio[controls] { display: inline-block; }
|
45
|
+
|
46
|
+
img { border: 0; -ms-interpolation-mode: bicubic; }
|
47
|
+
|
48
|
+
svg:not(:root) { overflow: hidden; }
|
49
|
+
|
50
|
+
legend { *margin-left: -7px; }
|
51
|
+
|
52
|
+
button, input, select, textarea { -webkit-appearance: none; border-radius: 0; vertical-align: baseline; *vertical-align: middle; }
|
53
|
+
|
54
|
+
button, input { line-height: normal; _overflow: expression(this.type == 'button|reset|submit' ? 'visible':''); }
|
55
|
+
|
56
|
+
button, input[type="button"], input[type="reset"], input[type="submit"] { overflow: visible; }
|
57
|
+
|
58
|
+
input[type="checkbox"], input[type="radio"] { box-sizing: border-box; }
|
59
|
+
|
60
|
+
input[type="search"] { -moz-box-sizing: content-box; -webkit-box-sizing: content-box; box-sizing: content-box; }
|
61
|
+
|
62
|
+
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
|
63
|
+
|
64
|
+
button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; }
|
65
|
+
|
66
|
+
textarea { overflow: auto; vertical-align: top; }
|
67
|
+
|
68
|
+
table { border-collapse: collapse; border-spacing: 0; }
|