lux-fw 0.5.36 → 0.5.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f88cd45d785eba48eb2321f58d7d6c5e8748339a6dffef24181be783724fed5c
4
- data.tar.gz: 368139721b7d25d90839e1b9d948130134c9b6f2bed642a10d75a8e81ba1ed1e
3
+ metadata.gz: 4eabd8ade1e698ed7f377a9d0e14f819b72be8847f403c1b380ebf4997994716
4
+ data.tar.gz: 5b2092385c1fae7b70ddfebe2efd4b0c97a3e03a3baec4bdb260156941c7e13d
5
5
  SHA512:
6
- metadata.gz: f38a00ea2a8d43814645f05dd4e59d39d81b6bff5ac29542ae1c41dbb7082f04a050e33d667c9d7a3a09dba285bd0786e7784869595f6ab340cb1bbb96558bde
7
- data.tar.gz: 381f478c2e06dd5123f04764b8515b4f8f6e4e438a222c7f89e6e8b5e05cb58952424640c19e2b1d14b2570f7fb646646b4820469e845b9631a526b226cc80e0
6
+ metadata.gz: a3e77f76261c629cff38cac6740968dd8c30acd620f4a5dd0370c1c0d3c4cdda8453586c67ab0bafae1205a7e22907db7b771af268009f9f401c656c454fc488
7
+ data.tar.gz: e71564c624c06c921da14ba3ac53a0a904ad1343af90c5bddcfa9fce06845fa1feb91a55964265dbe5514bfa7f63e3d6a8ccda9c68aec7e51aef2a973662e0b3
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.36
1
+ 0.5.37
@@ -75,3 +75,5 @@ File.write './README.md', out
75
75
  `rm -rf misc/demo/tmp`
76
76
  `rm -rf misc/demo/Gemfile.lock`
77
77
  `rm -rf misc/demo/package.json`
78
+
79
+ puts 'lux-fw Readme, demo build'
@@ -43,13 +43,14 @@ LuxCli.class_eval do
43
43
  route = '/%s' % route unless route.include?('/')
44
44
  route += '/*' unless target.include?('#')
45
45
  route = "#{@prefix}/*" if route .include?('#')
46
+
46
47
  print "#{indent}#{route}".ljust(50)
47
48
  print target.ljust(50)
48
49
 
49
50
  if controller && !target.include?('#')
50
51
  puts
51
52
  for el in controller.instance_methods(false)
52
- print " #{route.to_s.sub('/*', '/')}#{el}".ljust(50)
53
+ print " #{route.to_s.sub('/*', '/').gsub('//', '/')}#{el}".ljust(50)
53
54
  puts [target, el].join(' # ')
54
55
  end
55
56
  else
@@ -61,6 +62,8 @@ LuxCli.class_eval do
61
62
  if @target
62
63
  target = @target.is_a?(String) && !@target.include?('#') ? @target + "##{obj}" : @target
63
64
  show_route obj, target
65
+ elsif obj.is_a?(Array)
66
+ show_route obj[0], obj[1]
64
67
  elsif obj.is_a?(Hash)
65
68
  show_route obj.keys.first, obj.values.first
66
69
  elsif block_given?
@@ -25,6 +25,6 @@ Start the app
25
25
 
26
26
  Look at the generated code and play with it.
27
27
 
28
- ## Lux components
28
+
29
29
 
30
30
 
@@ -1,6 +1,6 @@
1
- # Page render flow
1
+ ## Page render flow
2
2
 
