site_settings 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 559fcd3fc3894bbef8aaa9c7d87d6dbd8fcd78c28eca87c8d760322c84dea82b
4
+ data.tar.gz: 03fb2dcd31dece52505f37e1e43e4ae9f67992b1bd84171bb5cec4773a2985ec
5
+ SHA512:
6
+ metadata.gz: 5caccf1bf71d0d23bf514e773e20b28d377192d7a4576e980ff0f1b7d5868330c9620aa8c4a4eceb083beebd36b5d2f3bfb3884a9639e77c480ac443bb9bcecf
7
+ data.tar.gz: f6bf50e73b6d2b374ce0d97f1874fa730059b92fc0aa573481846f393dccbd62edebe314b3aefee6fd52a7f7f21b327964f81d25bc6304a0f67d9efc36766f8b
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,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -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,4 @@
1
+ module SiteSettings
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module SiteSettings
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module SiteSettings
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module SiteSettings
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ 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,5 @@
1
+ SiteSettings::Engine.routes.draw do
2
+ root "settings#index"
3
+ get "settings", to: "settings#index"
4
+ post "settings", to: "settings#update"
5
+ end
@@ -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
@@ -0,0 +1,8 @@
1
+ module SiteSettings
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SiteSettings
4
+
5
+ config.autoload_paths << root.join("app", "components")
6
+ config.view_component.preview_paths << root.join("spec", "components", "previews")
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module SiteSettings
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "site_settings/version"
2
+ require "site_settings/engine"
3
+
4
+ module SiteSettings
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace SiteSettings
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :site_settings do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: site_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - usman@artisans.com
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 Artisans
28
+ email:
29
+ - usman@artisans.com
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.com
56
+ licenses: []
57
+ metadata:
58
+ allowed_push_host: https://rubygems.org
59
+ homepage_uri: https://artisans.com
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 Artisans
81
+ test_files: []