glib-web 0.3.6 → 0.3.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cce5921c4af9524cc6878c67521f8430dfac0e019beb296326b8ee0c866a6cd8
4
- data.tar.gz: ab5e417f1cdef79b23c282479f15d50fd708589a01758eea0c3c0327e096bc15
3
+ metadata.gz: a318fa9377a19b89642be242b820ee9e2670f0bff29e6a346806b76f8906b16f
4
+ data.tar.gz: 8797bfd1ab030db735284adcf8c9ddf86441dbd0b189273ca8e7cd0f4d8cdd57
5
5
  SHA512:
6
- metadata.gz: 567b6a172d515122068d7b3c71c4145417c8dda212ae4c5c8a195b150dc8e80990f218539aaf99df1f9e1d1cfb13f718030447e5983c5eca7cf7e2e3392657ab
7
- data.tar.gz: 5d6eca808238984d03e4b242e2da9a02b090e9983a240e8d30b06282da3b961c6eed595b52e760a9cff06061526f3f207e53920515eefd3d165680097d57e538
6
+ metadata.gz: dfe9421dcc2b4897220d5a7cea9ef1e258bbfbd9a4667b5a5c40e0a39876f7cc666b40b4b0f0efe4d3efb8020d888542d1757d625cf83b3cabcb53a6a27787e6
7
+ data.tar.gz: 3f6abcd4c53f2abd78b7a96c539c59dec16559147502b28ba3d4fb80f2bdea756a3e51f887082429043d8322bba4d75bb318fcaef27a1ffac121708aa4012d6e
@@ -14,7 +14,7 @@ module Concerns::Application::Json::Ui
14
14
  end
15
15
 
16
16
  # Override
17
- def form_authenticity_token
17
+ def form_authenticity_token(*args)
18
18
  Rails.env.test? ? 'test_token' : super
19
19
  end
20
20
 
@@ -0,0 +1,12 @@
1
+ module Glib
2
+ module DynamicTextsHelper
3
+ def dt(key, default_value = '', scope = 'itinerarybuilder')
4
+ new_key = key
5
+ if key.starts_with?('.')
6
+ new_key = "#{controller_name}.#{action_name}#{key}"
7
+ end
8
+
9
+ Glib::Text.get_content(scope, new_key, default_value)
10
+ end
11
+ end
12
+ end
@@ -76,8 +76,6 @@ class Glib::JsonUi::ViewBuilder
76
76
  json.view 'fields/hidden-v1'
77
77
  json.name 'authenticity_token'
78
78
  json.value page.context.form_authenticity_token
79
- # Produce consistent token for predictible test results
80
- # json.value Rails.env.test? ? 'test_token' : page.context.form_authenticity_token
81
79
  end
82
80
  end
83
81
 
@@ -0,0 +1,6 @@
1
+ module Glib
2
+ class DynamicTextRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ connects_to database: { writing: :dynamic_text, reading: :dynamic_text }
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ module Glib
2
+ class Text < Glib::DynamicTextRecord
3
+ validates :scope, presence: true
4
+ validates :key, presence: true, uniqueness: { scope: :scope }
5
+ validates :content, presence: true
6
+
7
+ after_save :update_to_redis
8
+
9
+ def self.get_content(scope, key, default_value)
10
+ scope_key = "#{scope}.#{key}"
11
+
12
+ unless content = $dt_redis.get(scope_key)
13
+ if text = find_by(scope: scope, key: key)
14
+ update_content(scope_key, text.content)
15
+ content = text.content
16
+ else
17
+ create(scope: scope, key: key, content: default_value)
18
+ update_content(scope_key, default_value)
19
+ content = default_value
20
+ end
21
+ end
22
+
23
+ content
24
+ end
25
+
26
+ private
27
+ def self.update_content(scope_key, content)
28
+ $dt_redis.set(scope_key, content)
29
+ end
30
+
31
+ def update_to_redis
32
+ Glib::Text.update_content("#{scope}.#{key}", content)
33
+ end
34
+ end
35
+ end
@@ -3,7 +3,7 @@ sleep 0.5
3
3
  json.title 'Menu'
4
4
 
5
5
  json_ui_page json do |page|
