sportweb 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile +97 -92
- data/Gemfile.lock +1 -1
- data/HISTORY.md +3 -3
- data/Manifest.txt +9 -0
- data/README.md +77 -57
- data/Rakefile +44 -44
- data/bin/sportweb +6 -6
- data/lib/sportweb.rb +37 -66
- data/lib/sportweb/app.rb +233 -137
- data/lib/sportweb/boot_with_bundler.rb +130 -128
- data/lib/sportweb/boot_with_require.rb +30 -30
- data/lib/sportweb/version.rb +12 -4
- data/public/404.html +67 -0
- data/public/422.html +67 -0
- data/public/500.html +66 -0
- data/public/favicon.ico +0 -0
- data/public/images/placeholder24x24.png +0 -0
- data/public/images/placeholder32x32.png +0 -0
- data/public/images/placeholder48x48.png +0 -0
- data/public/images/placeholder64x64.png +0 -0
- data/public/robots.txt +1 -0
- metadata +15 -5
data/bin/sportweb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'sportweb'
|
4
|
-
|
5
|
-
SportWeb.main
|
6
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sportweb'
|
4
|
+
|
5
|
+
SportWeb.main
|
6
|
+
|
data/lib/sportweb.rb
CHANGED
@@ -1,66 +1,37 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# test run like:
|
5
|
-
# $ ruby -I ./lib ./lib/sportweb.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'sportweb/version' # let version always go first
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module SportWeb
|
13
|
-
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# Rest with "Dummy" Rails Host App
|
40
|
-
map '/' do
|
41
|
-
run SportWebHost
|
42
|
-
end
|
43
|
-
|
44
|
-
}.to_app
|
45
|
-
|
46
|
-
|
47
|
-
#####
|
48
|
-
# fix/todo:
|
49
|
-
## use differnt port ??
|
50
|
-
##
|
51
|
-
## use --local for host e.g. 127.0.0.1 insteaod of 0.0.0.0 ???
|
52
|
-
|
53
|
-
puts 'before Puma.run app'
|
54
|
-
require 'rack/handler/puma'
|
55
|
-
Rack::Handler::Puma.run app, :Port => 3000, :Host => '0.0.0.0'
|
56
|
-
## Rack::Handler::Thin.run app, :Port => 3000, :Host => '0.0.0.0'
|
57
|
-
puts 'after Puma.run app'
|
58
|
-
|
59
|
-
puts 'bye'
|
60
|
-
end
|
61
|
-
|
62
|
-
end # module SportWeb
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
SportWeb.main if __FILE__ == $0
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# test run like:
|
5
|
+
# $ ruby -I ./lib ./lib/sportweb.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'sportweb/version' # let version always go first
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
module SportWeb
|
13
|
+
|
14
|
+
def self.main
|
15
|
+
puts 'hello from main'
|
16
|
+
|
17
|
+
require 'sportweb/boot_with_bundler'
|
18
|
+
|
19
|
+
#####
|
20
|
+
# fix/todo:
|
21
|
+
## use differnt port ??
|
22
|
+
##
|
23
|
+
## use --local for host e.g. 127.0.0.1 insteaod of 0.0.0.0 ???
|
24
|
+
|
25
|
+
puts 'before Puma.run app'
|
26
|
+
require 'rack/handler/puma'
|
27
|
+
Rack::Handler::Puma.run SportWebHost, :Port => 3000, :Host => '0.0.0.0'
|
28
|
+
puts 'after Puma.run app'
|
29
|
+
|
30
|
+
puts 'bye'
|
31
|
+
end
|
32
|
+
|
33
|
+
end # module SportWeb
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
SportWeb.main if __FILE__ == $0
|
data/lib/sportweb/app.rb
CHANGED
@@ -1,137 +1,233 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
puts '[boot] enter sportweb/app.rb'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
puts
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
puts '[boot] enter sportweb/app.rb'
|
5
|
+
|
6
|
+
|
7
|
+
##
|
8
|
+
# monkey patch image helpers
|
9
|
+
|
10
|
+
module ImageHelperExtension
|
11
|
+
def logo_for_team( team )
|
12
|
+
puts "*** image_helper/logo_for_team #{team.key}"
|
13
|
+
## super # old_logo_for_team( team )
|
14
|
+
''
|
15
|
+
end
|
16
|
+
|
17
|
+
def flag_for_country( country )
|
18
|
+
puts "*** image_helper/flag_for_country #{country.key}"
|
19
|
+
if country.key == 'eng'
|
20
|
+
## quick fix/hack: eng=>en
|
21
|
+
puts "*** use eng quick fix"
|
22
|
+
# image_tag( "flags/24x24/en.png" )
|
23
|
+
''
|
24
|
+
else
|
25
|
+
## super # old_flag_for_country( country )
|
26
|
+
''
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module SportDbAdmin
|
32
|
+
module ImageHelper
|
33
|
+
prepend ImageHelperExtension
|
34
|
+
end # module ImageHelperExtension
|
35
|
+
end # module SportDbAdmin
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
####
|
41
|
+
# setup mini-rails
|
42
|
+
# see https://gist.github.com/josevalim/1942658
|
43
|
+
# and others
|
44
|
+
|
45
|
+
### host app - no module - keep it simple
|
46
|
+
class SportWebHost < Rails::Application
|
47
|
+
|
48
|
+
routes.append do
|
49
|
+
get 'hello/world', to: 'hello#world'
|
50
|
+
|
51
|
+
|
52
|
+
## get 'images/flags/*other', to: 'images#flags'
|
53
|
+
## get 'images/logos/*other', to: 'images#logos'
|
54
|
+
|
55
|
+
## mount About::Server, :at => '/sysinfo'
|
56
|
+
## mount DbBrowser::Server, :at => '/browse'
|
57
|
+
|
58
|
+
###
|
59
|
+
# mount sinatra app (bundled w/ sportdb-service gem) for json api service
|
60
|
+
# todo: add JSON API link to layout
|
61
|
+
## get '/api' => redirect('/api/v1')
|
62
|
+
## mount SportDb::Service::Server, :at => '/api/v1' # NB: make sure to require 'sportdb-service'
|
63
|
+
|
64
|
+
## mount sinatra app (bundled w/ logutils gem)
|
65
|
+
## mount LogDb::Server, :at => '/logs' # NB: make sure to require 'logutils/server'
|
66
|
+
|
67
|
+
mount SportDbAdmin::Engine, :at => '/' # mount a root possible?
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
72
|
+
config.encoding = "utf-8"
|
73
|
+
|
74
|
+
# Enable cache classes. Production style.
|
75
|
+
config.cache_classes = true
|
76
|
+
|
77
|
+
config.eager_load = false ## switch to true - why? why not? - default for dev is false
|
78
|
+
|
79
|
+
##
|
80
|
+
# We need a secret token for session, cookies, etc.
|
81
|
+
# note: change for rails 5 to secret_key_base (from secret_token)
|
82
|
+
config.secret_key_base = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
#################################################
|
87
|
+
# Enable the asset pipeline !!!!!!!!!!!!!!!!
|
88
|
+
config.assets.enabled = true
|
89
|
+
# Version of your assets, change this if you want to expire all your assets
|
90
|
+
config.assets.version = 'v1'
|
91
|
+
## config.assets.precompile += %w(*.png)
|
92
|
+
|
93
|
+
# config.assets.quiet = false ## try for debugging to see asset pipeline requests
|
94
|
+
# config.assets.check_precompiled_asset = true
|
95
|
+
|
96
|
+
## config.assets.unknown_asset_fallback = true ## if not found with asset pipeline; use public as fallback
|
97
|
+
## DEPRECATION WARNING: The asset "flags/24x24/eng.png" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
|
98
|
+
## This behavior is deprecated and will be removed.
|
99
|
+
## To bypass the asset pipeline and preserve this behavior,
|
100
|
+
## use the `skip_pipeline: true` option.
|
101
|
+
|
102
|
+
|
103
|
+
### Enables Sprockets compile environment.
|
104
|
+
## If disabled, Rails.application.assets will be unavailable
|
105
|
+
## to any ActionView helpers.
|
106
|
+
## View helpers will depend on assets being precompiled
|
107
|
+
## to public/assets in order to link to them.
|
108
|
+
## You can still access the environment
|
109
|
+
## by directly calling Rails.application.assets
|
110
|
+
## config.assets.compile = true
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# This is a barebone controller. One good reference can be found here:
|
115
|
+
# http://piotrsarnacki.com/2010/12/12/lightweight-controllers-with-rails3/
|
116
|
+
|
117
|
+
## class HelloController < ActionController::Metal
|
118
|
+
## include ActionController::Rendering
|
119
|
+
class HelloController < ActionController::Base
|
120
|
+
def world
|
121
|
+
render inline: 'Hello world!'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
class ImagesController < ActionController::Base
|
129
|
+
def flags
|
130
|
+
puts "flags params:"
|
131
|
+
pp params
|
132
|
+
|
133
|
+
render inline: 'Not found', :status => 404
|
134
|
+
end
|
135
|
+
|
136
|
+
def logos
|
137
|
+
puts "logos params:"
|
138
|
+
pp params
|
139
|
+
|
140
|
+
render inline: 'Not found', :status => 404
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
####
|
147
|
+
# Database Setup & Config
|
148
|
+
#
|
149
|
+
# possible w/o config/database.yml ???
|
150
|
+
#
|
151
|
+
# see stackoverflow.com/questions/4204724/strategies-for-overriding-database-yml
|
152
|
+
#
|
153
|
+
# google for "rails database.yml opt out" ???
|
154
|
+
|
155
|
+
|
156
|
+
if ARGV[0]
|
157
|
+
DB_PATH = ARGV[0] ## e.g world.db etc.
|
158
|
+
else
|
159
|
+
DB_PATH = 'sport.db'
|
160
|
+
puts "trying to use default / fallback SQLite database >#{DB_PATH}<"
|
161
|
+
end
|
162
|
+
|
163
|
+
unless File.exist?( DB_PATH )
|
164
|
+
puts "*** error - single-file SQLite database >#{DB_PATH}< missing / not found"
|
165
|
+
exit 1
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
db_config = {
|
170
|
+
adapter: 'sqlite3',
|
171
|
+
database: DB_PATH # NOTE: change to use your db of choice (e.g. worldcup.db, bundesliga.db, ski.db etc.)
|
172
|
+
}
|
173
|
+
|
174
|
+
pp db_config
|
175
|
+
ActiveRecord::Base.establish_connection( db_config )
|
176
|
+
## for debugging - disable for production use
|
177
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
178
|
+
|
179
|
+
### make all SportDb models - top level (e.g. SportDb::Model::Team becomes Team)
|
180
|
+
include SportDb::Models
|
181
|
+
|
182
|
+
|
183
|
+
puts '[boot] before App.initialize!'
|
184
|
+
# Initialize the app (originally in config/environment.rb)
|
185
|
+
SportWebHost.initialize!
|
186
|
+
puts '[boot] after App.initialize!'
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
####
|
191
|
+
# check asset pipeline
|
192
|
+
|
193
|
+
puts "Rails.public_path:"
|
194
|
+
pp Rails.public_path
|
195
|
+
|
196
|
+
|
197
|
+
puts "Rails.version: #{Rails.version}"
|
198
|
+
puts "Rails.env: #{Rails.env}"
|
199
|
+
puts "Rails.root: #{Rails.root}"
|
200
|
+
puts "Rails.application.class: #{Rails.application.class.name}"
|
201
|
+
puts "Rails.application.assets.class: #{Rails.application.assets.class.name}"
|
202
|
+
|
203
|
+
pp Rails.application.assets
|
204
|
+
|
205
|
+
puts ">> Rails asset pipeline:"
|
206
|
+
|
207
|
+
if Rails.application.assets.find_asset( "logos/24x24/austria.png" ).present?
|
208
|
+
puts "asset 'logos/24x24/austria.png' found"
|
209
|
+
else
|
210
|
+
puts "!!! - asset 'logos/24x24/austria.png' NOT found"
|
211
|
+
end
|
212
|
+
|
213
|
+
## todo/check: include images/ folder - needed no/yes check - why? why not?
|
214
|
+
if Rails.application.assets.find_asset( "flags/24x24/at.png" ).present?
|
215
|
+
puts "asset 'flags/24x24/at.png' found"
|
216
|
+
else
|
217
|
+
puts "!!! - asset 'flags/24x24/at.png' NOT found"
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
# Print the stack for fun!
|
223
|
+
puts ">> Starting Rails stack:"
|
224
|
+
Rails.configuration.middleware.each do |middleware|
|
225
|
+
puts "use #{middleware.inspect}"
|
226
|
+
end
|
227
|
+
|
228
|
+
## # Run it (originally in config.ru)
|
229
|
+
## run MyApp
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
puts '[boot] leave sportweb/app.rb'
|