lux-fw 0.1.35 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +5 -5
  2. data/.version +1 -1
  3. data/bin/cli/am +67 -41
  4. data/bin/cli/assets +1 -1
  5. data/bin/cli/console +3 -2
  6. data/bin/cli/eval +11 -2
  7. data/bin/cli/exceptions +1 -1
  8. data/bin/cli/generate +4 -0
  9. data/bin/cli/render +18 -0
  10. data/bin/cli/routes +3 -1
  11. data/bin/cli/server +4 -1
  12. data/bin/lux +10 -1
  13. data/bin/txt/nginx.conf +35 -18
  14. data/lib/common/class_attributes.rb +10 -10
  15. data/lib/common/{before_and_after.rb → class_callbacks.rb} +12 -21
  16. data/lib/common/crypt.rb +10 -6
  17. data/lib/common/dynamic_class.rb +12 -7
  18. data/lib/common/generic_model.rb +6 -6
  19. data/lib/common/hash_with_indifferent_access.rb +6 -284
  20. data/lib/{lux/helper/lib/html_tag.rb → common/html_tag_builder.rb} +1 -1
  21. data/lib/common/policy.rb +2 -2
  22. data/lib/common/url.rb +6 -4
  23. data/lib/lux-fw.rb +2 -13
  24. data/lib/lux/api/api.rb +34 -47
  25. data/lib/lux/api/lib/dsl.rb +2 -2
  26. data/lib/lux/api/lib/model_api.rb +40 -23
  27. data/lib/lux/api/lib/response.rb +30 -5
  28. data/lib/lux/application/application.rb +182 -0
  29. data/lib/lux/{controller → application}/lib/nav.rb +18 -21
  30. data/lib/lux/application/lib/plugs.rb +10 -0
  31. data/lib/lux/application/lib/render.rb +58 -0
  32. data/lib/lux/application/lib/route_test.rb +64 -0
  33. data/lib/lux/cache/cache.rb +27 -16
  34. data/lib/lux/cell/cell.rb +66 -54
  35. data/lib/lux/config/config.rb +51 -27
  36. data/lib/lux/current/current.rb +122 -0
  37. data/lib/lux/{page → current}/lib/encrypt_params.rb +2 -2
  38. data/lib/lux/{page → current}/lib/static_file.rb +29 -25
  39. data/lib/lux/delayed_job/delayed_job.rb +4 -4
  40. data/lib/lux/error/error.rb +31 -16
  41. data/lib/lux/helper/helper.rb +32 -37
  42. data/lib/lux/helper/helpers/application_helper.rb +3 -0
  43. data/lib/lux/helper/helpers/html_helper.rb +3 -0
  44. data/lib/lux/helper/helpers/mailer_helper.rb +11 -0
  45. data/lib/lux/lux.rb +40 -30
  46. data/lib/lux/mailer/mailer.rb +46 -29
  47. data/lib/lux/{page → response}/lib/flash.rb +1 -1
  48. data/lib/lux/response/lib/header.rb +21 -0
  49. data/lib/lux/response/response.rb +237 -0
  50. data/lib/lux/template/template.rb +20 -18
  51. data/lib/overload/array.rb +5 -0
  52. data/lib/overload/auto_loader.rb +27 -0
  53. data/lib/overload/blank.rb +8 -2
  54. data/lib/overload/float.rb +10 -0
  55. data/lib/overload/hash.rb +5 -12
  56. data/lib/overload/integer.rb +1 -5
  57. data/lib/overload/nil.rb +5 -0
  58. data/lib/overload/object.rb +1 -0
  59. data/lib/overload/r.rb +5 -0
  60. data/lib/overload/string.rb +4 -5
  61. data/lib/overload/{date.rb → time.rb} +23 -3
  62. metadata +37 -73
  63. data/bin/forever +0 -65
  64. data/bin/job_que +0 -39
  65. data/lib/lux/api/lib/application_api.rb +0 -38
  66. data/lib/lux/api/lib/doc_builder.rb +0 -19
  67. data/lib/lux/api/lib/rescue.rb +0 -8
  68. data/lib/lux/controller/controller.rb +0 -185
  69. data/lib/lux/controller/lib/plugs.rb +0 -10
  70. data/lib/lux/html/html.rb +0 -3
  71. data/lib/lux/html/lib/form.rb +0 -81
  72. data/lib/lux/html/lib/input.rb +0 -71
  73. data/lib/lux/html/lib/input_types.rb +0 -287
  74. data/lib/lux/lib/lux.rb +0 -51
  75. data/lib/lux/page/lib/response.rb +0 -178
  76. data/lib/lux/page/page.rb +0 -292
  77. data/lib/lux/rescue_from/rescue_from.rb +0 -63
  78. data/lib/plugins/assets/assets_plug.rb +0 -31
  79. data/lib/plugins/assets/helper_module_adapter.rb +0 -51
  80. data/lib/plugins/assets/init.rb +0 -4
  81. data/lib/plugins/db_helpers/array_and_hstore.rb +0 -64
  82. data/lib/plugins/db_helpers/arrays_and_tags.rb +0 -23
  83. data/lib/plugins/db_helpers/before_save.rb +0 -44
  84. data/lib/plugins/db_helpers/cached_find_by.rb +0 -45
  85. data/lib/plugins/db_helpers/class_and_instance.rb +0 -120
  86. data/lib/plugins/db_helpers/dataset_plugin.rb +0 -101
  87. data/lib/plugins/db_helpers/filter_wrappers.rb +0 -21
  88. data/lib/plugins/db_helpers/link_plugin.rb +0 -95
  89. data/lib/plugins/db_helpers/localize_plugin.rb +0 -57
  90. data/lib/plugins/db_helpers/primary_keys.rb +0 -36
  91. data/lib/plugins/db_helpers/typero_attributes.rb +0 -69
  92. data/lib/plugins/db_logger/init.rb +0 -18
  93. data/lib/plugins/db_logger/lux_response_adapter.rb +0 -9
  94. data/lib/plugins/paginate/helper.rb +0 -32
  95. data/lib/plugins/paginate/sequel_adapter.rb +0 -18
  96. data/lib/vendor/mini_assets/lib/asset.rb +0 -71
  97. data/lib/vendor/mini_assets/lib/asset/css.rb +0 -19
  98. data/lib/vendor/mini_assets/lib/asset/js.rb +0 -17
  99. data/lib/vendor/mini_assets/lib/base.rb +0 -69
  100. data/lib/vendor/mini_assets/lib/base/javascript.rb +0 -13
  101. data/lib/vendor/mini_assets/lib/base/stylesheet.rb +0 -5
  102. data/lib/vendor/mini_assets/lib/manifest.rb +0 -18
  103. data/lib/vendor/mini_assets/lib/opts.rb +0 -16
  104. data/lib/vendor/mini_assets/mini_assets.rb +0 -74
  105. data/lib/vendor/oauth/lib/facebook.rb +0 -35
  106. data/lib/vendor/oauth/lib/github.rb +0 -37
  107. data/lib/vendor/oauth/lib/google.rb +0 -41
  108. data/lib/vendor/oauth/lib/linkedin.rb +0 -41
  109. data/lib/vendor/oauth/lib/stackexchange.rb +0 -37
  110. data/lib/vendor/oauth/lib/twitter.rb +0 -41
  111. data/lib/vendor/oauth/oauth.rb +0 -46
