oldskool 0.0.2 → 0.0.3
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/oldskool/router.rb +25 -21
- data/lib/oldskool/sinatra_app.rb +5 -3
- data/lib/oldskool/url_handler.rb +1 -3
- data/lib/oldskool/version.rb +1 -1
- data/views/layout.erb +1 -1
- metadata +15 -15
data/lib/oldskool/router.rb
CHANGED
@@ -11,38 +11,42 @@ module Oldskool
|
|
11
11
|
def route(params)
|
12
12
|
defaulting = false
|
13
13
|
|
14
|
+
k = ""
|
15
|
+
q = params[:q].strip
|
16
|
+
|
14
17
|
if params[:q] =~ /^(\w+?)(\s.+)*$/
|
15
18
|
k = $1
|
16
19
|
q = $2.strip rescue ""
|
17
|
-
|
18
|
-
handler = nil
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
default = nil
|
23
|
+
handler = nil
|
22
24
|
|
23
|
-
|
25
|
+
@config[:keywords].each do |keyword|
|
26
|
+
default = keyword if [keyword[:keywords]].flatten.include?(:default)
|
24
27
|
|
25
|
-
|
26
|
-
end
|
28
|
+
handler = keyword if [keyword[:keywords]].flatten.include?(k)
|
27
29
|
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
break if handler
|
31
|
+
end
|
32
|
+
|
33
|
+
if (!handler && default)
|
34
|
+
defaulting = true
|
35
|
+
handler = default
|
36
|
+
elsif !handler
|
37
|
+
return error("No handler for keyword #{k} found and no default handler specified")
|
38
|
+
end
|
34
39
|
|
35
|
-
|
40
|
+
handler_class = "%sHandler" % [handler[:type].to_s.capitalize]
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
Oldskool.const_get(handler_class).new(params, handler, @config).handle_request(k, q)
|
42
|
-
end
|
42
|
+
if Oldskool.constants.include?(handler_class)
|
43
|
+
if defaulting
|
44
|
+
Oldskool.const_get(handler_class).new(params, handler, @config).handle_request("", params[:q])
|
43
45
|
else
|
44
|
-
|
46
|
+
Oldskool.const_get(handler_class).new(params, handler, @config).handle_request(k, q)
|
45
47
|
end
|
48
|
+
else
|
49
|
+
return error("Do not know how to handle type %s keywords" % [ handler[:type] ])
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/oldskool/sinatra_app.rb
CHANGED
@@ -43,9 +43,11 @@ module Oldskool
|
|
43
43
|
if params[:q]
|
44
44
|
@result = @router.route(params)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
if @result
|
47
|
+
@sidemenu = @result.delete(:sidemenu)
|
48
|
+
@topmenu = @result.delete(:topmenu)
|
49
|
+
@error = @result.delete(:error)
|
50
|
+
end
|
49
51
|
|
50
52
|
case (template = @result[:template])
|
51
53
|
when :redirect
|
data/lib/oldskool/url_handler.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Oldskool
|
2
2
|
class UrlHandler
|
3
|
-
include Rack::Utils
|
4
|
-
|
5
3
|
def initialize(params, keyword, config)
|
6
4
|
@params = params
|
7
5
|
@keyword = keyword
|
@@ -10,7 +8,7 @@ module Oldskool
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def handle_request(keyword, query)
|
13
|
-
url = @keyword[:url].gsub(/%Q%/,
|
11
|
+
url = @keyword[:url].gsub(/%Q%/, URI.escape(query))
|
14
12
|
|
15
13
|
{:template => :redirect, :url => url}
|
16
14
|
end
|
data/lib/oldskool/version.rb
CHANGED
data/views/layout.erb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
<% end %>
|
18
18
|
</ul>
|
19
19
|
<% end %>
|
20
|
-
<form action="/do" method="get" class="pull-right"><input name="q" type="text" placeholder="#" /></form>
|
20
|
+
<form action="/do" method="get" class="pull-right"><input name="q" type="text" placeholder="#" value="<%= params[:q] == nil ? "" : h(params[:q]) %>"/></form>
|
21
21
|
</div>
|
22
22
|
</div>
|
23
23
|
</div>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oldskool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- R.I.Pienaar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-19 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -69,27 +69,27 @@ extensions: []
|
|
69
69
|
extra_rdoc_files: []
|
70
70
|
|
71
71
|
files:
|
72
|
-
- lib/oldskool
|
72
|
+
- lib/oldskool.rb
|
73
73
|
- lib/oldskool/error_handler.rb
|
74
|
-
- lib/oldskool/url_handler.rb
|
75
74
|
- lib/oldskool/version.rb
|
76
75
|
- lib/oldskool/sinatra_app.rb
|
77
|
-
- lib/oldskool.rb
|
76
|
+
- lib/oldskool/url_handler.rb
|
77
|
+
- lib/oldskool/router.rb
|
78
|
+
- views/do.erb
|
78
79
|
- views/layout.erb
|
79
80
|
- views/index.erb
|
80
81
|
- views/opensearch_xml.erb
|
81
|
-
-
|
82
|
+
- public/favicon.ico
|
82
83
|
- public/js/less-1.1.3.min.js
|
83
|
-
- public/lib/forms.less
|
84
|
-
- public/lib/scaffolding.less
|
85
|
-
- public/lib/bootstrap.less
|
86
|
-
- public/lib/tables.less
|
87
84
|
- public/lib/patterns.less
|
88
|
-
- public/lib/
|
89
|
-
- public/lib/mixins.less
|
85
|
+
- public/lib/bootstrap.less
|
90
86
|
- public/lib/variables.less
|
87
|
+
- public/lib/mixins.less
|
91
88
|
- public/lib/type.less
|
92
|
-
- public/
|
89
|
+
- public/lib/forms.less
|
90
|
+
- public/lib/tables.less
|
91
|
+
- public/lib/scaffolding.less
|
92
|
+
- public/lib/reset.less
|
93
93
|
- config/oldskool.yaml.dist
|
94
94
|
- config.ru
|
95
95
|
- Gemfile
|