![viatropos viatropos](https://entp-lh-avatar-production.s3.amazonaws.com/avatars/44528/large.jpg?AWSAccessKeyId=AKIAJ4QBZRZBVMOUBNZA&Expires=2038087081&Signature=iEOHwPoUSa0cUwJEK4nibohpMvQ%3D)
Abstract out "Configuration" functionality from i18n into separate gem.
Reported by viatropos | June 17th, 2010 @ 12:11 AM
Hi,
Not sure if there's an irc for i18n so I'm posting this here.
I am looking to build a sort of settings/configuration model that acts exactly like i18n, with a few extensions:
- Use dot-separated keys to acts as a nested set
(
site.authentication.use_openid
as a sample setting) - Allow settings to be unique to individual models (polymorphic
belongs_to
configurable
) - Have a default set of configurations/settings that are overridden on a per-model-as-needed basis.
I just looked through the i18n code to see if it was doing something similar (that's where I got the idea for dot-separated keys to mimic a nested set). It looks pretty much the same...
So I'm wondering, what are your thoughts on extracting out that core "nested set configuration" functionality into an even more fundamental gem which i18n builds upon?
By "nested set configuration" I mean these are equivalent:
path.to.translation = "Hello World"
{:path => {:to => {:translation => "Hello World"}}}
Setting.find("path", :scope => "to.translation").value => "Hello World"
That way I can do things like this (I'm actually using this now for settings):
Settings do
asset do
thumb do
width 100, :tip => "Thumb's width"
height 100, :tip => "Thumb's height"
end
medium do
width 600, :tip => "Thumb's width"
height 250, :tip => "Thumb's height"
end
large do
width 600, :tip => "Large's width"
height 295, :tip => "Large's height"
end
end
authentication do
use_open_id true
use_oauth true
email "martini@example.com"
password "martini"
end
front_page do
slideshow_tag "slideshow"
slideshow_effect "fade"
end
page do
per_page 10
feed_per_page 10
formats "markdown", :options => ["textile", "markdown", "plain", "html", "haml"]
end
people do
show_avatars true
default_avatar "/images/missing-person.png"
end
site do
title "Martini", :tooltip => "Main Site Title!"
tagline "Developer Friendly, Client Ready Blog with Rails 3"
keywords "Rails 3, Heroku, JQuery, HTML 5, Blog Engine, CSS3"
copyright "© 2010 Viatropos. All rights reserved."
menu :type => :integer,
:value => lambda { Post.roots },
:options => lambda { Post.roots.map {|p| [p.title, p.id]} }
date_format "%m %d, %Y"
time_format "%H"
week_starts_on "Monday", :options => ["Monday", "Sunday", "Friday"]
language "en-US", :options => ["en-US", "de"]
touch_enabled true
touch_as_subdomain false
google_analytics ""
logo "/images/logo-thumb.png"
cache_duration 60
permalink do
default "/:title"
date "/:date/:title"
numeric "/:id"
custom ""
end
teasers do
disable false
left :type => :integer,
:value => lambda { Post.first },
:options => lambda { Post.tree {|p| [p.title, p.id]} }
right :type => :integer,
:value => lambda { Post.first },
:options => lambda { Post.tree {|p| [p.title, p.id]} }
center :type => :integer,
:value => lambda { Post.first },
:options => lambda { Post.tree {|p| [p.title, p.id]} }
end
main_quote :type => :integer,
:value => lambda { Post.first },
:options => lambda { Post.tree {|p| [p.title, p.id]} }
end
s3 do
key "my_key"
secret "my_secret"
end
end
Here's the benefit of doing this:
- All applications that need Configuration (translations, preferences, app configuration, etc.) will only require one table
...something like this:
create_table :settings do |t|
t.string :scope #=> locale for translations
t.string :key
t.string :kind #=> or sti "type", "translations", "settings", etc.
t.references :configurable, :polymorphic => true # what it's associated with (per-user settings for example), null if global
t.text :value
t.text :interpolations
t.boolean :is_proc, :default => false
end
- Efforts can be divided among two main tasks: translations, and optimizing storing key/values and everything that entails (handling procs for example).
Otherwise, if I want to create settings functionality, where
Setting values are often procs (Post.all
for
instance), I have to copy most of the i18n code, or start from
scratch.
Maybe something like this would be useful to others?
What are your thoughts?
Comments and changes to this ticket
-
david001 September 13th, 2019 @ 05:52 PM
I Searching For this solution thanks to post such helpful Article. you can also Visit this website for More Help. https://techtoptricks.com/
-
willbent December 3rd, 2019 @ 10:25 AM
Nice information and thanks for sharing this to us. Online surveys are very popular at present. Get Greatpeople.me kroger Employee Login details here to use.
-
debbwall June 24th, 2020 @ 06:57 AM
I like the post which you shared here and thanks for sharing this to us. Robux is the virtual currency of Roblox. There are a few different ways to get free robux can be earned or purchased. You can purchase Robux from the generator.
-
Scott Heflin August 20th, 2020 @ 06:33 AM
This is these kinds of an ideal resource in which you will be giving and you also present that apart regarding complimentary.
-
artwin March 2nd, 2021 @ 11:28 AM
Taco Bell serves a wide range of delicious dishes on its menu. TellTheBell Survey is a customer survey on the official portal of Taco Bell. TellTheBell Survey is launched to enhance the quality of these delicious dishes by getting reviews on the same. The Tellthebell Survey at TellTheBell.com purely aims to meet customer requirements and expectations. https://tellthebell.ninja
-
Kopi Shop August 18th, 2021 @ 07:31 AM
Anthurium memuaskan para pecinta tumbuhan hias dengan tampilannya yang estetis. https://hobbymahal.com/ Tumbuhan hias dari famili Araceae ini populer dengan corak daunnya yang khas. Karena memiliki keindahan itu, konon anthurium menjadi salah satu tanaman hias yang sangat ditemukan di kawasan istana kerajaan.
-
yter dgd June 27th, 2024 @ 01:28 PM
The anti-inflammatory properties of omega-3 fatty acids in caviar extend beyond cardiovascular and brain health. Chronic inflammation is a root cause of many diseases, including arthritis, diabetes, and even some cancers https://caviarprice.io/. By incorporating caviar into the diet, individuals can help mitigate inflammation and reduce the risk of these chronic conditions. The anti-inflammatory effects also contribute to the overall feeling of well-being and can help alleviate symptoms in individuals suffering from inflammatory diseases.
-
hfutr2 August 1st, 2024 @ 12:39 PM
Since MCAs are based on future credit card sales rather than credit scores, businesses with poor or limited credit histories can still access funding. This feature can be especially advantageous for startups or businesses that are rebuilding their credit https://advancery.io/, as it allows them to secure necessary capital without the immediate need to improve their credit rating.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Internationalization API for Ruby.
This library is used in Ruby on Rails but also suited for use in other contexts.