@@ -1,8 +1,7 @@
1
1
  # experiment for different nav in rooter
2
2
 
3
- class Lux::Controller::Nav
4
-
5
- attr_reader :root, :path, :id, :full, :locale, :subdomain, :domain
3
+ class Lux::Application::Nav
4
+ attr_reader :path, :subdomain, :domain, :id
6
5
 
7
6
  # acepts path as a string
8
7
  def initialize request
@@ -12,32 +11,31 @@ class Lux::Controller::Nav
12
11
  @subdomain = request.host.split('.')
13
12
  @domain = @subdomain.pop(2).join('.')
14
13
  @domain += ".#{@subdomain.pop}" if @domain.length < 6
15
-
16
- build_full
17
14
  end
18
15
 
19
- def build_full
16
+ def full
20
17
  @full = '/%s/%s' % [@root, @path.join('/')]
18
+ @full = @full.sub(/\/$/, '')
21
19
  end
22
20
 
23
21
  def shift_to_root
24
22
  @root.tap do
25
23
  @root = @path.shift.to_s.gsub('-', '_')
26
- build_full
27
24
  end
25
+
26
+ @root = nil if @root.blank?
27
+
28
+ @root
29
+ end
30
+
31
+ def root sub_nav=nil
32
+ sub_nav ? ('%s/%s' % [@root, sub_nav]) : @root
28
33
  end
