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.
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.banner
15
- "sportweb/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
16
- end
17
-
18
- def self.root
19
- "#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
20
- end
21
-
22
- def self.main
23
- puts 'hello from main'
24
-
25
- require 'sportweb/boot_with_bundler'
26
-
27
- app = Rack::Builder.new {
28
- ### use Rails::Rack::Static
29
-
30
- # Anything urls starting with /tiny will go to Sinatra
31
- ### map "/tiny" do
32
- ## run Sinatra.application
33
- ### end
34
-
35
- ## map '/' do
36
- ## run SportDbAdmin::Engine
37
- ## end
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
- # setup mini-rails
8
- # see https://gist.github.com/josevalim/1942658
9
- # and others
10
-
11
- ### host app - no module - keep it simple
12
- class SportWebHost < Rails::Application
13
-
14
- routes.append do
15
- get '/hello/world' => 'hello#world'
16
-
17
- ## mount About::Server, :at => '/sysinfo'
18
- ## mount DbBrowser::Server, :at => '/browse'
19
-
20
- ###
21
- # mount sinatra app (bundled w/ sportdb-service gem) for json api service
22
- # todo: add JSON API link to layout
23
- ## get '/api' => redirect('/api/v1')
24
- ## mount SportDb::Service::Server, :at => '/api/v1' # NB: make sure to require 'sportdb-service'
25
-
26
- ## mount sinatra app (bundled w/ logutils gem)
27
- ## mount LogDb::Server, :at => '/logs' # NB: make sure to require 'logutils/server'
28
-
29
- mount SportDbAdmin::Engine, :at => '/' # mount a root possible?
30
- end
31
-
32
-
33
- # Configure the default encoding used in templates for Ruby 1.9.
34
- config.encoding = "utf-8"
35
-
36
- # Enable cache classes. Production style.
37
- config.cache_classes = true
38
-
39
- config.eager_load = false ## switch to true - why? why not? - default for dev is false
40
-
41
- # We need a secret token for session, cookies, etc.
42
- config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
43
-
44
-
45
- #################################################
46
- # Enable the asset pipeline !!!!!!!!!!!!!!!!
47
- config.assets.enabled = true
48
- # Version of your assets, change this if you want to expire all your assets
49
- config.assets.version = '1.0'
50
- config.assets.precompile += %w(*.png)
51
-
52
- ### Enables Sprockets compile environment.
53
- ## If disabled, Rails.application.assets will be unavailable
54
- ## to any ActionView helpers.
55
- ## View helpers will depend on assets being precompiled
56
- ## to public/assets in order to link to them.
57
- ## You can still access the environment
58
- ## by directly calling Rails.application.assets
59
- ## config.assets.compile = true
60
- end
61
-
62
-
63
- # This is a barebone controller. One good reference can be found here:
64
- # http://piotrsarnacki.com/2010/12/12/lightweight-controllers-with-rails3/
65
-
66
- class HelloController < ActionController::Metal
67
- include ActionController::Rendering
68
-
69
- def world
70
- render text: 'Hello world!'
71
- end
72
- end
73
-
74
-
75
- ####
76
- # Database Setup & Config
77
- #
78
- # possible w/o config/database.yml ???
79
- #
80
- # see stackoverflow.com/questions/4204724/strategies-for-overriding-database-yml
81
- #
82
- # google for "rails database.yml opt out" ???
83
-
84
-
85
- db_config = {
86
- adapter: 'sqlite3',
87
- database: 'sport.db' # NOTE: change to use your db of choice (e.g. worldcup.db, bundesliga.db, ski.db etc.)
88
- }
89
-
90
- pp db_config
91
- ActiveRecord::Base.establish_connection( db_config )
92
- ## for debugging - disable for production use
93
- ActiveRecord::Base.logger = Logger.new( STDOUT )
94
-
95
- ### make all SportDb models - top level (e.g. SportDb::Model::Team becomes Team)
96
- include SportDb::Models
97
-
98
-
99
- puts '[boot] before App.initialize!'
100
- # Initialize the app (originally in config/environment.rb)
101
- SportWebHost.initialize!
102
- puts '[boot] after App.initialize!'
103
-
104
-
105
-
106
- ####
107
- # check asset pipeline
108
-
109
- puts "Rails.version: #{Rails.version}"
110
- puts "Rails.env: #{Rails.env}"
111
- puts "Rails.root: #{Rails.root}"
112
- puts "Rails.application.class: #{Rails.application.class.name}"
113
- puts "Rails.application.assets.class: #{Rails.application.assets.class.name}"
114
-
115
- pp Rails.application.assets
116
-
117
- puts ">> Rails asset pipeline:"
118
-
119
- if Rails.application.assets.find_asset( "logos/24x24/austria.png" ).present?
120
- puts "asset 'logos/24x24/austria.png' found"
121
- else
122
- puts "asset 'logos/24x24/austria.png' not found"
123
- end
124
-
125
-
126
- # Print the stack for fun!
127
- puts ">> Starting Rails stack:"
128
- Rails.configuration.middleware.each do |middleware|
129
- puts "use #{middleware.inspect}"
130
- end
131
-
132
- ## # Run it (originally in config.ru)
133
- ## run MyApp
134
-
135
-
136
-
137
- puts '[boot] leave sportweb/app.rb'
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'