lux-fw 0.5.36 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +26 -13
  4. data/bin/cli/benchmark.rb +18 -0
  5. data/bin/cli/cerb.rb +90 -0
  6. data/bin/cli/config.rb +4 -11
  7. data/bin/cli/console.rb +72 -30
  8. data/bin/cli/eval.rb +5 -27
  9. data/bin/cli/generate.rb +9 -11
  10. data/bin/cli/get.rb +14 -6
  11. data/bin/cli/memory.rb +12 -0
  12. data/bin/cli/new.rb +2 -0
  13. data/bin/cli/secrets.rb +3 -31
  14. data/bin/cli/server.rb +28 -9
  15. data/bin/cli/stats.rb +26 -20
  16. data/bin/cli/template.rb +10 -0
  17. data/bin/generate_doc +168 -0
  18. data/bin/lux +73 -10
  19. data/lib/README.md +18 -8
  20. data/lib/common/crypt.rb +60 -9
  21. data/lib/common/string_base.rb +54 -15
  22. data/lib/common/struct_opts.rb +30 -0
  23. data/lib/common/time_difference.rb +75 -0
  24. data/lib/loader.rb +41 -0
  25. data/lib/lux/application/README.md +67 -105
  26. data/lib/lux/application/application.rb +87 -329
  27. data/lib/lux/application/lib/magic_routes.rb +22 -0
  28. data/lib/lux/application/lib/nav.rb +218 -99
  29. data/lib/lux/application/lib/render.rb +47 -67
  30. data/lib/lux/application/lib/routes.rb +242 -0
  31. data/lib/lux/application/lib/shared.rb +47 -0
  32. data/lib/lux/application/lux_adapter.rb +6 -0
  33. data/lib/lux/application/lux_config.rb +26 -0
  34. data/lib/lux/cache/Find Results +24 -0
  35. data/lib/lux/cache/README.md +28 -35
  36. data/lib/lux/cache/cache.rb +78 -26
  37. data/lib/lux/cache/lib/memcached_server.rb +36 -0
  38. data/lib/lux/cache/lib/memory_server.rb +44 -0
  39. data/lib/lux/cache/lib/null_server.rb +33 -0
  40. data/lib/lux/cache/lib/sqlite_server.rb +62 -0
  41. data/lib/lux/cache/lux_adapter.rb +19 -0
  42. data/lib/lux/config/config.rb +93 -144
  43. data/lib/lux/config/lux_adapter.rb +27 -0
  44. data/lib/lux/controller/README.md +67 -12
  45. data/lib/lux/controller/controller.rb +237 -187
  46. data/lib/lux/current/README.md +29 -10
  47. data/lib/lux/current/current.rb +166 -77
  48. data/lib/lux/current/lib/current.rb +6 -0
  49. data/lib/lux/current/lib/encrypt_params.rb +38 -36
  50. data/lib/lux/current/lib/session.rb +86 -65
  51. data/lib/lux/current/lux_adapter.rb +5 -0
  52. data/lib/lux/environment/README.md +24 -0
  53. data/lib/lux/environment/environment.rb +91 -0
  54. data/lib/lux/environment/lux_adapter.rb +13 -0
  55. data/lib/lux/error/README.md +18 -19
  56. data/lib/lux/error/error.rb +207 -152
  57. data/lib/lux/error/lux_adapter.rb +9 -0
  58. data/lib/lux/logger/README.md +45 -0
  59. data/lib/lux/logger/lux_adapter.rb +27 -0
  60. data/lib/lux/lux.rb +72 -129
  61. data/lib/lux/mailer/README.md +12 -5
  62. data/lib/lux/mailer/lux_config.rb +4 -0
  63. data/lib/lux/mailer/mailer.rb +81 -59
  64. data/lib/lux/plugin/README.md +19 -0
  65. data/lib/lux/plugin/lux_adapter.rb +8 -0
  66. data/lib/lux/plugin/plugin.rb +65 -0
  67. data/lib/lux/render/README.md +100 -0
  68. data/lib/lux/render/render.rb +12 -0
  69. data/lib/lux/response/README.md +57 -1
  70. data/lib/lux/response/lib/file.rb +87 -65
  71. data/lib/lux/response/lib/flash.rb +49 -34
  72. data/lib/lux/response/lib/header.rb +34 -33
  73. data/lib/lux/response/response.rb +252 -164
  74. data/lib/lux/template/helper.rb +130 -0
  75. data/lib/lux/template/inline_render_proxy.rb +31 -0
  76. data/lib/lux/template/lux_adapter.rb +5 -0
  77. data/lib/lux/template/template.rb +127 -0
  78. data/lib/lux-fw.rb +15 -33
  79. data/lib/overload/array.rb +33 -7
  80. data/lib/overload/blank.rb +8 -3
  81. data/lib/overload/boolean.rb +46 -0
  82. data/lib/overload/class.rb +28 -0
  83. data/lib/overload/dir.rb +117 -7
  84. data/lib/overload/file.rb +40 -5
  85. data/lib/overload/float.rb +38 -3
  86. data/lib/overload/hash.rb +81 -91
  87. data/lib/overload/integer.rb +15 -0
  88. data/lib/overload/json.rb +26 -0
  89. data/lib/overload/nil.rb +4 -8
  90. data/lib/overload/object.rb +91 -24
  91. data/lib/overload/pathname.rb +11 -0
  92. data/lib/overload/raise_variants.rb +26 -36
  93. data/lib/overload/string.rb +100 -27
  94. data/lib/overload/thread_simple.rb +100 -0
  95. data/lib/overload/time.rb +60 -38
  96. data/tasks/loader.rb +20 -7
  97. metadata +170 -169
  98. data/bin/.DS_Store +0 -0
  99. data/bin/build_gem +0 -77
  100. data/bin/cli/dbconsole.rb +0 -8
  101. data/bin/cli/routes.rb +0 -90
  102. data/lib/.DS_Store +0 -0
  103. data/lib/common/.DS_Store +0 -0
  104. data/lib/common/class_attributes.rb +0 -51
  105. data/lib/common/class_callbacks.rb +0 -47
  106. data/lib/common/free_struct.rb +0 -42
  107. data/lib/common/hash_with_indifferent_access.rb +0 -74
  108. data/lib/common/html_tag_builder.rb +0 -91
  109. data/lib/common/method_attr.rb +0 -69
  110. data/lib/common/url.rb +0 -191
  111. data/lib/lux/.DS_Store +0 -0
  112. data/lib/lux/README.md +0 -10
  113. data/lib/lux/cache/.DS_Store +0 -0
  114. data/lib/lux/cache/lib/memory.rb +0 -36
  115. data/lib/lux/cache/lib/null.rb +0 -21
  116. data/lib/lux/config/README.md +0 -63
  117. data/lib/lux/config/lib/plugin.rb +0 -65
  118. data/lib/lux/config/lib/secrets.rb +0 -48
  119. data/lib/lux/current/.DS_Store +0 -0
  120. data/lib/lux/delayed_job/.DS_Store +0 -0
  121. data/lib/lux/delayed_job/README.md +0 -3
  122. data/lib/lux/delayed_job/delayed_job.rb +0 -51
  123. data/lib/lux/delayed_job/lib/memory.rb +0 -16
  124. data/lib/lux/delayed_job/lib/nsq.rb +0 -3
  125. data/lib/lux/delayed_job/lib/postgre.rb +0 -6
  126. data/lib/lux/delayed_job/lib/redis.rb +0 -19
  127. data/lib/lux/event_bus/README.md +0 -36
  128. data/lib/lux/event_bus/event_bus.rb +0 -27
  129. data/lib/lux/view/README.md +0 -85
  130. data/lib/lux/view/cell.rb +0 -102
  131. data/lib/lux/view/helper.rb +0 -120
  132. data/lib/lux/view/lib/cell_helpers.rb +0 -29
  133. data/lib/lux/view/view.rb +0 -95
  134. data/lib/overload/it.rb +0 -29
  135. data/plugins/api/README.md +0 -49
  136. data/plugins/api/api.rb +0 -153
  137. data/plugins/api/lib/attr.rb +0 -31
  138. data/plugins/api/lib/dsl.rb +0 -52
  139. data/plugins/api/lib/error.rb +0 -3
  140. data/plugins/api/lib/model_api.rb +0 -203
  141. data/plugins/api/lib/response.rb +0 -85
  142. data/plugins/db/.DS_Store +0 -0
  143. data/plugins/db/README.md +0 -29
  144. data/plugins/db/auto_migrate/auto_migrate.rb +0 -268
  145. data/plugins/db/auto_migrate/db.rake +0 -15
  146. data/plugins/db/helpers/array_search.rb +0 -27
  147. data/plugins/db/helpers/before_save_filters.rb +0 -32
  148. data/plugins/db/helpers/composite_primary_keys.rb +0 -36
  149. data/plugins/db/helpers/core.rb +0 -94
  150. data/plugins/db/helpers/dataset_methods.rb +0 -138
  151. data/plugins/db/helpers/enums_plugin.rb +0 -52
  152. data/plugins/db/helpers/find_precache.rb +0 -31
  153. data/plugins/db/helpers/link_objects.rb +0 -84
  154. data/plugins/db/helpers/schema_checks.rb +0 -83
  155. data/plugins/db/helpers/typero_adapter.rb +0 -71
  156. data/plugins/db/logger/config.rb +0 -22
  157. data/plugins/db/logger/lux_response_adapter.rb +0 -10
  158. data/plugins/db/paginate/helper.rb +0 -32
  159. data/plugins/db/paginate/sequel_adapter.rb +0 -23
  160. data/plugins/exceptions/exceptions.rake +0 -43
  161. data/plugins/exceptions/simple_exception.rb +0 -64
  162. data/plugins/favicon/favicon.rb +0 -10
  163. data/plugins/html/README.md +0 -3
  164. data/plugins/html/html_form.rb +0 -118
  165. data/plugins/html/html_input.rb +0 -98
  166. data/plugins/html/html_menu.rb +0 -79
  167. data/plugins/html/input_types.rb +0 -346
  168. data/plugins/js_widgets/README.md +0 -5
  169. data/plugins/js_widgets/js/html_tag.coffee +0 -42
  170. data/plugins/js_widgets/js/widgets.coffee +0 -161
  171. data/plugins/js_widgets/js_widgets.rb +0 -15
  172. data/plugins/oauth/lib/facebook.rb +0 -35
  173. data/plugins/oauth/lib/github.rb +0 -38
  174. data/plugins/oauth/lib/google.rb +0 -41
  175. data/plugins/oauth/lib/linkedin.rb +0 -41
  176. data/plugins/oauth/lib/stackexchange.rb +0 -41
  177. data/plugins/oauth/lib/twitter.rb +0 -38
  178. data/plugins/oauth/oauth.rb +0 -42
  179. data/plugins/policy/policy.rb +0 -53
  180. data/tasks/nginx.rake +0 -23
  181. /data/lib/lux/{view/lib → mailer}/helper_modules.rb +0 -0