29
34
 
30
35
  # used to make admin.lvm.me/users to lvh.me/admin/users
31
36
  def unshift name
32
37
  @path.unshift @root
33
38
  @root = name
34
- build_full
35
- end
36
-
37
- def parse_locale
38
- return false unless Locale.all.include?(@root)
39
- Locale.current = shift_to_root
40
- true
41
39
  end
42
40
 
43
41
  def shift
@@ -68,14 +66,13 @@ class Lux::Controller::Nav
68
66
  @full
69
67
  end
70
68
 
71
- # if sets @id to whatever function returns
72
- # page.nav.id! { |id| StringBase.extract id }
73
- def id! &block
74
- @block = block if block
69
+ def id
70
+ if first && block_given?
71
+ if @id = yield(first)
72
+ shift
73
+ end
74
+ end
75
75
 
76
- return unless first
77
- @id = @block.call first
78
- shift if @id
79
76
  @id
80
77
  end
81
78
  end
@@ -0,0 +1,10 @@
1
+ class Lux::Application
2
+
3
+ def lux_static_files_plug
4
+ file = Lux::Current::StaticFile.new(Lux.current.request.path)
5
+ return false unless file.is_static_file?
6
+ file.deliver
7
+ true
8
+ end
9
+
10
+ end
@@ -0,0 +1,58 @@
1
+ # handy :)
2
+ # renders full pages and exposes page object (req, res) in yiled
3
+ # for easy and powerful testing
4
+ # Hash :qs, Hash :post, String :method, Hash :cookies, Hash :session
5
+ # https://github.com/rack/rack/blob/master/test/spec_request.rb
6
+
7
+ Lux::Application.class_eval do
8
+ def self.render path='/mock', in_opts={}, &block
9
+ allowed_opts = [:qs, :post, :method, :session, :cookies]
10
+ in_opts.keys.each { |k| die "#{k} is not allowed as opts param. allowed are #{allowed_opts}" unless allowed_opts.index(k) }
11
+
12
+ opts = {}
13
+
14
+ if in_opts[:post]
15
+ opts[:query_string] = in_opts[:post]
16
+ opts[:request_method] = :post
17
+ else
18
+ opts[:query_string] = in_opts[:qs] || {}
19
+ opts[:request_method] ||= in_opts[:method] || :get
20
+ end
21
+
22
+ opts[:request_method] = opts[:request_method].to_s.upcase
23
+ opts[:query_string] = opts[:query_string].to_query if opts[:query_string].class.to_s == 'Hash'
24
+
25
+ if path[0,4] == 'http'
26
+ parsed = URI.parse(path)
27
+ opts[:server_name] = parsed.host
28
+ opts[:server_port] = parsed.port
29
+ path = '/'+path.split('/', 4).last
30
+ end
31
+
32
+ env = Rack::MockRequest.env_for(path)
33
+ env[:input] = opts[:post] if opts[:post]
34
+ for k,v in opts
35
+ env[k.to_s.upcase] = v
36
+ end
37
+
38
+ page = Lux::Current.new(env)
39
+ Lux.current.session.merge!(in_opts[:session]) if in_opts[:session]
40
+
41
+ if block_given?
42
+ return Lux.app.new.instance_exec &block
43
+ end
44
+
45
+ response = Lux.current.response.render
46
+
47
+ body = response[2].join('')
48
+ body = JSON.parse body if response[1]['content-type'].index('/json')
49
+
50
+ {
51
+ time: response[1]['x-lux-speed'],
52
+ status: response[0],
53
+ headers: response[1],
54
+ session: Lux.current.session,
55
+ body: body
56
+ }.h
57
+ end
58
+ end
@@ -0,0 +1,64 @@
1
+ # called by Lux::Application to test route matching
2
+ class Lux::Application::RouteTest
3
+ LUX_PRINT_ROUTES = !!ENV['LUX_PRINT_ROUTES'] unless defined?(LUX_PRINT_ROUTES)
4
+
5
+ def initialize controller
6
+ @controller = controller
7
+ end
8
+
9
+ def current
10
+ Lux.current
11
+ end
12
+
13
+ def action route_object, opts={}
14
+ if route_object.class == Hash
15
+ route_test = route_object.keys.first
16
+ route_to = route_object.values.first
17
+ else
18
+ route_test = route_object
19
+ route_to = opts[:to] || route_object
20
+ end
21
+
22
+ puts '/%s => %s#%s' % [route_test.to_s.ljust(20), @controller.route_target, route_to] if LUX_PRINT_ROUTES
23
+
24
+ if test? route_test
25
+ @controller.call @controller.route_target, route_to
26
+ end
27
+ end
28
+ alias :map :action
29
+
30
+ def call route
31
+ if test? route
32
+ @controller.call @controller.route_target
33
+ end
34
+ end
35
+
36
+ # calls base index if root
37
+ def root
38
+ @controller.call @controller.route_target unless current.nav.root
39
+ end
40
+
41
+ def test? route
42
+ case route
43
+ when String
44
+ current.request.path.starts_with?(route)
45
+ when Symbol
46
+ route.to_s == current.nav.root
47
+ when Regexp
48
+ !!(route =~ current.nav.root)
49
+ when Array
50
+ !!route.map(&:to_s).include?(current.nav.root)
51
+ else
52
+ raise 'Route type %s is not supported' % route.class
53
+ end
54
+ end
55
+
56
+ def print_route route, action=nil
57
+ return unless LUX_PRINT_ROUTES
58
+
59
+ target = @controller.route_target.to_s
60
+ target += '#%s' % action if action
61
+
62
+ puts '/%s => %s' % [route.to_s.ljust(20), target]
63
+ end
64
+ end
@@ -3,19 +3,14 @@
3
3
  module Lux::Cache