6
- render "#{@path_prefix}/nav_menu", json: json, page: page, top_nav: true
6
+ render "#{@path_prefix}/nav_menu", json: json, page: page, top_nav: false
7
7
 
8
8
  page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
9
9
  scroll.label text: 'Blank page'
@@ -0,0 +1,18 @@
1
+ module Glib
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../templates', __FILE__)
5
+
6
+ class_option :redis_env_key, type: :string, default: 'DT_REDIS_URL'
7
+ class_option :database_env_key, type: :string, default: 'DT_DATABASE_URL'
8
+ class_option :app_name, type: :string, default: Rails.application.class.parent_name
9
+
10
+ def copy_initializer
11
+ template '20191017062519_create_texts.rb', 'db/dynamic_text_migrate/20191017062519_create_texts.rb'
12
+ template '20191024063257_add_scope_to_texts.rb', 'db/dynamic_text_migrate/20191024063257_add_scope_to_texts.rb'
13
+ template 'dynamic_text.rb', 'config/initializers/dynamic_text.rb'
14
+ template 'database.yml', 'config/database.yml'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTexts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :texts do |t|
4
+ t.string :key
5
+ t.text :content
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :texts, :key, unique: true
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class AddScopeToTexts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :texts, :scope, :string
4
+ remove_index :texts, :key
5
+ add_index :texts, [:scope, :key], unique: true
6
+ end
7
+ end
@@ -0,0 +1,107 @@
1
+ # PostgreSQL. Versions 9.1 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On OS X with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On OS X with MacPorts:
8
+ # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9
+ # On Windows:
10
+ # gem install pg
11
+ # Choose the win32 build.
12
+ # Install PostgreSQL and put its /bin directory on your path.
13
+ #
14
+ # Configure Using Gemfile
15
+ # gem 'pg'
16
+ #
17
+ default: &default
18
+ adapter: postgresql
19
+ encoding: unicode
20
+ # For details on connection pooling, see Rails configuration guide
21
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
22
+ pool: <%= "\<\%\= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } \%\>" %>
23
+ host: <%= "\<\%\= ENV.fetch(\"DATABASE_HOST\") {} \%\>" %>
24
+ username: <%= "\<\%\= ENV.fetch(\"DATABASE_USER\") {} \%\>" %>
25
+ password: <%= "\<\%\= ENV.fetch(\"DATABASE_PASSWORD\") {} \%\>" %>
26
+
27
+ development:
28
+ primary:
29
+ <<: *default
30
+ database: <%= "\<\%\= ENV.fetch(\"DATABASE_NAME\") { \"#{options[:app_name]}\" } + \"_development\" \%\>" %>
31
+ dynamic_text:
32
+ <<: *default
33
+ migrations_paths: db/dynamic_text_migrate
34
+ database: <%= "\<\%\= ENV.fetch(\"DT_DATABASE_NAME\") { \"DynamicText\" } + \"_development\" \%\>" %>
35
+
36
+ # The specified database role being used to connect to postgres.
37
+ # To create additional roles in postgres see `$ createuser --help`.
38
+ # When left blank, postgres will use the default role. This is
39
+ # the same name as the operating system user that initialized the database.
40
+ #username: ItineraryBuilder
41
+
42
+ # The password associated with the postgres role (username).
43
+ #password:
44
+
45
+ # Connect on a TCP socket. Omitted by default since the client uses a
46
+ # domain socket that doesn't need configuration. Windows does not have
47
+ # domain sockets, so uncomment these lines.
48
+ #host: localhost
49
+
50
+ # The TCP port the server listens on. Defaults to 5432.
51
+ # If your server runs on a different port number, change accordingly.
52
+ #port: 5432
53
+
54
+ # Schema search path. The server defaults to $user,public
55
+ #schema_search_path: myapp,sharedapp,public
56
+
57
+ # Minimum log levels, in increasing order:
58
+ # debug5, debug4, debug3, debug2, debug1,
59
+ # log, notice, warning, error, fatal, and panic
60
+ # Defaults to warning.
61
+ #min_messages: notice
62
+
63
+ # Warning: The database defined as "test" will be erased and
64
+ # re-generated from your development database when you run "rake".
65
+ # Do not set this db to the same as development or production.
66
+ test:
67
+ primary:
68
+ <<: *default
69
+ database: <%= "\<\%\= ENV.fetch(\"DATABASE_NAME\") { \"#{options[:app_name]}\" } + \"_test\" \%\>" %>
70
+ dynamic_text:
71
+ <<: *default
72
+ migrations_paths: db/dynamic_text_migrate
73
+ database: <%= "\<\%\= ENV.fetch(\"DT_DATABASE_NAME\") { \"DynamicText\" } + \"_test\" \%\>" %>
74
+
75
+ # As with config/secrets.yml, you never want to store sensitive information,
76
+ # like your database password, in your source code. If your source code is
77
+ # ever seen by anyone, they now have access to your database.
78
+ #
79
+ # Instead, provide the password as a unix environment variable when you boot
80
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
81
+ # for a full rundown on how to provide these environment variables in a
82
+ # production deployment.
83
+ #
84
+ # On Heroku and other platform providers, you may have a full connection URL
85
+ # available as an environment variable. For example:
86
+ #
87
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
88
+ #
89
+ # You can use this database configuration with:
90
+ #
91
+ # production:
92
+ # url: <%= "\<\%\= ENV[\'DATABASE_URL\'] \%\>" %>
93
+ #
94
+
95
+ production_default: &production_default
96
+ adapter: postgresql
97
+ encoding: unicode
98
+ pool: <%= "\<\%\= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } \%\>" %>
99
+
100
+ production:
101
+ primary:
102
+ <<: *production_default
103
+ url: <%= "\<\%\= ENV[\"DATABASE_URL\"] \%\>" %>
104
+ dynamic_text:
105
+ <<: *production_default
106
+ migrations_paths: db/dynamic_text_migrate
107
+ url: <%= "\<\%\= ENV[\"#{options[:database_env_key]}\"] \%\>" %>
@@ -0,0 +1,2 @@
1
+ dt_redis_url = ENV.fetch('<%= options[:redis_env_key] %>', 'redis://localhost:6379')
2
+ $dt_redis = Redis.new(url: dt_redis_url)
@@ -20,39 +20,38 @@ module Glib
20
20
  end
