odania 0.1.0 → 0.2.0

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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → MIT-LICENSE} +1 -3
  3. data/README.md +3 -3
  4. data/Rakefile +33 -3
  5. data/app/assets/config/odania_manifest.js +0 -0
  6. data/app/assets/javascripts/application.js +13 -0
  7. data/app/assets/javascripts/textAngular.js +15 -0
  8. data/app/assets/javascripts/textAngular/textAngular-rangy.min.js +478 -0
  9. data/app/assets/javascripts/textAngular/textAngular-sanitize.min.js +322 -0
  10. data/app/assets/javascripts/textAngular/textAngular.min.js +1481 -0
  11. data/app/assets/stylesheets/scaffold.css +80 -0
  12. data/app/assets/stylesheets/textAngular/application.css +15 -0
  13. data/app/assets/stylesheets/textAngular/textAngular.css +204 -0
  14. data/app/controllers/admin/home_controller.rb +2 -0
  15. data/app/controllers/admin/languages_controller.rb +74 -0
  16. data/app/controllers/admin_controller.rb +4 -0
  17. data/app/controllers/application_controller.rb +3 -0
  18. data/app/controllers/categories_controller.rb +34 -0
  19. data/app/controllers/home_controller.rb +11 -0
  20. data/app/controllers/protected/home_controller.rb +2 -0
  21. data/app/controllers/protected_controller.rb +22 -0
  22. data/app/controllers/registration_controller.rb +12 -0
  23. data/app/helpers/standard_form_builder.rb +71 -0
  24. data/app/helpers/standard_form_helper.rb +13 -0
  25. data/app/models/admin.rb +37 -0
  26. data/app/models/language.rb +5 -0
  27. data/app/models/user.rb +47 -0
  28. data/app/views/admin/home/index.html.erb +1 -0
  29. data/app/views/admin/languages/_form.html.erb +16 -0
  30. data/app/views/admin/languages/_language.json.jbuilder +2 -0
  31. data/app/views/admin/languages/edit.html.erb +6 -0
  32. data/app/views/admin/languages/index.html.erb +27 -0
  33. data/app/views/admin/languages/index.json.jbuilder +1 -0
  34. data/app/views/admin/languages/new.html.erb +5 -0
  35. data/app/views/admin/languages/show.html.erb +9 -0
  36. data/app/views/admin/languages/show.json.jbuilder +1 -0
  37. data/app/views/categories/index.html.erb +9 -0
  38. data/app/views/categories/show.html.erb +16 -0
  39. data/app/views/devise/confirmations/new.html.erb +11 -0
  40. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  41. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  42. data/app/views/devise/mailer/password_change.html.erb +4 -0
  43. data/app/views/devise/mailer/reset_password_instructions.html.erb +9 -0
  44. data/app/views/devise/mailer/unlock_instructions.html.erb +8 -0
  45. data/app/views/devise/passwords/edit.html.erb +13 -0
  46. data/app/views/devise/passwords/new.html.erb +11 -0
  47. data/app/views/devise/registrations/edit.html.erb +39 -0
  48. data/app/views/devise/registrations/new.html.erb +15 -0
  49. data/app/views/devise/sessions/new.html.erb +14 -0
  50. data/app/views/devise/shared/_links.html.erb +25 -0
  51. data/app/views/devise/unlocks/new.html.erb +11 -0
  52. data/app/views/home/index.html.erb +11 -0
  53. data/app/views/languages/_form.html.erb +20 -0
  54. data/app/views/languages/edit.html.erb +6 -0
  55. data/app/views/languages/index.html.erb +27 -0
  56. data/app/views/languages/new.html.erb +5 -0
  57. data/app/views/languages/show.html.erb +9 -0
  58. data/app/views/protected/home/index.html.erb +1 -0
  59. data/config/initializers/elasticsearch.rb +5 -0
  60. data/config/locales/devise.en.yml +64 -0
  61. data/config/routes.rb +23 -0
  62. data/db/seeds.rb +5 -0
  63. data/lib/odania.rb +7 -56
  64. data/lib/odania/engine.rb +14 -0
  65. data/lib/odania/version.rb +1 -1
  66. data/lib/tasks/odania_tasks.rake +4 -0
  67. data/lib/templates/erb/scaffold/_form.html.erb +27 -0
  68. data/lib/templates/erb/scaffold/edit.html.erb +6 -0
  69. data/lib/templates/erb/scaffold/index.html.erb +31 -0
  70. data/lib/templates/erb/scaffold/new.html.erb +5 -0
  71. data/lib/templates/erb/scaffold/show.html.erb +11 -0
  72. metadata +129 -84
  73. data/.codeclimate.yml +0 -30
  74. data/.gitignore +0 -17
  75. data/.rspec +0 -2
  76. data/.rubocop.yml +0 -1156
  77. data/.travis.yml +0 -20
  78. data/Gemfile +0 -4
  79. data/Gemfile.lock +0 -113
  80. data/Guardfile +0 -31
  81. data/features/plugin.feature +0 -35
  82. data/features/step_definitions/plugin_steps.rb +0 -75
  83. data/features/support/env.rb +0 -1
  84. data/lib/odania/config.rb +0 -17
  85. data/lib/odania/config/backend.rb +0 -31
  86. data/lib/odania/config/backend_group.rb +0 -43
  87. data/lib/odania/config/domain.rb +0 -59
  88. data/lib/odania/config/duplicates.rb +0 -28
  89. data/lib/odania/config/global_config.rb +0 -210
  90. data/lib/odania/config/layout.rb +0 -30
  91. data/lib/odania/config/page.rb +0 -29
  92. data/lib/odania/config/page_base.rb +0 -47
  93. data/lib/odania/config/plugin_config.rb +0 -58
  94. data/lib/odania/config/style.rb +0 -36
  95. data/lib/odania/config/sub_domain.rb +0 -113
  96. data/lib/odania/config/subdomain_config.rb +0 -124
  97. data/lib/odania/consul.rb +0 -138
  98. data/lib/odania/plugin.rb +0 -103
  99. data/odania.gemspec +0 -34
  100. data/spec/fixtures/global_config.json +0 -135
  101. data/spec/fixtures/plugin_config_1.json +0 -102
  102. data/spec/lib/odania/config/global_config_spec.rb +0 -69
  103. data/spec/lib/odania/config/plugin_config_spec.rb +0 -31
  104. data/spec/lib/odania/plugin_spec.rb +0 -25
  105. data/spec/lib/odania_spec.rb +0 -10
  106. data/spec/spec_helper.rb +0 -19
  107. data/spec/support/consul_mock.rb +0 -123
  108. data/tasks/odania.rake +0 -8
  109. data/tasks/rspec.rake +0 -7