4
4
  extend self
5
5
 
6
+ # Lux::Cache.sever = :ram
6
7
  def server= obj
8
+ obj = "Lux::Cache::#{obj.to_s.classify}Cache".constantize if obj.class == Symbol
7
9
  @@server = obj
8
10
  end
9
11
 
10
- # cache data in current thread
11
- def thread key
12
- data = Lux.thread[:cache][key]
13
- return data if data
14
- Lux.thread[:cache][key] = yield
15
- end
16
-
17
12
  def read key
18
- return nil if (Lux.page.no_cache? rescue false)
13
+ return nil if (Lux.current.no_cache? rescue false)
19
14
  @@server.get(key)
20
15
  end
21
16
  alias :get :read
@@ -36,20 +31,22 @@ module Lux::Cache
36
31
  end
37
32
 
38
33
  def fetch key, opts={}
39
- opts = { ttl: opts } unless opts.is_a?(Hash)
40
- opts = opts.to_opts!(:ttl, :log, :force)
34
+ opts = { ttl: opts } unless opts.is_a?(Hash)
35
+ opts = opts.to_opts!(:ttl, :force, :log)
41
36
 
42
37
  opts.ttl = opts.ttl.to_i if opts.ttl
43
- opts.log ||= true if opts.log.nil?
44
- opts.force ||= true if opts.force.nil?
38
+ opts.log ||= Lux.config(:log_to_stdout) unless opts.log.class == FalseClass
39
+ opts.force ||= Lux.current.try(:no_cache?) unless opts.force.class == FalseClass
45
40
 