21
21
 
22
22
  def get(url, controller)
23
-
24
- http_header = {
25
- 'Client-DeviceOS' => user[:device],
26
- 'Client-Version' => user[:version],
27
- }
28
-
29
- # Allow repeating urls because excluding them makes the test results really hard to analyze.
30
- # if history.include?(url)
31
-
32
- if url.blank?
33
- nil
34
- else
35
- @context.assert_match URI_REGEXP, url
36
- history << url
37
- @context.get url, params: {}, headers: http_header
38
- response = @context.response
39
- JsonCrawler::Router.log controller, url, response
40
- if (code = response.code.to_i) == 302
41
- redirect_uri = URI(response.headers['Location'])
42
- redirect_uri.query = [redirect_uri.query, "format=json"].compact.join('&')
43
- return get redirect_uri.to_s, controller
44
- else
45
- response_times << response.headers['X-Runtime'].to_f
46
- @context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
47
-
48
- if response.media_type == 'application/json'
49
- JSON.parse(response.body)
50
- else
51
- nil
52
- end
53
- end
54
- end
55
-
23
+ fetch(:get, url, controller)
24
+
25
+ # http_header = {
26
+ # 'Client-DeviceOS' => user[:device],
27
+ # 'Client-Version' => user[:version],
28
+ # }
29
+
30
+ # # Allow repeating urls because excluding them makes the test results really hard to analyze.
31
+ # # if history.include?(url)
32
+
33
+ # if url.blank?
34
+ # nil
35
+ # else
36
+ # @context.assert_match URI_REGEXP, url
37
+ # history << url
38
+ # @context.get url, params: {}, headers: http_header
39
+ # response = @context.response
40
+ # JsonCrawler::Router.log controller, url, response
41
+ # if (code = response.code.to_i) == 302
42
+ # redirect_uri = URI(response.headers['Location'])
43
+ # redirect_uri.query = [redirect_uri.query, "format=json"].compact.join('&')
44
+ # return get redirect_uri.to_s, controller
45
+ # else
46
+ # response_times << response.headers['X-Runtime'].to_f
47
+ # @context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
48
+ # if response.content_type == 'application/json'
49
+ # JSON.parse(response.body)
50
+ # else
51
+ # nil
52
+ # end
53
+ # end
54
+ # end
56
55
  end