@@ -1,22 +1,53 @@
1
1
  class String
2
2
  def constantize
3
- Object.const_get('::'+self)
3
+ Object.const_get('::' + self)
4
+ end
5
+
6
+ # 'User'.constantize? # User
7
+ # 'UserFoo'.constantize? # nil
8
+ def constantize?
9
+ Object.const_defined?('::' + self) ? constantize : nil
10
+ end
11
+
12
+ # prepare data for storage write, to make it safe to dump on screen without unescape
13
+ def html_escape display = false
14
+ # .gsub('<', '&lt;').gsub('>', '&gt;')
15
+ # .gsub("'", '&#39').gsub('"', '&#34')
16
+ self
17
+ .gsub('<', display ? '&lt;' : '#LT;')
18
+ .gsub(/\A^\s+|\s+\z/,'')
19
+ end
20
+
21
+ # restore original before storage read
22
+ def html_unsafe full = false
23
+ if full
24
+ self
25
+ .gsub('#LT;', '<')
26
+ .gsub('$LT;', '<')
27
+ .gsub('&lt;', '<')
28
+ .gsub('&gt;', '>')
29
+ .gsub('&#39', "'")
30
+ .gsub('&#34', '"')
31
+ else
32
+ self.gsub('#LT;', '<')
33
+ end
4
34
  end