46
- @@server.delete key if Lux.page && opts.force && Lux.page.no_cache?
41
+ @@server.delete key if opts.force
47
42
 
48
43
  Lux.log " Cache.fetch.get #{key} (ttl: #{opts.ttl.or(:nil)})".green if opts.log
49
44
 
50
45
  data = @@server.fetch key, opts.ttl do
51
- data = yield
52
- Lux.log " Cache.fetch.SET #{key} len:#{data.to_s.length}" if opts.log
46
+ speed = Lux.speed { data = yield }
47
+
48
+ Lux.log " Cache.fetch.SET #{key} len:#{data.to_s.length} (#{speed})".red if opts.log
49
+
53
50
  data
54
51
  end
55
52
 
@@ -63,7 +60,10 @@ module Lux::Cache
63
60
 
64
61
  def generate_key *data
65
62
  keys = []
63
+
66
64
  for el in [data].flatten
65
+ keys.push el.id if el.respond_to?(:id)
66
+
67
67
  if el.respond_to?(:updated_at)
68
68
  keys.push el.updated_at
69
69
  elsif el.respond_to?(:created_at)
@@ -72,7 +72,18 @@ module Lux::Cache
72
72
  keys.push el.to_s
73
73
  end
74
74
  end
75
+
75
76
  key = keys.join('-')
76
- key.length < 30 ? key : Crypt.md5(key)
77
+ Crypt.sha1(key)
78
+ end
79
+
80
+ def []= key, value
81
+ @@server.set key.to_s, value
82
+ value
77
83
  end
84
+
85
+ def [] key
86
+ @@server.get key.to_s
87
+ end
88
+
78
89
  end
data/lib/lux/cell/cell.rb CHANGED
@@ -14,18 +14,18 @@ class Lux::Cell
14
14
  ClassAttributes.define self, :helper
15
15
 
16
16
  # before and after any action filter, ignored in cells, after is called just before render
17
- BeforeAndAfter.define self, :before, :before_action, :before_render, :after
17
+ ClassCallbacks.define self, :before, :before_action, :before_render, :after
18
18
 
19
19
  class << self
20
20
  # class call method, should not be overridden
21
21
  def call
22
- Lux.page.files_in_use.push "app/cells/#{self.to_s.underscore}.rb"
22
+ Lux.current.files_in_use.push "app/cells/#{self.to_s.underscore}.rb"
23
23
 
24
24
  cell = new
25
25
  cell.filter :before
26
26
  cell.call
27
27
 
28
- return if Lux.page.body
28
+ return if Lux.current.response.body
29
29
 
30
30
  # we want to exec filter after the call
31
31
  cell.filter :before_action
@@ -34,8 +34,7 @@ class Lux::Cell
34
34
  # create mock function, to enable template rendering
35
35
  # mock :index, :login
36
36
  def mock *args
37
- for el in args
38
- # class_eval %[def #{el}(*args); true; end]
37
+ args.each do |el|
39
38
  define_method el do
40
39
  true
41
40
  end
@@ -43,19 +42,8 @@ class Lux::Cell
43
42
  end
44
43
 
45
44
  # simple shortcut allows direct call to action, bypasing call
46
- def action name, object=nil
47
- object.present? ? new.action(name, object) : new.action(name)
48
- end
49
-
50
- # for use in helpers, mostly
51
- # renders only cell without layout
52
- # = cell :tag_list, object
53
- def cell name, *args
54
- c = new
55
- c.instance_variable_set '@cell_action', name
56
- c.instance_variable_set '@no_render', true
57
- c.send name, *args
58
- c.render_part
45
+ def action *args
46
+ new.action(*args)
59
47
  end