57
56
 
58
57
  def post(url, controller, params)
@@ -73,24 +72,37 @@ module Glib
73
72
 
74
73
  private
75
74
  def fetch(method, url, controller, params = {})
76
- if url.blank? || history.include?(url)
77
- nil
78
- else
79
- # history << url
80
- @context.assert_match(URI_REGEXP, url)
75
+ return nil if url.blank?
81
76
 
82
- http_header = {
83
- 'Client-DeviceOS' => user[:device],
84
- 'Client-Version' => user[:version],
85
- 'X-CSRF-Token' => user[:token]
86
- }
77
+ if method == :get
78
+ return nil if history.include?(url)
87
79
 
88
- @context.send(method, url, params: params, headers: http_header)
89
- response = @context.response
90
- response_times << response.headers['X-Runtime'].to_f
91
- @context.assert_includes VALID_RESPONSE_CODES, response.code.to_i, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
92
- JsonCrawler::Router.log(controller, url, response)
80
+ history << url
81
+ end
82
+
83
+ @context.assert_match(URI_REGEXP, url)
84
+
85
+ http_header = {
86
+ 'Client-DeviceOS' => user[:device],
87
+ 'Client-Version' => user[:version],
88
+ 'X-CSRF-Token' => user[:token]
89
+ }
90
+
91
+ params.each do |name, value|
92
+ params[name] = "" if value.is_a?(Array) && value.size == 0
93
+ end
93
94
 
95
+ @context.send(method, url, params: params, headers: http_header)
96
+ response = @context.response
97
+ JsonCrawler::Router.log(controller, url, response)
98
+
99
+ if (code = response.code.to_i) == 302
100
+ redirect_uri = URI(response.headers['Location'])
101
+ redirect_uri.query = [redirect_uri.query, "format=json"].compact.join('&')
102
+ return get redirect_uri.to_s, controller
103
+ else
104
+ response_times << response.headers['X-Runtime'].to_f
105
+ @context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
94
106
  if response.media_type == 'application/json'
95
107
  JSON.parse(response.body)
96
108
  else
@@ -100,4 +112,4 @@ module Glib
100
112
  end
101
113
  end
102
114
  end
103
- end
115
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -35,6 +35,7 @@ files:
35
35
  - app/controllers/concerns/application/json/ui.rb
36
36
  - app/controllers/concerns/application/json/validation.rb
37
37
  - app/controllers/glib/home_controller.rb
38
+ - app/helpers/glib/dynamic_texts_helper.rb
38
39
  - app/helpers/glib/json_ui/abstract_builder.rb
39
40
  - app/helpers/glib/json_ui/action_builder.rb
40
41
  - app/helpers/glib/json_ui/list_builders.rb
@@ -48,6 +49,8 @@ files:
48
49
  - app/helpers/glib/json_ui/view_builder/banners.rb
49
50
  - app/helpers/glib/json_ui/view_builder/fields.rb
50
51
  - app/helpers/glib/json_ui/view_builder/panels.rb
52
+ - app/models/glib/dynamic_text_record.rb
53
+ - app/models/glib/text.rb
51
54
  - app/views/app/views/json_ui/vue/renderer.html.erb
52
55
  - app/views/json_ui/garage/_nav_menu.json.jbuilder
53
56
  - app/views/json_ui/garage/actions/index.json.jbuilder
@@ -111,6 +114,11 @@ files:
111
114
  - app/views/json_ui/garage/views/misc.json.jbuilder
112
115
  - app/views/json_ui/garage/views/texts.json.jbuilder
113
116
  - config/routes.rb
117
+ - lib/generators/glib/install_generator.rb
118
+ - lib/generators/templates/20191017062519_create_texts.rb
119
+ - lib/generators/templates/20191024063257_add_scope_to_texts.rb
120
+ - lib/generators/templates/database.yml
121
+ - lib/generators/templates/dynamic_text.rb
114
122
  - lib/glib-web.rb
115
123
  - lib/glib/engine.rb
116
124
  - lib/glib/json_crawler.rb