artisans_site_settings 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/app/assets/stylesheets/site_settings/application.css +15 -0
- data/app/components/site_settings/form_component.html.erb +17 -0
- data/app/components/site_settings/form_component.rb +14 -0
- data/app/controllers/site_settings/application_controller.rb +17 -0
- data/app/controllers/site_settings/settings_controller.rb +14 -0
- data/app/helpers/site_settings/application_helper.rb +4 -0
- data/app/jobs/site_settings/application_job.rb +4 -0
- data/app/mailers/site_settings/application_mailer.rb +6 -0
- data/app/models/site_settings/application_record.rb +5 -0
- data/app/models/site_settings/setting.rb +15 -0
- data/app/services/site_settings/manager.rb +37 -0
- data/app/views/layouts/site_settings/application.html.erb +16 -0
- data/app/views/site_settings/settings/index.html.erb +14 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20241009155632_create_site_settings_settings.rb +11 -0
- data/lib/site_settings/engine.rb +8 -0
- data/lib/site_settings/version.rb +3 -0
- data/lib/site_settings.rb +8 -0
- data/lib/tasks/site_settings_tasks.rake +4 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a807f6bb942f741b07309f83b47b16c7f88770a6b6f9fe5902825bdb6e5336a9
|
4
|
+
data.tar.gz: 657400064b86ca6eeff27e871e89a516c22e3c4549bc7e025e0e10b183199e6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2084121653af00fe4d074c51049eef5c99d50c36f4401947d12c74d58b9ef3417deae14d16f0c3a76e9eb5bb8891ac5f36918337ff60b7e48073e0c6144d84bc
|
7
|
+
data.tar.gz: 911c0effaff34dabeb3015f94563e6a7b62ac48c3ccbef552e341631bb7f49de6eb63523c8f0f6b2a292adcda842797b7b0d42fe456d88e93f36fe8ab4a1b4d9
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# SiteSettings
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "site_settings"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install site_settings
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_with url: settings_path, local: true, class: "primer-form" do |form| %>
|
2
|
+
<div class="d-flex flex-column flex-md-row flex-wrap gutter-md-spacious">
|
3
|
+
<% settings.each_slice(2) do |setting_pair| %>
|
4
|
+
<% setting_pair.each do |key, value| %>
|
5
|
+
<div class="col-md-6 mb-0">
|
6
|
+
<div class="form-group">
|
7
|
+
<%= form.label key, class: "form-label f5 text-bold d-block mb-1" %>
|
8
|
+
<%= form.text_field key, value: value, class: "form-control input-block width-full" %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
14
|
+
<div class="col-12 mt-3">
|
15
|
+
<%= form.submit "Save Settings", class: "btn btn-primary" %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SiteSettings
|
2
|
+
class FormComponent < ViewComponent::Base
|
3
|
+
def initialize(settings:, settings_path:)
|
4
|
+
@settings = settings
|
5
|
+
@settings_path = settings_path
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :settings, :settings_path
|
9
|
+
|
10
|
+
def render?
|
11
|
+
@settings.present?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# site_settings/app/controllers/site_settings/application_controller.rb
|
2
|
+
module SiteSettings
|
3
|
+
class ApplicationController < ::ApplicationController
|
4
|
+
layout :determine_layout
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def determine_layout
|
9
|
+
# Use the main app's layout if it exists, otherwise fall back to the engine's layout
|
10
|
+
layout_exists_in_main_app? ? "application" : "site_settings/application"
|
11
|
+
end
|
12
|
+
|
13
|
+
def layout_exists_in_main_app?
|
14
|
+
File.exist?(Rails.root.join("app", "views", "layouts", "application.html.erb"))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SiteSettings
|
2
|
+
class SettingsController < ApplicationController
|
3
|
+
def index
|
4
|
+
@settings = Manager.all
|
5
|
+
end
|
6
|
+
|
7
|
+
def update
|
8
|
+
params.except(:action, :controller).each do |key, value|
|
9
|
+
Manager.set(key, value)
|
10
|
+
end
|
11
|
+
redirect_to settings_path, notice: "Settings updated successfully."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SiteSettings
|
2
|
+
class Setting < ApplicationRecord
|
3
|
+
validates :key, presence: true, uniqueness: true
|
4
|
+
validates :value, presence: true
|
5
|
+
|
6
|
+
def self.get(key)
|
7
|
+
find_by(key: key)&.value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.set(key, value)
|
11
|
+
setting = find_or_initialize_by(key: key)
|
12
|
+
setting.update(value: value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module SiteSettings
|
2
|
+
class Manager
|
3
|
+
DEFAULT_SETTINGS = {
|
4
|
+
app_name: "The Artisans Company",
|
5
|
+
app_short_name: "Artisans Company",
|
6
|
+
app_url: "artisans.company",
|
7
|
+
business_name: "Artisan Company Inc",
|
8
|
+
business_address: "2261 Market Street",
|
9
|
+
business_phone: "2099044448",
|
10
|
+
business_email: "hey@artisan.company",
|
11
|
+
description: "Build a different outcome.",
|
12
|
+
default_language: "EN",
|
13
|
+
default_country: "NG",
|
14
|
+
default_currency: "NGN",
|
15
|
+
meta_title: "Artisans Company",
|
16
|
+
meta_keywords: "venture studio, venture capital",
|
17
|
+
meta_description: "Build a different outcome.",
|
18
|
+
meta_author: "Artisans Company",
|
19
|
+
logo: "logo.png",
|
20
|
+
favicon: "favicon.ico",
|
21
|
+
default_timezone: "WAT",
|
22
|
+
app_version: "0.0.1"
|
23
|
+
}
|
24
|
+
|
25
|
+
def self.get(key)
|
26
|
+
Setting.get(key) || DEFAULT_SETTINGS[key.to_sym]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.set(key, value)
|
30
|
+
Setting.set(key, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.all
|
34
|
+
DEFAULT_SETTINGS.keys.map { |key| [ key, get(key) ] }.to_h
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Site settings</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= yield :head %>
|
9
|
+
<%= stylesheet_link_tag "site_settings/application", media: "all" %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div class="Box">
|
2
|
+
<div class="Box-header d-flex flex-column flex-md-row">
|
3
|
+
<div class="col-12 col-md-8">
|
4
|
+
<h1 class="h2 mb-2 mb-md-0">Site Settings</h1>
|
5
|
+
<p class="color-fg-muted mb-0">Manage the default settings for your site.</p>
|
6
|
+
</div>
|
7
|
+
<div class="col-12 col-md-4 mt-3 mt-md-0 d-flex flex-items-center flex-justify-end">
|
8
|
+
<!-- You can add action buttons here if needed -->
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<div class="Box-body">
|
12
|
+
<%= render(SiteSettings::FormComponent.new(settings: @settings, settings_path: site_settings.settings_path)) %>
|
13
|
+
</div>
|
14
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateSiteSettingsSettings < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :site_settings_settings do |t|
|
4
|
+
t.string :key, null: false
|
5
|
+
t.text :value
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :site_settings_settings, :key, unique: true
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: artisans_site_settings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- usman@artisans.company
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 8.0.0.beta1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 8.0.0.beta1
|
27
|
+
description: Site Settings for the Artisans Platform Configuration
|
28
|
+
email:
|
29
|
+
- usman@artisans.company
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- app/assets/stylesheets/site_settings/application.css
|
37
|
+
- app/components/site_settings/form_component.html.erb
|
38
|
+
- app/components/site_settings/form_component.rb
|
39
|
+
- app/controllers/site_settings/application_controller.rb
|
40
|
+
- app/controllers/site_settings/settings_controller.rb
|
41
|
+
- app/helpers/site_settings/application_helper.rb
|
42
|
+
- app/jobs/site_settings/application_job.rb
|
43
|
+
- app/mailers/site_settings/application_mailer.rb
|
44
|
+
- app/models/site_settings/application_record.rb
|
45
|
+
- app/models/site_settings/setting.rb
|
46
|
+
- app/services/site_settings/manager.rb
|
47
|
+
- app/views/layouts/site_settings/application.html.erb
|
48
|
+
- app/views/site_settings/settings/index.html.erb
|
49
|
+
- config/routes.rb
|
50
|
+
- db/migrate/20241009155632_create_site_settings_settings.rb
|
51
|
+
- lib/site_settings.rb
|
52
|
+
- lib/site_settings/engine.rb
|
53
|
+
- lib/site_settings/version.rb
|
54
|
+
- lib/tasks/site_settings_tasks.rake
|
55
|
+
homepage: https://artisans.company
|
56
|
+
licenses: []
|
57
|
+
metadata:
|
58
|
+
allowed_push_host: https://rubygems.org
|
59
|
+
homepage_uri: https://artisans.company
|
60
|
+
source_code_uri: https://github.com/artisanscompany/artisans-site-settings
|
61
|
+
changelog_uri: https://github.com/artisanscompany/artisans-site-settings/blob/main/CHANGELOG.md
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.5.21
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Site Settings for the Artisans Platform Configuration
|
81
|
+
test_files: []
|