60
48
  end
61
49
 
@@ -66,7 +54,7 @@ class Lux::Cell
66
54
  def initialize
67
55
  # before and after should be exected only once
68
56
  @executed_filters = {}
69
- @base_template = self.class.to_s.index('::') ? self.class.to_s.sub(/Cell$/,'').underscore : self.class.to_s.sub(/Cell$/,'').downcase
57
+ @base_template = self.class.to_s.include?('::') ? self.class.to_s.sub(/Cell$/,'').underscore : self.class.to_s.sub(/Cell$/,'').downcase
70
58
  end
71
59
 
72
60
  # default call method, should be overitten
@@ -76,11 +64,17 @@ class Lux::Cell
76
64
  action(:index)
77
65
  end
78
66
 
67
+ # execute before and after filters, only once
79
68
  def filter fiter_name
69
+ # move this to ClassCallbacks class?
80
70
  return if @executed_filters[fiter_name]
81
71
  @executed_filters[fiter_name] = true
82
72
 
83
- BeforeAndAfter.execute(self, fiter_name)
73
+ ClassCallbacks.execute(self, fiter_name)
74
+ end
75
+
76
+ def cache *args, &block
77
+ Lux.cache.fetch *args, &block
84
78
  end
85
79
 
86
80
  # action(:show, 2)
@@ -89,17 +83,17 @@ class Lux::Cell
89
83
  raise ArgumentError.new('Cell action called with blank action name argument') if method_name.blank?
90
84
 
91
85
  # maybe before filter rendered page
92
- return if Lux.page.body
86
+ return if response.body
93
87
 
94
88
  method_name = method_name.to_s.gsub('-', '_').gsub(/[^\w]/, '')
95
89
 
96
90
  Lux.log " #{self.class.to_s}(:#{method_name})".light_blue
97
- Lux.page.files_in_use.push "app/cells/#{self.class.to_s.underscore}.rb"
91
+ Lux.current.files_in_use.push "app/cells/#{self.class.to_s.underscore}.rb"
98
92
 
99
93
  @cell_action = method_name
100
94
 
101
95
  unless respond_to? method_name
102
- raise NotFoundError.new('Method %s not found' % method_name) unless Lux.verbose?
96
+ raise NotFoundError.new('Method %s not found' % method_name) unless Lux.config(:show_server_errors)
103
97
 
104
98
  list = methods - Lux::Cell.instance_methods
105
99
  err = [%[No instance method "#{method_name}" found in class "#{self.class.to_s}"]]
@@ -109,15 +103,15 @@ class Lux::Cell
109
103
  end
110
104
 
111
105
  filter :before
112
- return if Lux.page.body
106
+ return if response.body
113
107
 
114
108
  filter :before_action
115
- return if Lux.page.body
109
+ return if response.body
116
110
 
117
111
  send method_name, *args
118
112
  filter :after
119
113
 
120
- return if Lux.page.body
114
+ return if response.body
121
115
  render
122
116
  end
123
117
 
@@ -127,7 +121,7 @@ class Lux::Cell
127
121
  # render :profile, name:'Dux'
128
122
  # render text: 'ok'
129
123
  def render name=nil, opts={}
130
- return if Lux.page.body
124
+ return if response.body
131
125
  return if @no_render
132
126
 
133
127
  filter :before_render
@@ -139,8 +133,9 @@ class Lux::Cell
139
133
 
140
134
  opts[:template] = name if name
141
135
 
142
- render_resolve_body(opts)
143
- Lux.cache.set(opts[:cache], Lux.page.body) if opts[:cache]
136
+ render_resolve_body opts
137
+
138
+ Lux.cache.set(opts[:cache], response.body) if opts[:cache]
144
139
  end
145
140
 
146
141
  # renders template to string
