orange 0.1.10 → 0.2.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.
@@ -20,7 +20,7 @@ module Orange::Middleware
20
20
  path = packet['route.path'] || packet.request.path_info
21
21
  if @options[:migration_url] && @options[:migration_url] == path
22
22
  orange.migrate_db!
23
- after = packet.session['flash.redirect_to'] ? packet.session['flash.redirect_to'] : '/'
23
+ after = packet.flash('redirect_to') || '/'
24
24
  packet.reroute(after)
25
25
  end
26
26
  pass packet
@@ -87,9 +87,23 @@ module Orange
87
87
  # Access to the rack session
88
88
  # @return [Hash] the session information made available by Rack
89
89
  def session
90
+ env['rack.session']["flash"] ||= {}
90
91
  env['rack.session']
91
92
  end
92
93
 
94
+ # Access to the rack session flash
95
+ # @return [String] the string stored in the flash
96
+ def flash(key = nil, val = nil)
97
+ env['rack.session']["flash"] ||= {}
98
+ if key.nil? && val.nil?
99
+ env['rack.session']["flash"]
100
+ elsif val.nil?
101
+ env['rack.session']["flash"].delete(key)
102
+ else
103
+ env['rack.session']["flash"][key] = val
104
+ end
105
+ end
106
+
93
107
  # Generate headers for finalization
94
108
  # @return [Hash] the header information stored in the orange.env, combined with the defaults
95
109
  # set as DEFAULT_HEADERS
@@ -20,8 +20,11 @@ module Orange
20
20
  out = YAML::load(string)
21
21
  end
22
22
 
23
- def haml(file, packet, *vars, &block)
23
+ def haml(file, packet_binding, *vars, &block)
24
24
  opts = vars.extract_options!
25
+ if packet_binding.is_a? Orange::Packet
26
+ context = packet_binding['route.context'].to_s
27
+ end
25
28
  temp = opts.delete(:template)
26
29
  opts[:resource_name] = opts[:resource].orange_name.to_s if
27
30
  opts[:resource] && opts[:resource].respond_to?(:orange_name)
@@ -33,23 +36,36 @@ module Orange
33
36
  string ||= read_if_exists('templates', file)
34
37
  @template_dirs.each do |templates_dir|
35
38
  string ||= read_if_exists(templates_dir, file)
36
- end
39
+ end unless string
37
40
  end
41
+
42
+ if context
43
+ #Check for context specific overrides
44
+ string ||= read_if_exists('views', resource, context+"."+file) if resource
45
+ string ||= read_if_exists('views', context+"."+file)
46
+ @view_dirs.each do |views_dir|
47
+ string ||= read_if_exists(views_dir, resource, context+"."+file) if resource
48
+ string ||= read_if_exists(views_dir, context+"."+file)
49
+ end unless string
50
+ end
51
+
52
+ # Check for standard views
38
53
  string ||= read_if_exists('views', resource, file) if resource
39
54
  string ||= read_if_exists('views', file)
40
55
  @view_dirs.each do |views_dir|
41
56
  string ||= read_if_exists(views_dir, resource, file) if resource
42
57
  string ||= read_if_exists(views_dir, file)
43
- end
58
+ end unless string
59
+
60
+ # Check for default resource views
44
61
  string ||= read_if_exists('views', 'default_resource', file)
45
62
  @view_dirs.each do |views_dir|
46
63
  string ||= read_if_exists(views_dir, 'default_resource', file) if resource
47
- string ||= read_if_exists(views_dir, file)
48
- end
64
+ end unless string
49
65
  raise LoadError, "Couldn't find haml file '#{file}'" unless string
50
66
 
51
67
  haml_engine = Haml::Engine.new(string)
52
- out = haml_engine.render(packet, opts, &block)
68
+ out = haml_engine.render(packet_binding, opts, &block)
53
69
  end
54
70
 
55
71
  def read_if_exists(*args)
@@ -38,7 +38,7 @@ module Orange::Middleware
38
38
  return ret unless ret.blank? # unless handle_openid returns false, exit immediately
39
39
  end
40
40
  unless access_allowed?(packet)
41
- packet.session['user.after_login'] = packet.request.path
41
+ packet.flash['user.after_login'] = packet.request.path
42
42
  packet.reroute(@login)
43
43
  end
44
44
 
@@ -75,8 +75,7 @@ module Orange::Middleware
75
75
  if packet.request.path.gsub(/\/$/, '') == @logout
76
76
  packet.session['user.id'] = nil
77
77
  packet['user.id'] = nil
78
- after = packet.session['user.after_login'].blank? ?
79
- '/' : packet.session['user.after_login']
78
+ after = packet.flash('user.after_login') || '/'
80
79
  packet.reroute(after)
81
80
  return false
