public
Description: Everything I know about X, I learned from Y. (a simple Camping app)
Homepage: http://learning.kicks-ass.org/
Clone URL: git://github.com/beppu/learning.git
Click here to lend your support to: learning and make a donation at www.pledgie.com !
learning / learning.rb
100644 67 lines (56 sloc) 1.655 kb
1
2
3
4
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
#!/usr/bin/ruby
 
require 'rubygems'
require 'camping'
require 'camping/session'
require 'ostruct'
 
Camping.goes :Learning
 
require 'learning/config'
require 'learning/helpers'
require 'learning/migrations'
 
class L
  def self.method_missing(method, *args)
    "Learning::Models::#{method.to_s}".constantize
  end
end
 
module Learning::RequestWrapper
  def service(*a)
    @css = [ '/static/css/main.css' ]
    @js = [ '/static/js/jquery.js', '/static/js/main.js' ]
    @js_session = { :id => cookies.camping_sid }
    @u = User.find(@state.user_id) if @state.is_logged_in
    @subdomain = @env['HTTP_HOST'].split('.')[0] # not 100% correct
    @title = "Everything I know about X, I learned from Y."
    @google_ad_client = Learning::GOOGLE_AD_CLIENT
    @google_ad_slot = Learning::GOOGLE_AD_SLOT
    @google_analytics = Learning::GOOGLE_ANALYTICS
    response = super(*a)
  end
end
 
module Learning::CookieWrapper
  def service(*a)
    @cgi_cookies = Camping::H.new
    @default_cookie = Camping::H.new.merge({ :path => '/' })
    response = super(*a)
    @cgi_cookies.each do |name, settings|
      c = @default_cookie.merge(settings);
      c.name = name
      cookie = CGI::Cookie.new(c);
      headers['Set-Cookie'].push(cookie.to_s)
    end
    response
  end
end
 
module Learning
  include Camping::Session, Learning::RequestWrapper, Learning::CookieWrapper
 
  def self.create
    Camping::Models::Session.create_schema
    Learning::Models.create_schema
  end
 
  class UserNotFound < RuntimeError
  end
  class WorkspaceNotFound < RuntimeError
  end
end
 
require 'learning/models'
require 'learning/views'
require 'learning/controllers'