@@ -162,18 +157,16 @@ class Lux::Cell
162
157
  def render_resolve_body opts
163
158
  # resolve basic types
164
159
  if opts[:text]
165
- Lux.page.content_type = 'text/plain'
166
- return Lux.page.body(opts[:text])
160
+ response.content_type = 'text/plain'
161
+ return response.body(opts[:text])
167
162
  elsif opts[:html]
168
- Lux.page.content_type = 'text/html'
169
- return Lux.page.body(opts[:html])
163
+ response.content_type = 'text/html'
164
+ return response.body(opts[:html])
170
165
  elsif opts[:json]
171
- Lux.page.content_type = 'application/json'
172
- return Lux.page.body(opts[:json])
166
+ response.content_type = 'application/json'
167
+ return response.body(opts[:json])
173
168
  end
174
169
 
175
- ivh = instance_variables_hash
176
-
177
170
  # resolve page data, without template
178
171
  page_data = opts[:data] || Proc.new do
179
172
  if template = opts.delete(:template)
@@ -183,15 +176,17 @@ class Lux::Cell
183
176
  template = "#{@base_template}/#{@cell_action}"
184
177
  end
185
178
 
186
- Lux::Template.render_part(template, ivh, self.class.helper)
179
+ Lux::Template.render_part(template, helper)
187
180
  end.call
188
181
 
189
182
  # resolve data with layout
190
183
  layout = opts.delete(:layout)
191
184
  layout = nil if layout.class == TrueClass
192
185
  layout = false if @layout.class == FalseClass
186
+
193
187
  if layout.class != FalseClass
194
- layout_define = self.class.layout
188
+ layout_define = layout || self.class.layout
189
+
195
190
  layout = case layout_define
196
191
  when String
197
192
  layout = layout_define
@@ -203,47 +198,64 @@ class Lux::Cell
203
198
  "#{@base_template.split('/')[0]}/layout"
204
199
  end
205
200
 
206
- page_data = Lux::Template.new(layout, instance_variables_hash, self.class.helper).render_part do
201
+ page_data = Lux::Template.new(layout, helper).render_part do
207
202
  page_data
208
203
  end
209
204
  end
210
205
 
211
- Lux.page.body(page_data) unless opts[:set_page_body].is_false?
206
+ response.body(page_data) unless opts[:set_page_body].is_false?
207
+
212
208
  page_data
213
209
  end
214
210
 
215
- # helper functions
216
- def page
217
- Lux.page
211
+ def etag *args
212
+ response.etag *args
218
213
  end
219
214
 
220
- def params
221
- Lux.page.params
215
+ def halt status, desc=nil
216
+ response.status = status
217
+ response.body = desc || "Hatlt code #{status}"
218
+
219
+ throw :done
222
220
  end
223
221
 
224
- def nav
225
- Lux.page.nav
222
+ # helper functions
223
+ def current
224
+ Lux.current
226
225
  end
227
226
 
228
227
  def request
229
- Lux.page.request
228
+ Lux.current.request
229
+ end
230
+
231
+ def response
232
+ Lux.current.response
233
+ end
234
+
235
+ def params
236
+ Lux.current.params
237
+ end
238
+
239
+ def nav
240
+ Lux.current.nav
230
241
  end
231
242
 
232
243
  def redirect where, flash={}
233
- Lux.page.redirect where, flash
244
+ Lux.current.redirect where, flash
234
245
  end
235
246
 
236
247
  def session
237
- Lux.page.session
248
+ Lux.current.session
238
249
  end
239
250
 
240
251
  def namespace
241
252
  @base_template.split('/')[0].to_sym
242
253
  end
243
254
 
244
- def helper(ns=nil)
245
- Lux::Helper.for(ns || namespace)
255
+ def helper ns=nil
256
+ Lux::Helper.new self, :html, self.class.helper, ns
246
257
  end
247
-
248
258
  end
249
259
 
260
+ ApplicationCell = Class.new Lux::Cell
261
+