@@ -1,124 +0,0 @@
1
- module Odania
2
- module Config
3
- class SubdomainConfig
4
-
5
- def initialize(global_config, domain, subdomain)
6
- @global_config = global_config
7
- @domain = domain
8
- @subdomain = subdomain
9
- end
10
-
11
- def generate
12
- @layout = get_layout_name
13
- config = {
14
- domain: @domain,
15
- subdomain: @subdomain,
16
- full_domain: "#{@subdomain}.#{@domain}",
17
- layout: @layout,
18
- config: generate_merged_config,
19
- partials: generate_merged_partials
20
- }
21
-
22
- layout_config = get_layout_config @layout
23
- layout_config.delete('assets')
24
- config[:styles] = layout_config['config']['styles']
25
-
26
- if $debug
27
- $logger.debug 'Generated config:'
28
- $logger.debug JSON.pretty_generate(config)
29
- end
30
-
31
- config
32
- end
33
-
34
- private
35
-
36
- def get_layout_name
37
- # subdomain specific layouts
38
- result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'config', 'layout']
39
- return result unless result.nil?
40
-
41
- # domain specific layouts
42
- result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'config', 'layout']
43
- return result unless result.nil?
44
-
45
- # general layouts
46
- result = retrieve_hash_path @global_config, %w(domains _general _general config layout)
47
- return result unless result.nil?
48
-
49
- # general layouts
50
- result = retrieve_hash_path @global_config, %w(config layout)
51
- return result unless result.nil?
52
-
53
- 'simple'
54
- end
55
-
56
- def get_layout_config(layout)
57
- # subdomain specific layouts
58
- result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'layouts', layout]
59
- return result unless result.nil?
60
-
61
- # domain specific layouts
62
- result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'layouts', layout]
63
- return result unless result.nil?
64
-
65
- # general layouts
66
- result = retrieve_hash_path @global_config, ['domains', '_general', '_general', 'layouts', layout]
67
- return result unless result.nil?
68
-
69
- {}
70
- end
71
-
72
- def generate_merged_config
73
- config = retrieve_hash_path @global_config, %w(domains _general _general config)
74
- config = {} if config.nil?
75
-
76
- # domain specific layouts
77
- result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'config']
78
- config.deep_merge!(result) unless result.nil?
79
-
80
- # subdomain specific layouts
81
- result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'config']
82
- config.deep_merge!(result) unless result.nil?
83
-
84
- config
85
- end
86
-
87
- def generate_merged_partials
88
- partials = retrieve_hash_path @global_config, %w(partials _general _general default)
89
- partials = {} if partials.nil?
90
-
91
- # general specific layout
92
- result = retrieve_hash_path @global_config, ['partials', '_general', '_general', 'layouts', @layout]
93
- partials.deep_merge!(result) unless result.nil?
94
-
95
- # domain specific
96
- result = retrieve_hash_path @global_config, ['partials', @domain, '_general', 'default']
97
- partials.deep_merge!(result) unless result.nil?
98
-
99
- # domain specific layout
100
- result = retrieve_hash_path @global_config, ['partials', @domain, '_general', 'layouts', @layout]
101
- partials.deep_merge!(result) unless result.nil?
102
-
103
- # subdomain
104
- result = retrieve_hash_path @global_config, ['partials', @domain, @subdomain, 'default']
105
- partials.deep_merge!(result) unless result.nil?
106
-
107
- # subdomain specific layout
108
- result = retrieve_hash_path @global_config, ['partials', @domain, @subdomain, 'layouts', @layout]
109
- partials.deep_merge!(result) unless result.nil?
110
-
111
- partials
112
- end
113
-
114
- def retrieve_hash_path(hash, path)
115
- key = path.shift
116
-
117
- return nil until hash.has_key? key
118
- return hash[key].clone if path.empty?
119
- retrieve_hash_path hash[key], path
120
- end
121
-
122
- end
123
- end
124
- end
@@ -1,138 +0,0 @@
1
- module Odania
2
- class Consul
3
- attr_reader :service, :config, :event, :health
4
-
5
- def initialize(consul_url)
6
- consul_url = ENV['CONSUL_ADDR'] if consul_url.nil?
7
- consul_url = 'http://consul:8500' if consul_url.nil?
8
- $logger.info "Consul URL: #{consul_url}" if $debug
9
- Diplomat.configure do |config|
10
- # Set up a custom Consul URL
11
- config.url = consul_url
12
- end
13
-
14
- @service = Service.new
15
- @config = Config.new
16
- @event = Event.new
17
- @health = Health.new
18
- end
19
-
20
- class Config
21
- def get(path)
22
- begin
23
- JSON.parse Diplomat::Kv.get path
24
- rescue Diplomat::KeyNotFound
25
- nil
26
- end
27
- end
28
-
29
- def get_all(path)
30
- retrieve_value path
31
- end
32
-
33
- def set(key, value)
34
- Diplomat::Kv.put(key, JSON.dump(value))
35
- end
36
-
37
- def delete(key)
38
- Diplomat::Kv.delete(key)
39
- end
40
-
41
- protected
42
-
43
- def retrieve_value(plugin_path)
44
- begin
45
- result = {}
46
- Diplomat::Kv.get(plugin_path, :recurse => true).each do |data|
47
- result[data[:key]] = JSON.parse data[:value]
48
- end
49
- result
50
- rescue Diplomat::KeyNotFound
51
- {}
52
- end
53
- end
54
- end
55
-
56
- class Service
57
- def get_all
58
- services = {}
59
- Diplomat::Service.get_all.each_pair do |key, _value|
60
- services[key.to_s] = get_all_for(key)
61
- end
62
- $logger.info "SERVICES: #{JSON.pretty_generate services}" if $debug
63
- services
64
- end
65
-
66
- def get_all_for(plugin_name)
67
- begin
68
- instances = get(plugin_name, :all)
69
- rescue
70
- instances = []
71
- end
72
- instances.is_a?(Array) ? instances : [instances]
73
- end
74
-
75
- # TODO Is there an easier way to get the first service tagges with "core-backend"?
76
- def get_core_service
77
- core_backends = []
78
- Diplomat::Service.get_all.each_pair do |key, tags|
79
- core_backends << key if tags.include? 'core-backend'
80
- end
81
-
82
- get(core_backends.shuffle.first)
83
- end
84
-
85
- def get(key, scope=:first)
86
- Diplomat::Service.get(key, scope)
87
- end
88
-
89
- def register(consul_config)
90
- if Diplomat::Service.register consul_config
91
- $logger.info 'Service registered' if $debug
92
- else
93
- $logger.error 'Error registering service'
94
- end
95
- end
96
-
97
- def deregister(name)
98
- Diplomat::Service.deregister name
99
- end
100
-
101
- def build_config(plugin_name, plugin_instance_name, ip, tags=[], port=80)
102
- {
103
- 'id' => plugin_instance_name,
104
- 'name' => plugin_name,
105
- 'tags' => tags,
106
- 'address' => ip,
107
- 'port' => port,
108
- 'token' => plugin_instance_name,
109
- 'checks' => [
110
- {
111
- 'id' => plugin_name,
112
- 'name' => "HTTP on port #{port}",
113
- 'http' => "http://#{ip}:#{port}/health",
114
- 'interval' => '10s',
115
- 'timeout' => '1s'
116
- }
117
- ]
118
- }
119
- end
120
- end
121
-
122
- class Event
123
- def fire(key, value)
124
- Diplomat::Event.fire key, value
125
- end
126
- end
127
-
128
- class Health
129
- def state(state=:any)
130
- Diplomat::Health.state(state)
131
- end
132
-
133
- def service(name)
134
- Diplomat::Health.service(name)
135
- end
136
- end
137
- end
138
- end
@@ -1,103 +0,0 @@
1
- module Odania
2
- class Plugin
3
- INSTANCE_FILES_PATH = '/tmp/plugin_instance_name_'
4
-
5
- def initialize(consul)
6
- @consul = consul
7
- @plugin_config = Config::GlobalConfig.new
8
- end
9
-
10
- def register(plugin_instance_name, plugin_config)
11
- plugin_name = plugin_config['plugin-config']['name']
12
-
13
- # Write configuration of the plugin
14
- @consul.config.set(get_plugin_config_path_for(plugin_name), plugin_config)
15
-
16
- # Register service
17
- consul_config = @consul.service.build_config(plugin_name, plugin_instance_name, plugin_config['plugin-config']['ip'], plugin_config['plugin-config']['tags'], plugin_config['plugin-config']['port'])
18
- @consul.service.register(consul_config)
19
-
20
- # Fire event
21
- @consul.event.fire 'service-registered', "#{plugin_name}|#{plugin_instance_name}"
22
- "#{plugin_name}|#{plugin_instance_name}"
23
- end
24
-
25
- def deregister(plugin_instance_name)
26
- @consul.service.deregister(plugin_instance_name)
27
- end
28
-
29
- def get_all
30
- @consul.service.get_all
31
- end
32
-
33
- def config_for(plugin_name)
34
- @consul.config.get get_plugin_config_path_for(plugin_name)
35
- end
36
-
37
- # Generate a unique number for this instance of the plugin
38
- def get_plugin_instance_name(plugin_name)
39
- "#{plugin_name}_#{Socket.gethostname.gsub(/[^0-9a-zA-Z_]/, '_')}"
40
- end
41
-
42
- def plugin_config
43
- @plugin_config
44
- end
45
-
46
- def set_global_config(config)
47
- @consul.config.set get_global_plugin_config_path, config
48
- end
49
-
50
- def get_global_config
51
- @consul.config.get get_global_plugin_config_path
52
- end
53
-
54
- def set_subdomain_config(full_domain, config)
55
- @consul.config.set get_subdomain_config_path(full_domain), config
56
- end
57
-
58
- def get_subdomain_config(full_domain)
59
- @consul.config.get get_subdomain_config_path(full_domain)
60
- end
61
-
62
- def set_valid_domain_config(config)
63
- @consul.config.set get_valid_domain_config_path, config
64
- end
65
-
66
- def get_valid_domain_config
67
- @consul.config.get get_valid_domain_config_path
68
- end
69
-
70
- def get_domain_config_for(domain, global_config=nil)
71
- global_config = get_global_config if global_config.nil?
72
-
73
- return global_config['domains'][domain], domain unless global_config['domains'][domain].nil?
74
- return false, nil
75
- end
76
-
77
- def health
78
- @consul.health
79
- end
80
-
81
- private
82
-
83
- def get_subdomain_config_path(full_domain)
84
- "subdomain_config/#{full_domain}"
85
- end
86
-
87
- def get_valid_domain_config_path
88
- 'valid_domain_config'
89
- end
90
-
91
- def get_global_plugin_config_path
92
- 'global_plugins_config'
93
- end
94
-
95
- def get_plugin_config_path
96
- 'plugins_config'
97
- end
98
-
99
- def get_plugin_config_path_for(plugin_name)
100
- "#{get_plugin_config_path}/#{plugin_name}"
101
- end
102
- end
103
- end
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'odania/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'odania'
8
- spec.version = Odania::VERSION
9
- spec.authors = ['Mike Petersen']
10
- spec.email = ['mike@odania-it.de']
11
- spec.summary = %q{Helper for the odania portal}
12
- spec.description = %q{Helper for the odania portal}
13
- spec.homepage = 'http://www.odania.com'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.5'
22
- spec.add_development_dependency 'rake', '< 11.0'
23
- spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'cucumber'
25
- spec.add_development_dependency 'guard'
26
- spec.add_development_dependency 'guard-rspec'
27
- spec.add_development_dependency 'codeclimate-test-reporter'
28
- spec.add_development_dependency 'hashdiff'
29
-
30
- spec.add_dependency 'diplomat'
31
- spec.add_dependency 'erubis'
32
- spec.add_dependency 'public_suffix'
33
- spec.add_dependency 'deep_merge'
34
- end
@@ -1,135 +0,0 @@
1
- {
2
- "config": {
3
- "title": "This is my awesome title",
4
- "default_backend_groups": [
5
- "odania-static"
6
- ]
7
- },
8
- "plugin-config": {
9
- "odania-static": {
10
- "name": "odania-core",
11
- "default": true,
12
- "author": [
13
- "Mike Petersen <mike@odania-it.com>"
14
- ],
15
- "url": "http://www.odania.com",
16
- "sites": [
17
- "www.domain.de"
18
- ]
19
- }
20
- },
21
- "valid_domains": {
22
- "example.com": [
23
- "www"
24
- ]
25
- },
26
- "default_domains": {
27
- "example.com": [
28
- "www"
29
- ]
30
- },
31
- "domains": {
32
- "_general": {
33
- "_general": {
34
- "config": {
35
- },
36
- "redirects": {
37
- "odania.com$": "www.odania.com",
38
- "odania.de$": "www.odania.com/de"
39
- },
40
- "assets": {
41
- },
42
- "layouts": {
43
- }
44
- }
45
- },
46
- "example.com": {
47
- "_general": {
48
- "config": {
49
- },
50
- "web": {
51
- "/imprint": {
52
- "group_name": "static-content",
53
- "plugin_url": "/contents/my-awesome-imprint"
54
- }
55
- },
56
- "assets": {},
57
- "layouts": {}
58
- },
59
- "www": {
60
- "dynamic": {
61
- "/de/openhab/2015-09-17-testing-openhab2": {
62
- "group_name": "static-content",
63
- "plugin_url": "/contents/www.example.com/web/de/openhab/2015-09-17-testing-openhab2.html",
64
- "cacheable": true,
65
- "expires": 60
66
- },
67
- "/de": {
68
- "group_name": "static-content",
69
- "plugin_url": "/contents/www.example.com/web/de/index.html"
70
- }
71
- },
72
- "direct": {
73
- "/favicon.ico": {
74
- "group_name": "odania-core",
75
- "plugin_url": "/admin/favicon.ico"
76
- },
77
- "/assets/admin/js/admin.js": {
78
- "group_name": "odania-core",
79
- "plugin_url": "/assets/admin/js/admin.js"
80
- },
81
- "hamster.jpeg": {
82
- "group_name": "static-content",
83
- "plugin_url": "/contents/www.example.com/assets/hamster.jpeg"
84
- },
85
- "imprint": {
86
- "group_name": "static-content",
87
- "plugin_url": "/contents/my-special-imprint"
88
- }
89
- },
90
- "layouts": {
91
- "main": {
92
- "config": {
93
- "styles": {
94
- "_general": {
95
- "entry_point": "application.html.erb"
96
- },
97
- "left_menu": {
98
- "entry_point": "application.html.erb"
99
- }
100
- }
101
- },
102
- "assets": {
103
- "layouts/mac-beath/img/favicon/favicon.png": {
104
- "group_name": "static-content",
105
- "plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
106
- "cacheable": true,
107
- "expires": 60
108
- },
109
- "layouts/mac-beath/img/photos/t12.jpg": {
110
- "group_name": "static-content",
111
- "plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
112
- }
113
- },
114
- "partials": {
115
- "layouts/simple/application_part1.html": {
116
- "group_name": "static-content",
117
- "plugin_url": "layouts/simple/application_part1.html.erb",
118
- "cacheable": true,
119
- "expires": 60
120
- }
121
- }
122
- }
123
- }
124
- }
125
- }
126
- },
127
- "partials": {
128
- "example.com": {
129
- "www": {
130
- "tracking": "partials/tracking.html",
131
- "footer": "partials/footer.html"
132
- }
133
- }
134
- }
135
- }