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,5 +0,0 @@
1
- class MiniAssets::Base::StyleSheet < MiniAssets::Base
2
- def asset_class
3
- MiniAssets::Asset::Css
4
- end
5
- end
@@ -1,18 +0,0 @@
1
- class MiniAssets::Manifest
2
- def initialize
3
- @manifest = MiniAssets::Opts.public_root.join('./manifest.json')
4
- @manifest.write '{"files":{}}' unless @manifest.exist?
5
- @json = JSON.load @manifest.read
6
- end
7
-
8
- def add name, target
9
- return if @json['files'][name] == target
10
-
11
- @json['files'][name] = target
12
- @manifest.write JSON.pretty_generate(@json)
13
- end
14
-
15
- def get file
16
- @json['files'][file]
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- module MiniAssets::Opts
2
- extend self
3
-
4
- [:app, :tmp, :public].each do |folder|
5
- name = '%s_root' % folder
6
- path = Pathname.new './%s/assets' % folder
7
-
8
- Dir.mkdir(path) unless path.exist?
9
-
10
- define_method(name) { path }
11
- end
12
-
13
- def production?
14
- ENV['RACK_ENV'] == 'production'
15
- end
16
- end
@@ -1,74 +0,0 @@
1
- # app/assets/main/js.assets
2
- # ---
3
- # add 'js_vendor/*'
4
- # add 'js/*'
5
- # add 'index.coffee'
6
-
7
- # render production asset
8
- # ---
9
- # MiniAssets.call('js/main/index.coffee').render
10
-
11
- # render single asset
12
- # ---
13
- # asset = MiniAssets::Asset.call(path)
14
- # asset.content_type
15
- # asset.render
16
-
17
- require 'json'
18
- require 'pathname'
19
- require 'awesome_print'
20
- require 'open3'
21
- require 'digest'
22
-
23
- # calls base classes
24
- class MiniAssets
25
- attr_reader :files
26
-
27
- def initialize source
28
- @files = []
29
- @fsource = source
30
-
31
- @source = MiniAssets::Opts.app_root.join source
32
-
33
- # fill @files, via dsl or direct
34
- if source.split('.').last == 'assets'
35
- # add './js/*'
36
- eval @source.read
37
- else
38
- @source.read.split($/).each do |line|
39
- test = line.split(/^[\/#]+=\s*req\w*\s+/)
40
- add test[1] if test[1]
41
- end
42
-
43
- @files.push source
44
- end
45
-
46
- # figure out type unless defined
47
- unless @type
48
- ext = @files.first.split('.').last
49
- @type = ['css', 'sass', 'scss'].include?(ext) ? :css : :js
50
- end
51
- end
52
-
53
- def type name
54
- @type = name
55
- end
56
-
57
- def add files
58
- files = files.sub(/^\.\//,'')
59
- files += '/*' unless files.include?('*')
60
- path = @source.dirname.join files
61
-
62
- @files += Dir[path].sort.map{ |f| f.split(MiniAssets::Opts.app_root.to_s+'/', 2).last }
63
- end
64
-
65
- # render production file
66
- def render
67
- # load right base class
68
- base_class = @type == :css ?
69
- MiniAssets::Base::StyleSheet
70
- : MiniAssets::Base::JavaScript
71
-
72
- base_class.new(@fsource, @files).render
73
- end
74
- end
@@ -1,35 +0,0 @@
1
- # https://developers.facebook.com
2
- # https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
3
-
4
- class LuxOauth::Facebook < LuxOauth
5
- def login
6
- 'https://www.facebook.com/v2.8/dialog/oauth?scope=email&client_id=%s&redirect_uri=%s' % [@key, CGI::escape(redirect_url)]
7
- end
8
-
9
- def format_response opts
10
- {
11
- email: opts['email'],
12
- avatar: '//graph.facebook.com/%s/picture?type=large' % opts['id'],
13
- name: opts['name']
14
- }
15
- end
16
-
17
- def callback(session_code)
18
- result = RestClient.post('https://graph.facebook.com/v2.8/oauth/access_token', {
19
- redirect_uri: redirect_url,
20
- client_id: @key,
21
- client_secret: @secret,
22
- code: session_code
23
- }, { :accept => :json })
24
-
25
- access_token = JSON.parse(result)['access_token']
26
-
27
- response = RestClient.get('https://graph.facebook.com/me', {
28
- :accept => :json,
29
- :params => { :access_token => access_token }
30
- })
31
-
32
- format_response JSON.parse response
33
- end
34
- end
35
-
@@ -1,37 +0,0 @@
1
- # https://github.com/github/platform-samples/tree/master/api/ruby/basics-of-authentication
2
- # https://github.com/settings/applications/404731
3
-
4
- class LuxOauth::Github < LuxOauth
5
- def login
6
- "https://github.com/login/oauth/authorize?scope=user:email&client_id=#{@key}"
7
- end
8
-
9
- def format_response opts
10
- {
11
- email: opts['email'],
12
- avatar: opts['avatar_url'],
13
- github: opts['login'],
14
- company: opts['company'],
15
- location: opts['location'],
16
- bio: opts['description'],
17
- name: opts['name']
18
- }
19
- end
20
-
21
- def callback session_code
22
- result = RestClient.post('https://github.com/login/oauth/access_token', {
23
- client_id: @key,
24
- client_secret: @secret,
25
- code: session_code
26
- }, { :accept => :json })
27
-
28
- # extract token and granted scopes
29
- access_token = JSON.parse(result)['access_token']
30
- # scopes = JSON.parse(result)['scope'].split(',')
31
-
32
- opts = JSON.parse(RestClient.get('https://api.github.com/user', {:params => {:access_token => access_token}, :accept => :json}))
33
-
34
- format_response opts
35
- end
36
- end
37
-
@@ -1,41 +0,0 @@
1
- # https://console.developers.google.com
2
- # https://developers.google.com/identity/protocols/googlescopes
3
-
4
- class LuxOauth::Google < LuxOauth
5
- def scope
6
- [
7
- 'https://www.googleapis.com/auth/userinfo.email',
8
- 'https://www.googleapis.com/auth/userinfo.profile'
9
- ]
10
- end
11
-
12
- def format_response opts
13
- {
14
- email: opts['email'],
15
- name: opts['name'],
16
- avatar: opts['picture'],
17
- locale: opts['locale'],
18
- gender: opts['gender']
19
- }
20
- end
21
-
22
- def login
23
- "https://accounts.google.com/o/oauth2/auth?client_id=#{@key}&redirect_uri=#{redirect_url}&scope=#{scope.join('%20')}&response_type=code"
24
- end
25
-
26
- def callback(session_code)
27
- result = RestClient.post('https://www.googleapis.com/oauth2/v3/token', {
28
- grant_type: 'authorization_code',
29
- client_id: @key,
30
- client_secret: @secret,
31
- code: session_code,
32
- redirect_uri: redirect_url
33
- })
34
-
35
- hash = JSON.parse(result)
36
-
37
- user = JSON.parse RestClient.get('https://www.googleapis.com/oauth2/v1/userinfo', { :params => {:access_token => hash['access_token'], :alt=>:json }})
38
-
39
- format_response user
40
- end
41
- end
@@ -1,41 +0,0 @@
1
- # https://developer.linkedin.com/docs/oauth2
2
- # https://developer.linkedin.com/docs/fields/basic-profile
3
-
4
- class LuxOauth::Linkedin < LuxOauth
5
- def scope
6
- [
7
- 'r_basicprofile',
8
- 'r_emailaddress'
9
- ]
10
- end
11
-
12
- def login
13
- "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=#{@key}&redirect_uri=#{redirect_url}&state=987654321&scope=#{scope.join('%20')}"
14
- end
15
-
16
- def format_response opts
17
- {
18
- email: opts['emailAddress'],
19
- linkedin: opts['publicProfileUrl'],
20
- description: opts['specialties'],
21
- location: opts['location'],
22
- avatar: opts['pictureUrl'],
23
- name: "#{opts['firstName']} #{opts['lastName']}"
24
- }
25
- end
26
-
27
- def callback(session_code)
28
- result = RestClient.post('https://www.linkedin.com/oauth/v2/accessToken', {
29
- grant_type: 'authorization_code',
30
- client_id: @key,
31
- client_secret: @secret,
32
- code: session_code,
33
- redirect_uri: redirect_url
34
- })
35
-
36
- access_token = JSON.parse(result)['access_token']
37
- opts = JSON.parse RestClient::Request.execute(:method=>:get, :url=>'https://api.linkedin.com/v1/people/~:(id,picture-url,first-name,last-name,email-address,public-profile-url,specialties,location)?format=json', :headers => {'Authorization'=>"Bearer #{access_token}"})
38
-
39
- format_response opts
40
- end
41
- end
@@ -1,37 +0,0 @@
1
- # https://api.stackexchange.com/docs/authentication
2
-
3
- class LuxOauth::Stackexchange < LuxOauth
4
- def login
5
- 'https://stackexchange.com/oauth?client_id=%d&redirect_uri=%s' % [ENV.fetch('STACKEXCHANGE_OAUTH_ID'), CGI::escape(redirect_url)]
6
- end
7
-
8
- def format_response
9
- {
10
- stackexchnage_user_id: opts['items'].first['user_id'],
11
- user: opts['items'].first
12
- }
13
- end
14
-
15
- def callback session_code
16
- result = RestClient.post('https://stackexchange.com/oauth/access_token', {
17
- redirect_uri: redirect_url,
18
- client_id: ENV.fetch('STACKEXCHANGE_OAUTH_ID'),
19
- client_secret: @secret,
20
- code: session_code
21
- }, { :accept => :json })
22
-
23
- access_token = result.to_s.css_to_hash['access_token']
24
-
25
- response = RestClient.get('https://api.stackexchange.com/2.2/me', {
26
- accept: :json,
27
- params: {
28
- site: 'stackoverflow',
29
- access_token: access_token,
30
- key: @key
31
- }
32
- })
33
-
34
- format_response JSON.parse response
35
- end
36
- end
37
-
@@ -1,41 +0,0 @@
1
- # https://developer.linkedin.com/docs/oauth2
2
- # https://developer.linkedin.com/docs/fields/basic-profile
3
-
4
- class LuxOauth::Twitter < LuxOauth
5
- # def scope
6
- # [
7
- # 'r_basicprofile',
8
- # 'r_emailaddress'
9
- # ]
10
- # end
11
-
12
- # def login
13
- # 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % @key
14
- # end
15
-
16
- # def format_response opts
17
- # {
18
- # email: opts['emailAddress'],
19
- # linkedin: opts['publicProfileUrl'],
20
- # description: opts['specialties'],
21
- # location: opts['location'],
22
- # avatar: opts['pictureUrl'],
23
- # name: "#{opts['firstName']} #{opts['lastName']}"
24
- # }
25
- # end
26
-
27
- # def callback(session_code)
28
- # result = RestClient.post('https://www.linkedin.com/oauth/v2/accessToken', {
29
- # grant_type: 'authorization_code',
30
- # client_id: @key,
31
- # client_secret: @secret,
32
- # code: session_code,
33
- # redirect_uri: redirect_url
34
- # })
35
-
36
- # access_token = JSON.parse(result)['access_token']
37
- # opts = JSON.parse RestClient::Request.execute(:method=>:get, :url=>'https://api.linkedin.com/v1/people/~:(id,picture-url,first-name,last-name,email-address,public-profile-url,specialties,location)?format=json', :headers => {'Authorization'=>"Bearer #{access_token}"})
38
-
39
- # format_response opts
40
- # end
41
- end
@@ -1,46 +0,0 @@
1
- class LuxOauth
2
- @@keys = {}
3
- @@local_path = 'callback'
4
-
5
- class << self
6
- # LuxOauth.register :google, ENV.fetch('GOOGLE_OAUTH_KEY'), ENV.fetch('GOOGLE_OAUTH_SECRET')
7
- def register schema, client_key=nil, client_secret=nil
8
- client_key ||= ENV["#{schema.to_s.upcase}_OAUTH_KEY"] || raise('Oauth :%s key not defined' % schema)
9
- client_secret ||= ENV["#{schema.to_s.upcase}_OAUTH_SECRET"] || raise('Oauth :%s secret not defined' % schema)
10
-
11
- @@keys[schema] = {}
12
- @@keys[schema][:key] = client_key
13
- @@keys[schema][:secret] = client_secret
14
- end
15
-
16
- def local_path= value
17
- @@local_path = value
18
- end
19
-
20
- def get scheme, full_host
21
- "LuxOauth::#{scheme.to_s.classify}".constantize.new full_host
22
- end
23
- end
24
-
25
- ###
26
-
27
- def initialize full_host
28
- schema = self.class.to_s.split('::').last.downcase
29
-
30
- raise ArgumentError, 'Host is invalid: %s' % full_host.to_s unless full_host.to_s =~ /^https?:/
31
- @schema = schema.to_sym
32
-
33
- raise "Oauth config :#{schema} is not registred" unless @@keys[@schema]
34
- raise "Oauth config :#{schema} is missing key" unless @@keys[@schema][:key]
35
- raise "Oauth config :#{schema} is missing secret" unless @@keys[@schema][:secret]
36
-
37
- @full_host = full_host
38
- @key = @@keys[@schema][:key]
39
- @secret = @@keys[@schema][:secret]
40
- end
41
-
42
- def redirect_url
43
- [@full_host, @@local_path, @schema].join('/')
44
- end
45
-
46
- end