5
35
 
6
- # simple markdown
7
- def as_html
8
- self.gsub($/, '<br />')
36
+ # export html without scripts and styles
37
+ def html_safe full = false
38
+ html_unsafe(full)
39
+ .gsub(/<(\/?script)/i,'&lt;\1')
40
+ .gsub(/<(\/?style)/i,'&lt;\1')
9
41
  end
10
42
 
11
- # convert escaped strings, remove scritpts
12
- def to_html opts={}
13
- value = self.gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/&amp;/,'&')
14
- value = value.gsub(/<script/,'&lt;script') unless opts[:script]
15
- value = value.gsub(/<link/,'&lt;link') unless opts[:link]
16
- value
43
+ # simple markdown
44
+ def as_html
45
+ self
46
+ .gsub($/, '<br />')
47
+ .gsub(/(https?:\/\/[^\s<]+)/) { %[<a href="#{$1}">#{$1.trim(40)}</a>] }
17
48
  end
18
49
 
19
- def trim(len)
50
+ def trim len
20
51
  return self if self.length<len
21
52
  data = self.dup[0,len]+'&hellip;'
22
53
  data
@@ -26,10 +57,24 @@ class String
26
57
  self[0,1]
27
58
  end
28
59
 
60
+ def last num = 1
61
+ len = self.length
62
+ self[len-num, len]
63
+ end
64
+
65
+ # https://github.com/rgrove/sanitize
29
66
  def sanitize
30
67
  Sanitize.clean(self, :elements=>%w[span ul ol li b bold i italic u underline hr br p], :attributes=>{'span'=>['style']} )
31
68
  end
32
69
 
70
+ def quick_sanitize
71
+ out = self.gsub('<!--{tag}-->', '')
72
+ out = out.gsub(/\sstyle="([^"]+)"/) do
73
+ $1.start_with?('text-align:') ? $1 : ''
74
+ end
75
+ out
76
+ end
77
+
33
78
  def wrap node_name, opts={}
34
79
  return self unless node_name
35
80
  opts.tag(node_name, self)
@@ -39,23 +84,24 @@ class String
39
84
  self.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
40
85
  end
41
86
 
42
- def parse_erb
43
- self.gsub(/<%=([^%]+)%>/) { eval $1; }
87
+ def parse_erb scope = nil
88
+ ERB.new(self).result(scope || binding)
44
89
  end
45
90
 
46
91
  def parameterize
47
- self.downcase.gsub(/[^\w]+/,'-')
48
- end
49
-
50
- def to_url
51
92
  str_from = 'šđč枊ĐČĆŽäÄéeöÖüüÜß'
52
93
  str_to = 'sdcczSDCCZaAeeoOuuUs'
53
- str = self.downcase.gsub(/\s+/,'-').tr(str_from, str_to)
54
- # self.downcase.gsub(/\s+/,'-').tr(str_from, str_to).gsub(/[^\w\-]/,'')
55
- str.sub(/\.$/, '').gsub('&',' and ').gsub('.',' dot ').parameterize.gsub('-dot-','.').downcase[0, 50].sub(/[\.\-]$/,'')
94
+
95
+ self
96
+ .tr(str_from, str_to)
97
+ .sub(/^[^\w+]/, '')
98
+ .sub(/[^\w+]$/, '')
99
+ .downcase
100
+ .gsub(/[^\w+]+/,'-')[0, 50]
56
101
  end
102
+ alias :to_url :parameterize
57
103
 
58
- def css_to_hash
104
+ def qs_to_hash
59
105
  self.split('&').inject({}) do |h,line|
60
106
  el = line.split('=', 2)
61
107
  h[el[0]] = el[1]
@@ -67,17 +113,21 @@ class String
67
113
  self.split(/\s*,\s*/)
68
114
  end
69
115
 
116
+ def attribute_safe
117
+ self.gsub('"', '').gsub("'", '')
118
+ end
119
+
120
+ def db_safe
121
+ self.gsub(/[^0-9a-zA-Z_]/, '')
122
+ end
123
+
70
124
  def starts_with? prefix
71
125
  prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix
72
126
  end
73
127
 
74
128
  def ends_with? suffix
129
+ return true if suffix == self
75
130
  suffix.is_a?(String) && self[-suffix.length, suffix.length] == suffix && self != suffix
76
- end
77
-
78
- def last(num=1)
79
- len = self.length
80
- self[len-num, len]
81
131
  end
82
132
 
83
133
  def span_green
@@ -94,10 +144,33 @@ class String
94
144
  end
95
145
 
96
146
  def escape
97
- CGI::escape self
147
+ CGI::escape(self).gsub('+', '%20')
98
148
  end
99
149
 
100
150
  def unescape
101
151
  CGI::unescape self
102
152
  end
153
+
154
+ def sha1
155
+ Digest::SHA1.hexdigest self
156
+ end
157
+
158
+ def md5
159
+ Digest::MD5.hexdigest self
160
+ end
161
+
162
+ def extract_scripts! list: false
163
+ scripts = []
164
+ self.gsub!(/<script\b[^>]*>(.*?)<\/script>/im) { scripts.push $1; '' }
165
+ list ? scripts : scripts.map{ "<script>#{_1}</script>"}.join($/)
166
+ end
167
+
168
+ def to_slug len = 80
169
+ self.downcase.gsub(/[^\w]+/, '_').gsub(/_+/, '-').sub(/\-$/, '')[0, len]
170
+ end
171
+
172
+ def remove_tags
173
+ self.gsub(/<[^>]+>/, '')
174
+ end
175
+
103
176
  end
@@ -0,0 +1,100 @@
1
+ # https://gist.github.com/dux/466507a5e86cadd2c4714381a1f06cf4
2
+
3
+ class Thread::Simple
4
+ # Thread::Simple.run do |t|
5
+ # for foo in bar
6
+ # t.add { ... }
7
+ # end
8
+ # end
9
+ def self.run **args
10
+ ts = new
11
+ yield ts
12
+ ts.run
13
+ end
14
+
15
+ ###
16
+
17
+ attr_accessor :que, :size, :named
18
+
19
+ def initialize size: 5, sleep: 0.05
20
+ @sync = Mutex.new
21
+ @sleep = sleep
22
+ @size = size
23
+ @que = []
24
+ @threds = []
25
+ @name_val = {}
26
+ end
27
+
28
+ def add name = nil, &block
29
+ @sync.synchronize do
30
+ if name
31
+ @que << proc { @name_val[name] = block.call }
32
+ else
33
+ @que << block
34
+ end
35
+ end
36
+ end
37
+
38
+ def run endless: false
39
+ @endless = endless
40
+
41
+ @size.times do
42
+ @threds << Thread.new do
43
+ task = nil
44
+
45
+ while active?
46
+ @sync.synchronize { task = @que.pop }
47
+ task.call if task
48
+ sleep @sleep
49
+ end
50
+ end
51
+ end
52
+
53
+ unless @endless
54
+ @threds.each(&:join)
55
+ end
56
+ end
57
+
58
+ def stop
59
+ @endless = false
60
+ end
61
+
62
+ def [] name
63
+ @name_val[name]
64
+ end
65
+
66
+ private
67
+
68
+ def active?
69
+ @endless || @que.first
70
+ end
71
+ end
72
+
73
+ ###
74
+
75
+ # pool = Thread::Simple.new
76
+
77
+ # 1.upto(20) do |i|
78
+ # pool.add i do
79
+ # print '.'
80
+ # time = rand
81
+ # sleep time
82
+ # 'Integer: %s (%s - %s)' % [i, pool.que.size, time]
83
+ # end
84
+ # end
85
+
86
+ # Thread.new do
87
+ # sleep 5
88
+ # pool.stop
89
+ # end
90
+
91
+ # pool.run endless: true
92
+
93
+ # puts
94
+
95
+ # for key in pool.named.keys.sort
96
+ # puts '%s -> %s' % [key, pool.named[key]]
97
+ # end
98
+
99
+ # puts
100
+ # puts pool[10]
data/lib/overload/time.rb CHANGED
@@ -1,10 +1,30 @@
1
1
  module TimeOptions
2
- def short
3
- strftime("%Y-%m-%d")
2
+ def short use_default = false
3
+ # lang = Lux.current.request.env['HTTP_ACCEPT_LANGUAGE'] rescue 'en'
4
+ default_format = '%Y-%m-%d'
5
+ date_format = Lux.current.var[:date_format].or(Lux.config[:date_format] || default_format)
6
+ date_format = default_format if use_default
7
+ date_format = date_format.sub('yyyy', '%Y').sub('mm', '%m').sub('dd', '%d')
8
+
9
+ current.strftime date_format
10
+ end
11
+
12
+ def long use_default=false
13
+ current.strftime("#{short(use_default)} %H:%M")
4
14
  end
5
15
 
6
- def long
7
- strftime("%Y-%m-%d %H:%M")
16
+ def current
17
+ if respond_to?(:utc) && time_zone = Lux.current.var[:time_zone]
18
+ begin
19
+ tz = TZInfo::Timezone.get(time_zone)
20
+ tz.utc_to_local utc
21
+ rescue TZInfo::InvalidTimezoneIdentifier => e
22
+ Lux.logger(:time_zone).error '%s (%s)' % [e.message, time_zone]
23
+ self
24
+ end
25
+ else
26
+ self
27
+ end
8
28
  end
9
29
  end
10
30
 
@@ -12,44 +32,39 @@ class Time
12
32
  include TimeOptions
13
33
 
14
34
  class << self
15
- # humanize_seconds(61) -> 1min 1sec
16
- # humanize_seconds(1111) -> 18min 31sec
17
- def humanize_seconds secs
35
+ # prints proc speed of execution
36
+ # it will print first execution separate from the rest, used in cache testing
37
+ def speed num = 1
38
+ start = Time.now
39
+ yield
40
+ total = Time.now - start
41
+ puts 'Speed: %s sec for 1st run' % total.round(3)
42
+ if num > 1
43
+ start = Time.now
44
+ (num - 1).times { yield }
45
+ total = Time.now - start
46
+ puts 'Other %s runs speed: %s sec, avg -> %s' % [num, total.round(3), (total/num).round(3)]
47
+ end
48
+ end
49
+
50
+ # Precise ago
51
+ # Time.agop(61) -> 1min 1sec
52
+ # Time.agop(1111) -> 18min 31sec
53
+ def agop secs, desc = nil
18
54
  return '-' unless secs
19
- secs = secs.to_i
20
- [[60, :sec], [60, :min], [24, :hrs], [356, :days], [1000, :years]].map{ |count, name|
55
+
56
+ [[60, :sec], [60, :min], [24, :hrs], [356, :days], [1000, :years]].map do |count, name|
21
57
  if secs > 0
22
58
  secs, n = secs.divmod(count)
23
59
  "#{n.to_i}#{name}"
24
60
  end
25
- }.compact.reverse.slice(0,2).join(' ')
61
+ end.compact.reverse.slice(0,2).join(' ')
26
62
  end
27
63
 
28
- def ago start_time, end_time=nil
29
- start_time = Time.new(start_time.year, start_time.month, start_time.day) if start_time.class == Date
30
-
31
- end_time ||= Time.now
32
- time_diff = end_time.to_i - start_time.to_i
33
-
34
- in_past = time_diff > 0 ? true : false
35
- time_diff = time_diff.abs
36
-
37
- d_minutes = (time_diff / 60).round rescue 0
38
- d_hours = (time_diff / (60 * 60)).round rescue 0
39
- d_days = (time_diff / (60*60 * 24)).round rescue 0
40
- d_months = (time_diff / (60*60*24 * 30)).round rescue 0
41
- d_years = (time_diff / (60*60*24*30 * 12)).round rescue 0
42
-
43
- return (in_past ? 'few sec ago' : 'in few seconds') if time_diff < 10
44
- return (in_past ? 'less than min ago' : 'in less then a minute') if time_diff < 60
45
-
46
- template = in_past ? '%s ago' : 'in %s'
47
-
48
- return template % d_minutes.pluralize('min') if d_minutes < 60
49
- return template % d_hours.pluralize('hour') if d_hours < 24
50
- return template % d_days.pluralize('day') if d_days < 31
51
- return template % d_months.pluralize('month') if d_months < 12
52
- return template % d_years.pluralize('year')
64
+ # How long ago?
65
+ def ago start_time, end_time = nil
66
+ start = Time.parse start_time.to_s if [String, Date].include?(start_time.class)
67
+ TimeDifference.new(start || start_time, end_time, start_time.class).humanize
53
68
  end
54
69
 
55
70
  def monotonic
@@ -59,7 +74,7 @@ class Time
59
74
  # Generates a Time object from the given value.
60
75
  # Used by #expires and #last_modified.
61
76
  # extracted from Sinatra
62
- def for(value)
77
+ def for value
63
78
  if value.is_a? Numeric
64
79
  Time.at value
65
80
  elsif value.respond_to? :to_s
@@ -67,8 +82,6 @@ class Time
67
82
  else
68
83
  value.to_time
69
84
  end
70
- rescue ArgumentError => boom
71
- raise boom
72
85
  rescue Exception
73
86
  raise ArgumentError, "unable to convert #{value.inspect} to a Time object"
74
87
  end
@@ -78,3 +91,12 @@ end
78
91
  class DateTime
79
92
  include TimeOptions
80
93
  end
94
+
95
+ class Date
96
+ include TimeOptions
97
+
98
+ def to_i
99
+ Time.parse(to_s).to_i
100
+ end
101
+ end
102
+
data/tasks/loader.rb CHANGED
@@ -1,10 +1,17 @@
1
+ require 'whirly'
2
+
3
+ def invoke task, *args
4
+ puts task.light_black
5
+ Rake::Task[task].invoke(*args)
6
+ end
7
+
1
8
  def run what
2
9
  puts what.yellow
3
10
  system what
4
11
  end
5
12
 
6
13
  def die what
7
- puts '%s (%s)' % [what.red. caller[0]]
14
+ puts '%s (%s)' % [what.red, caller[0]]
8
15
  exit
9
16
  end
10
17
 
@@ -23,27 +30,33 @@ end
23
30
  ###
24
31
 
25
32
  task :env do
26
- require './config/application'
33
+ require './config/env'
34
+ end
35
+
36
+ task :app do
37
+ require './config/app'
27
38
  end
28
39
 
29
40
  task :default do
30
- puts '"rake -T" to show all tasks'
41
+ require 'lux-fw'
42
+ system Lux.fw_root.join('bin/lux').to_s
31
43
  end
32
44
 
33
45
  ###
34
46
 
35
47
  require 'bundler/setup'
36
- require 'dotenv'
37
48
 
38
- Dotenv.load
39
49
  Bundler.require :default, ENV.fetch('RACK_ENV')
40
50
 
41
51
  tasks = []
42
52
  tasks += Dir['%s/tasks/*.rake' % Lux.fw_root]
43
53
  tasks += Dir['./lib/**/*.rake']
44
54
 
45
- for dir in Lux.plugin.loaded.map(&:folder)
55
+ for dir in Lux.plugin.folders
46
56
  tasks += Dir['%s/**/*.rake' % dir]
47
57
  end
48
58
 
49
- tasks.each { |file| eval File.read file }
59
+ tasks.each do |file|
60
+ load file
61
+ end
62
+