3
- ## Example config ru
3
+ ### Example config.ru
4
4
  ```
5
5
  $lux_start_time = Time.now
6
6
  require './config/application'
@@ -65,7 +65,7 @@ Lux.app do
65
65
 
66
66
  ###
67
67
 
68
- routes do
68
+ routes do |r|
69
69
  # we show on root method, that target can be multiple object types, 5 variants
70
70
  root [RootController, :index] # calls RootController#index
71
71
  root 'root#call' # calls RootController#call
@@ -76,7 +76,12 @@ Lux.app do
76
76
  # we can route based on the user status
77
77
  root User.current ? 'main/root' : 'guest'
78
78
 
79
+ # simple route
80
+ r.about 'static#about'
81
+
79
82
  # map "/api" to "api_router" method
83
+ r.api :api_router
84
+ # or
80
85
  map api: :api_router
81
86
 
82
87
  # with MainController
@@ -4,19 +4,20 @@
4
4
 
5
5
  class Lux::Application
6
6
  class_callback :config # pre boot app config
7
- class_callback :web_boot # rack_handler is passed as argument
7
+ class_callback :rack_boot # rack_handler is passed as argument
8
8
  class_callback :info # called by "lux config" cli
9
9
  class_callback :before # before any page load
10
10
  class_callback :routes # routes resolve
11
11
  class_callback :after # after any page load
12
12
 
13
- web_boot do |rack_handler|
13
+ rack_boot do |rack_handler|
14
14
  # deafult host is required
15
15
  unless Lux.config.host.to_s.include?('http')
16
16
  raise 'Invalid "Lux.config.host"'
17
17
  end
18
18
 
19
19
  if Lux.config(:dump_errors)
20
+ require 'binding_of_caller'
20
21
  require 'better_errors'
21
22
 
22
23
  rack_handler.use BetterErrors::Middleware
@@ -280,7 +281,7 @@ class Lux::Application
280
281
  case data = object.call
281
282
  when Array
282
283
  response.status = data.first
283
- response.body data[2]
284
+ response.body data[2].is_a?(Array) ? data[2][0] : data[2]
284
285
  else
285
286
  response.body data
286
287
  end
@@ -340,13 +341,15 @@ class Lux::Application
340
341
  def main
341
342
  return if deliver_static_assets
342
343
 
344
+ magic = MagicRoutes.new self
345
+
343
346
  catch(:done) do
344
- class_callback :before
345
- class_callback :routes unless body?
347
+ class_callback :before, magic
348
+ class_callback :routes, magic unless body?
346
349
  end
347
350
 
348
351
  catch(:done) do
349
- class_callback :after
352
+ class_callback :after, magic
350
353
  end
351
354
  rescue => e
352
355
  response.body { nil }
@@ -0,0 +1,16 @@
1
+ # Maps routes to method missing for cleaner interface
2
+ # routes do |r|
3
+ # map :about => 'root#about'
4
+ # r.about 'root#about'
5
+ class Lux::Application::MagicRoutes
6
+
7
+ def initialize app
8
+ @app = app
9
+ end
10
+
11
+ def method_missing route, *args, &block
12
+ @app.map [route, args.first || block]
13
+ end
14
+
15
+ end
16
+
@@ -22,11 +22,15 @@ class Lux::Application::Nav
22
22
  parts = @path.last.split('.')
23
23
 
24
24
  if parts[1]
25
- @format = parts.pop.to_s.downcase.to_sym
25
+ @format = @format_once = parts.pop.to_s.downcase.to_sym
26
26
  @path.last = parts.join('.')
27
27
  end
28
28
  end
29
29
 
30
+ def get_format_once
31
+ @format_once.tap { @format_once = nil }
32
+ end
33
+
30
34
  def active_shift
31
35
  @active = @path.shift
32
36
  end
@@ -39,15 +39,6 @@ class Lux::Controller
39
39
  @base_template = self.class.to_s.include?('::') ? self.class.to_s.sub(/Controller$/,'').underscore : self.class.to_s.sub(/Controller$/,'').downcase
40
40
  end
41
41
 
42
- # because we can call action multiple times
43
- # ensure we execute filters only once
44
- def filter fiter_name, arg=nil
45
- return if @executed_filters[fiter_name]
46
- @executed_filters[fiter_name] = true
47
-
48
- Object.class_callback fiter_name, self, @controller_action
49
- end
50
-
51
42
  def cache *args, &block
52
43
  Lux.cache.fetch *args, &block
53
44
  end
@@ -246,4 +237,12 @@ class Lux::Controller
246
237
  end
247
238
  end
248
239
 
240
+ # because we can call action multiple times
241
+ # ensure we execute filters only once
242
+ def filter fiter_name, arg=nil
243
+ return if @executed_filters[fiter_name]
244
+ @executed_filters[fiter_name] = true
245
+
246
+ Object.class_callback fiter_name, self, @controller_action
247
+ end
249
248
  end
@@ -39,6 +39,7 @@ class Lux::Current
39
39
  @nav = Lux::Application::Nav.new request
40
40
  end
41
41
 
42
+ # Domain part of the host
42
43
  def domain
43
44
  host = Lux.current.request.host.split('.')
44
45
  host_country = host.pop
@@ -46,32 +47,35 @@ class Lux::Current
46
47
  host_name ? "#{host_name}.#{host_country}" : host_country
47
48
  end
48
49
 
50
+ # Full host with port
49
51
  def host
50
52
  "#{request.env['rack.url_scheme']}://#{request.host}:#{request.port}".sub(':80','')# rescue 'http://locahost:3000'
51
53
  end
52
54
 
55
+ # Current scope variables hash
53
56
  def var
54
57
  Thread.current[:lux][:var] ||= Hashie::Mash.new
55
58
  end
56
59
 
57
- # cache data in current page
60
+ # Cache data in current page
58
61
  def cache key
59
62
  data = Thread.current[:lux][:cache][key]
60
63
  return data if data
61
64
  Thread.current[:lux][:cache][key] = yield
62
65
  end
63
66
 
64
- # set current.can_clear_cache = true in production for admins
67
+ # Set current.can_clear_cache = true in production for admins
65
68
  def no_cache?
66
69
  @can_clear_cache = true if Lux.dev?
67
70
  @can_clear_cache && @request.env['HTTP_CACHE_CONTROL'].to_s.downcase == 'no-cache' ? true : false
68
71
  end
69
72
 
73
+ # Redirect from current page
70
74
  def redirect *args
71
75
  response.redirect *args
72
76
  end
73
77
 
74
- # execute action once per page
78
+ # Execute action once per page
75
79
  def once id=nil, data=nil, &block
76
80
  id ||= Digest::SHA1.hexdigest caller[0] if block
77
81
 
@@ -82,11 +86,13 @@ class Lux::Current
82
86
  block_given? ? yield : data
83
87
  end
84
88
 
89
+ # Generete unique ID par page render
85
90
  def uid
86
91
  Thread.current[:uid_cnt] ||= 0
87
92
  "uid-#{Thread.current[:uid_cnt]+=1}"
88
93
  end
89
94
 
95
+ # Add to list of files in use
90
96
  def files_in_use file=nil
91
97
  if block_given?
92
98
  return yield(file) unless @files_in_use.include?(file)
@@ -139,7 +139,9 @@ module ::Lux
139
139
  # must be called when serving web pages from rackup
140
140
  def serve rack_handler
141
141
  @rackup_start = true
142
- Object.class_callback :web_boot, Lux::Application, rack_handler
142
+
143
+ # Boot Lux
144
+ Object.class_callback :rack_boot, Lux::Application, rack_handler
143
145
  rack_handler.run self
144
146
  end
145
147
 
@@ -109,6 +109,11 @@ class Hash
109
109
  transform_keys!{ |key| key.to_sym rescue key }
110
110
  end
111
111
 
112
+ def pretty_generate
113
+ JSON.pretty_generate(self).gsub(/"([\w\-]+)":/) { %["#{$1.yellow}":] }
114
+ end
115
+
116
+ # Returns hash with only se
112
117
  def slice *keys
113
118
  keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
114
119
  keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
@@ -124,8 +129,21 @@ class Hash
124
129
  omit
125
130
  end
126
131
 
127
- def pretty_generate
128
- JSON.pretty_generate(self).gsub(/"([\w\-]+)":/) { %["#{$1.yellow}":] }
132
+ # Returns a hash that includes everything but the given keys.
133
+ # hash = { a: true, b: false, c: nil}
134
+ # hash.except(:c) # => { a: true, b: false}
135
+ # hash # => { a: true, b: false, c: nil}
136
+ #
137
+ # This is useful for limiting a set of parameters to everything but a few known toggles:
138
+ # @person.update(params[:person].except(:admin))
139
+ def except(*keys)
140
+ dup.except!(*keys)
141
+ end
142
+
143
+ # Hash#except in place, modifying current hash
144
+ def except!(*keys)
145
+ keys.each { |key| delete(key) }
146
+ self
129
147
  end
130
148
  end
131
149
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux-fw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.36
4
+ version: 0.5.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
@@ -262,6 +262,34 @@ dependencies:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
264
  version: '2'
265
+ - !ruby/object:Gem::Dependency
266
+ name: binding_of_caller
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: nokogiri
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - "~>"
284
+ - !ruby/object:Gem::Version
285
+ version: '1'
286
+ type: :runtime
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - "~>"
291
+ - !ruby/object:Gem::Version
292
+ version: '1'
265
293
  description: Ruby framework optimized for speed and linghtness
266
294
  email: rejotl@gmail.com
267
295
  executables:
@@ -302,6 +330,7 @@ files:
302
330
  - "./lib/lux/README.md"
303
331
  - "./lib/lux/application/README.md"
304
332
  - "./lib/lux/application/application.rb"
333
+ - "./lib/lux/application/lib/magic_routes.rb"
305
334
  - "./lib/lux/application/lib/nav.rb"
306
335
  - "./lib/lux/application/lib/render.rb"
307
336
  - "./lib/lux/cache/.DS_Store"