82
81
  end
@@ -112,9 +111,7 @@ module Orange::Middleware
112
111
  end
113
112
 
114
113
 
115
- after = packet.session.has_key?('user.after_login') ?
116
- packet.session['user.after_login'] : '/'
117
- packet.session['user.after_login'] = false
114
+ after = packet.flash('user.after_login') || '/'
118
115
 
119
116
  # Save id into session if we have one.
120
117
  packet.session['user.id'] = packet['user.id']
@@ -123,7 +120,7 @@ module Orange::Middleware
123
120
  packet.reroute(after)
124
121
  false
125
122
  else
126
- packet.session['flash.error'] = resp.status
123
+ packet.flash['error'] = resp.status
127
124
  packet.reroute(@login)
128
125
  false
129
126
  end
@@ -131,8 +128,10 @@ module Orange::Middleware
131
128
  else
132
129
  packet[:status] = 401
133
130
  packet[:headers] = {}
131
+ id = packet.request.params["openid_identifier"]
132
+ id = "http://#{id}" unless id =~ /^https?:\/\//
134
133
  packet.add_header('WWW-Authenticate', Rack::OpenID.build_header(
135
- :identifier => packet.request.params["openid_identifier"],
134
+ :identifier => id,
136
135
  :required => [:email, "http://axschema.org/contact/email"]
137
136
  )
138
137
  )
@@ -29,7 +29,7 @@ module Orange
29
29
  sites = params.delete 'sites'
30
30
  obj.update(params)
31
31
  obj.orange_sites.destroy
32
- sites.each{|k,v| s = OrangeSite.first(:id => k); m.orange_sites << s if s} if sites
32
+ sites.each{|k,v| s = OrangeSite.first(:id => k); obj.orange_sites << s if s} if sites
33
33
  obj.save
34
34
  end
35
35
 
@@ -5,8 +5,8 @@
5
5
  %h2 Wait a minute...
6
6
  %p You'll need to log in before you can continue. Use your OpenID.
7
7
  %p (You can use a Google account to log in. Put https://www.google.com/accounts/o8/id in the box below.)
8
- - if(session['flash.error'])
9
- .error= session['flash.error']
8
+ - if(flash['error'])
9
+ .error= flash('error')
10
10
  %form{:action => '', :method => 'POST'}
11
11
  %input{:type => 'text', :name => 'openid_identifier'}
12
12
  %input{:type => 'submit', :value => 'Log in'}
@@ -9,7 +9,7 @@ module Orange::Middleware
9
9
  # Passes packet then parses the return
10
10
  def packet_call(packet)
11
11
  if orange.options[:development_mode]
12
- packet.session['flash.redirect_to'] = packet.request.path
12
+ packet.flash['redirect_to'] = packet.request.path
13
13
  packet.add_css('debug_bar.css', :module => '_debugger_')
14
14
  end
15
15
  pass packet
@@ -63,7 +63,7 @@ module Orange
63
63
 
64
64
  # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
65
65
  # @param [Orange::Packet] packet the packet being routed
66
- def onSave(packet, params = {})
66
+ def onSave(packet, m, params = {})
67
67
  params[:published] = false
68
68
  m.update(params)
69
69
  m.orange_site = packet['site']
@@ -55,8 +55,32 @@ describe Orange::Packet do
55
55
  end
56
56
 
57
57
  it "should give access to the rack.session env" do
58
- p= Orange::Packet.new(Orange::Core.new, {'rack.session' => 'banana'})
59
- p.session.should == 'banana'
58
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {'foo' => 'banana'}})
59
+ p.session.should have_key 'foo'
60
+ p.session.should have_key 'flash'
61
+ end
62
+
63
+ it "should give always have a flash" do
64
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {}})
65
+ p.session.should have_key 'flash'
66
+ p.flash.should == {}
67
+ end
68
+
69
+ it "should destruct a flash value upon reading" do
70
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {}})
71
+ p.session.should have_key 'flash'
72
+ p.session["flash"]["foo"] = "bar"
73
+ p.flash("foo").should == "bar"
74
+ p.flash("foo").should be_nil
75
+ p.session["flash"].should_not have_key("foo")
76
+ p.flash("foo", "bar")
77
+ p.flash("foo").should == "bar"
78
+ p.flash("foo").should be_nil
79
+ p.session["flash"].should_not have_key("foo")
80
+ p.flash["foo"] = "bar"
81
+ p.flash("foo").should == "bar"
82
+ p.flash("foo").should be_nil
83
+ p.flash.should_not have_key("foo")
60
84
  end
61
85
 
62
86
  it "should give headers by combining :headers with defaults" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 10
9
- version: 0.1.10
7
+ - 2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Haslem
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 -04:00
17
+ date: 2010-05-06 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency