lastobelus-merb_global 0.0.7 → 0.0.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.
- data/activerecord_generators/translations_migration/USAGE +4 -0
- data/activerecord_generators/translations_migration/templates/translations_migration.erb +30 -0
- data/activerecord_generators/translations_migration/translations_migration_generator.rb +31 -0
- data/examples/active_record_example/README.txt +9 -0
- data/examples/active_record_example/application.rb +5 -0
- data/examples/active_record_example/config/database.yml +9 -0
- data/examples/active_record_example/config/framework.rb +5 -0
- data/examples/active_record_example/config/init.rb +24 -0
- data/examples/active_record_example/config/plugins.yml +3 -0
- data/examples/data_mapper_example/README.txt +9 -0
- data/examples/data_mapper_example/application.rb +5 -0
- data/examples/data_mapper_example/config/database.yml +9 -0
- data/examples/data_mapper_example/config/framework.rb +5 -0
- data/examples/data_mapper_example/config/init.rb +24 -0
- data/examples/data_mapper_example/config/plugins.yml +3 -0
- data/examples/database.sql +28 -0
- data/examples/gettext_example/README.txt +9 -0
- data/examples/gettext_example/application.rb +8 -0
- data/examples/gettext_example/config/framework.rb +5 -0
- data/examples/gettext_example/config/init.rb +24 -0
- data/examples/gettext_example/config/plugins.yml +4 -0
- data/examples/gettext_example/locale/merbapp.pot +21 -0
- data/examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo +0 -0
- data/examples/gettext_example/locale/pl.po +23 -0
- data/examples/mock_example/README.txt +9 -0
- data/examples/mock_example/application.rb +5 -0
- data/examples/mock_example/config/framework.rb +5 -0
- data/examples/mock_example/config/init.rb +23 -0
- data/examples/mock_example/config/plugins.yml +3 -0
- data/examples/sequel_example/README.txt +9 -0
- data/examples/sequel_example/application.rb +5 -0
- data/examples/sequel_example/config/database.yml +9 -0
- data/examples/sequel_example/config/framework.rb +5 -0
- data/examples/sequel_example/config/init.rb +24 -0
- data/examples/sequel_example/config/plugins.yml +3 -0
- data/examples/yaml_example/README.txt +9 -0
- data/examples/yaml_example/application.rb +5 -0
- data/examples/yaml_example/config/framework.rb +5 -0
- data/examples/yaml_example/config/init.rb +24 -0
- data/examples/yaml_example/config/plugins.yml +4 -0
- data/examples/yaml_example/locale/en.yaml +2 -0
- data/examples/yaml_example/locale/pl.yaml +2 -0
- data/lib/merb_global/base.rb +105 -0
- data/lib/merb_global/config.rb +36 -0
- data/lib/merb_global/controller.rb +38 -0
- data/lib/merb_global/date_providers/fork.rb +35 -0
- data/lib/merb_global/date_providers.rb +47 -0
- data/lib/merb_global/locale.rb +139 -0
- data/lib/merb_global/merbrake.rb +37 -0
- data/lib/merb_global/message_providers/active_record.rb +113 -0
- data/lib/merb_global/message_providers/data_mapper.rb +113 -0
- data/lib/merb_global/message_providers/gettext.rb +123 -0
- data/lib/merb_global/message_providers/gettext.treetop +60 -0
- data/lib/merb_global/message_providers/mock.rb +17 -0
- data/lib/merb_global/message_providers/sequel.rb +99 -0
- data/lib/merb_global/message_providers/yaml.rb +92 -0
- data/lib/merb_global/message_providers.rb +146 -0
- data/lib/merb_global/numeric_providers/fork.rb +35 -0
- data/lib/merb_global/numeric_providers/java.rb +15 -0
- data/lib/merb_global/numeric_providers.rb +48 -0
- data/lib/merb_global/plural.rb +20 -0
- data/lib/merb_global/plural.treetop +267 -0
- data/lib/merb_global/providers.rb +40 -0
- data/lib/merb_global.rb +8 -0
- data/sequel_generators/translations_migration/USAGE +4 -0
- data/sequel_generators/translations_migration/templates/translations_migration.erb +28 -0
- data/sequel_generators/translations_migration/translations_migration_generator.rb +32 -0
- metadata +92 -1
@@ -0,0 +1,30 @@
|
|
1
|
+
#<% if false %>
|
2
|
+
class Merb::Global::MessageProviders::ActiveRecord
|
3
|
+
#<% end %>
|
4
|
+
class AddTranslationsMigration < ActiveRecord::Migration
|
5
|
+
def self.up
|
6
|
+
create_table :merb_global_languages do |t|
|
7
|
+
t.string :name, :limit => 16
|
8
|
+
t.integer :nplural
|
9
|
+
t.string :plural, :size => 128
|
10
|
+
end
|
11
|
+
add_index :merb_global_languages, :name, :unique => true
|
12
|
+
create_table :merb_global_translations,
|
13
|
+
:id => false, :primary_key => [:language_id,
|
14
|
+
:msgid_hash,
|
15
|
+
:msgstr_index] do |t|
|
16
|
+
t.integer :language_id, :null => false
|
17
|
+
t.text :msgid, :null => false
|
18
|
+
t.text :msgid_plural
|
19
|
+
t.text :msgstr, :null => false
|
20
|
+
t.integer :msgstr_index, :null => true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def self.down
|
24
|
+
drop_table :merb_global_languages
|
25
|
+
drop_table :merb_global_translations
|
26
|
+
end
|
27
|
+
end
|
28
|
+
#<% if false %>
|
29
|
+
end
|
30
|
+
#<% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class TranslationMigrationGenerator < Merb::GeneratorBase
|
2
|
+
protected :banner
|
3
|
+
|
4
|
+
def initialize runtime_args, runtime_options = {}
|
5
|
+
runtime_args.push ''
|
6
|
+
super
|
7
|
+
@name = 'translations'
|
8
|
+
end
|
9
|
+
|
10
|
+
def mainfest
|
11
|
+
record do |m|
|
12
|
+
m.directory 'schema/migrations'
|
13
|
+
highest_migration = Dir[Dir.pwd+'/schema/migrations/*'].map do |f|
|
14
|
+
File.basename(f) =~ /^(\d+)/
|
15
|
+
$1
|
16
|
+
end.max
|
17
|
+
filename = format '%03d_%s', (highest_migration.to_i+1), @name.snake_case
|
18
|
+
m.template 'translation_migration.erb',
|
19
|
+
"schema/migrations/#{filename}.rb"
|
20
|
+
puts banner
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def banner
|
25
|
+
<<-EOS
|
26
|
+
A migration to add translation tables to your database has been created.
|
27
|
+
Run 'rake sequel:db:migrate' to add the translations migration to your database.
|
28
|
+
|
29
|
+
EOS
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the merb_global from current tree
|
2
|
+
Gem.clear_paths
|
3
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
4
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
5
|
+
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match('/').to(:controller => 'active_record_example', :action =>'index')
|
8
|
+
end
|
9
|
+
|
10
|
+
use_orm :activerecord
|
11
|
+
dependency 'merb_global'
|
12
|
+
|
13
|
+
Merb::Config.use { |c|
|
14
|
+
c[:environment] = 'production',
|
15
|
+
c[:framework] = {},
|
16
|
+
c[:log_level] = 'debug',
|
17
|
+
c[:use_mutex] = false,
|
18
|
+
c[:session_store] = 'cookie',
|
19
|
+
c[:session_id_key] = '_session_id',
|
20
|
+
c[:session_secret_key] = '779c710d6a7b90faf17cba97c156fc133a9884c9',
|
21
|
+
c[:exception_details] = true,
|
22
|
+
c[:reload_classes] = true,
|
23
|
+
c[:reload_time] = 0.5
|
24
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the merb_global from current tree
|
2
|
+
Gem.clear_paths
|
3
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
4
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
5
|
+
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match('/').to(:controller => 'data_mapper_example', :action =>'index')
|
8
|
+
end
|
9
|
+
|
10
|
+
use_orm :datamapper
|
11
|
+
dependency 'merb_global'
|
12
|
+
|
13
|
+
Merb::Config.use { |c|
|
14
|
+
c[:environment] = 'production',
|
15
|
+
c[:framework] = {},
|
16
|
+
c[:log_level] = 'debug',
|
17
|
+
c[:use_mutex] = false,
|
18
|
+
c[:session_store] = 'cookie',
|
19
|
+
c[:session_id_key] = '_session_id',
|
20
|
+
c[:session_secret_key] = '5b587281e1b277c3e90f5de2e42e5125dc649837',
|
21
|
+
c[:exception_details] = true,
|
22
|
+
c[:reload_classes] = true,
|
23
|
+
c[:reload_time] = 0.5
|
24
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
DROP TABLE IF EXISTS merb_global_languages;
|
2
|
+
CREATE TABLE merb_global_languages (
|
3
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
4
|
+
name VARCHAR(50),
|
5
|
+
nplural INTEGER,
|
6
|
+
plural TEXT
|
7
|
+
);
|
8
|
+
|
9
|
+
DROP TABLE IF EXISTS merb_global_translations;
|
10
|
+
CREATE TABLE merb_global_translations (
|
11
|
+
language_id INTEGER NOT NULL,
|
12
|
+
msgid TEXT NOT NULL,
|
13
|
+
msgid_plural TEXT,
|
14
|
+
msgstr TEXT NOT NULL,
|
15
|
+
msgstr_index INTEGER,
|
16
|
+
PRIMARY KEY(language_id, msgid, msgstr_index));
|
17
|
+
|
18
|
+
|
19
|
+
CREATE UNIQUE INDEX unique_index_merb_global_languages_name
|
20
|
+
ON merb_global_languages (name);
|
21
|
+
|
22
|
+
INSERT INTO merb_global_languages (name, nplural, plural)
|
23
|
+
VALUES ("pl", 3, "(n==1?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2)");
|
24
|
+
|
25
|
+
INSERT INTO merb_global_translations (language_id, msgid, msgstr)
|
26
|
+
SELECT id, "Hi! Hello world!", "Cześć. Witaj świecie!"
|
27
|
+
FROM merb_global_languages
|
28
|
+
WHERE name = "pl";
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the merb_global from current tree
|
2
|
+
Gem.clear_paths
|
3
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
4
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
5
|
+
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match('/').to(:controller => 'gettext_example', :action =>'index')
|
8
|
+
r.default_routes
|
9
|
+
end
|
10
|
+
|
11
|
+
dependency 'merb_global'
|
12
|
+
|
13
|
+
Merb::Config.use { |c|
|
14
|
+
c[:environment] = 'production',
|
15
|
+
c[:framework] = {},
|
16
|
+
c[:log_level] = 'debug',
|
17
|
+
c[:use_mutex] = false,
|
18
|
+
c[:session_store] = 'cookie',
|
19
|
+
c[:session_id_key] = '_session_id',
|
20
|
+
c[:session_secret_key] = '489739417a2edcb2ae6ec7390fc467992e313ed8',
|
21
|
+
c[:exception_details] = true,
|
22
|
+
c[:reload_classes] = true,
|
23
|
+
c[:reload_time] = 0.5
|
24
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
2
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
3
|
+
# This file is distributed under the same license as the PACKAGE package.
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
5
|
+
#
|
6
|
+
#, fuzzy
|
7
|
+
msgid ""
|
8
|
+
msgstr ""
|
9
|
+
"Project-Id-Version: PACKAGE VERSION\n"
|
10
|
+
"Report-Msgid-Bugs-To: \n"
|
11
|
+
"POT-Creation-Date: 2008-05-22 13:59+0200\n"
|
12
|
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
13
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14
|
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=CHARSET\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
|
19
|
+
#: gettext_example.rb:21
|
20
|
+
msgid "Hi! Hello world!"
|
21
|
+
msgstr ""
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Polish translations for PACKAGE package
|
2
|
+
# Polskie tłumaczenia dla pakietu PACKAGE.
|
3
|
+
# Copyright (C) 2008 THE PACKAGE'S COPYRIGHT HOLDER
|
4
|
+
# This file is distributed under the same license as the PACKAGE package.
|
5
|
+
# <uzytkownik2@gmail.com>, 2008.
|
6
|
+
#
|
7
|
+
msgid ""
|
8
|
+
msgstr ""
|
9
|
+
"Project-Id-Version: PACKAGE VERSION\n"
|
10
|
+
"Report-Msgid-Bugs-To: \n"
|
11
|
+
"POT-Creation-Date: 2008-05-22 13:59+0200\n"
|
12
|
+
"PO-Revision-Date: 2008-05-22 21:42+0100\n"
|
13
|
+
"Last-Translator: Maciej Piechotka <uzytkownik2@gmail.com>\n"
|
14
|
+
"Language-Team: Polish\n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
19
|
+
|
20
|
+
#: gettext_example.rb:21
|
21
|
+
msgid "Hi! Hello world!"
|
22
|
+
msgstr "Cześć. Witaj świecie!"
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem.clear_paths
|
2
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
3
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
4
|
+
|
5
|
+
Merb::Router.prepare do |r|
|
6
|
+
r.match('/').to(:controller => 'mock_example', :action =>'index')
|
7
|
+
r.default_routes
|
8
|
+
end
|
9
|
+
|
10
|
+
dependency 'merb_global'
|
11
|
+
|
12
|
+
Merb::Config.use { |c|
|
13
|
+
c[:environment] = 'production',
|
14
|
+
c[:framework] = {},
|
15
|
+
c[:log_level] = 'debug',
|
16
|
+
c[:use_mutex] = false,
|
17
|
+
c[:session_store] = 'cookie',
|
18
|
+
c[:session_id_key] = '_session_id',
|
19
|
+
c[:session_secret_key] = 'd729662a1de4755ac16f34d1bb012fe5c9e6a965',
|
20
|
+
c[:exception_details] = true,
|
21
|
+
c[:reload_classes] = true,
|
22
|
+
c[:reload_time] = 0.5
|
23
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the merb_global from current tree
|
2
|
+
Gem.clear_paths
|
3
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
4
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
5
|
+
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match('/').to(:controller => 'gettext_example', :action =>'index')
|
8
|
+
end
|
9
|
+
|
10
|
+
use_orm :sequel
|
11
|
+
dependency 'merb_global'
|
12
|
+
|
13
|
+
Merb::Config.use { |c|
|
14
|
+
c[:environment] = 'production',
|
15
|
+
c[:framework] = {},
|
16
|
+
c[:log_level] = 'debug',
|
17
|
+
c[:use_mutex] = false,
|
18
|
+
c[:session_store] = 'cookie',
|
19
|
+
c[:session_id_key] = '_session_id',
|
20
|
+
c[:session_secret_key] = 'dd578852e40789695203305439f3ee2cf77b0cfc',
|
21
|
+
c[:exception_details] = true,
|
22
|
+
c[:reload_classes] = true,
|
23
|
+
c[:reload_time] = 0.5
|
24
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the merb_global from current tree
|
2
|
+
Gem.clear_paths
|
3
|
+
Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
|
4
|
+
$LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
|
5
|
+
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match('/').to(:controller => 'yaml_example', :action =>'index')
|
8
|
+
r.default_routes
|
9
|
+
end
|
10
|
+
|
11
|
+
dependency 'merb_global'
|
12
|
+
|
13
|
+
Merb::Config.use { |c|
|
14
|
+
c[:environment] = 'production',
|
15
|
+
c[:framework] = {},
|
16
|
+
c[:log_level] = 'debug',
|
17
|
+
c[:use_mutex] = false,
|
18
|
+
c[:session_store] = 'cookie',
|
19
|
+
c[:session_id_key] = '_session_id',
|
20
|
+
c[:session_secret_key] = 'ceb534866f8bb368f8e935b31604e45b818c6dd4',
|
21
|
+
c[:exception_details] = true,
|
22
|
+
c[:reload_classes] = true,
|
23
|
+
c[:reload_time] = 0.5
|
24
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'merb_global/config'
|
2
|
+
require 'merb_global/plural'
|
3
|
+
require 'merb_global/locale'
|
4
|
+
require 'merb_global/date_providers'
|
5
|
+
require 'merb_global/message_providers'
|
6
|
+
require 'merb_global/numeric_providers'
|
7
|
+
|
8
|
+
class String
|
9
|
+
def localize(args = {})
|
10
|
+
opts = {:locale => Merb::Global::Locale.current, :n => 1, :plural => nil}
|
11
|
+
opts.merge!(args)
|
12
|
+
Merb::Global::MessageProviders.provider.localize self, opts[:plural],
|
13
|
+
opts[:n], opts[:locale]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Numeric
|
18
|
+
def localize(args = {})
|
19
|
+
opts = {:locale => Merb::Global::Locale.current}
|
20
|
+
opts.merge!(args)
|
21
|
+
Merb::Global::NumericProviders.provider.localize opts[:locale], self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Date
|
26
|
+
def localize(format, args = {})
|
27
|
+
opts = {:locale => Merb::Global::Locale.current}
|
28
|
+
opts.merge!(args)
|
29
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class DateTime
|
34
|
+
def localize(format, args = {})
|
35
|
+
opts = {:locale => Merb::Global::Locale.current}
|
36
|
+
opts.merge!(args)
|
37
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Time
|
42
|
+
def localize(format, args = {})
|
43
|
+
opts = {:locale => Merb::Global::Locale.current}
|
44
|
+
opts.merge!(args)
|
45
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Merb
|
50
|
+
module Global
|
51
|
+
# call-seq:
|
52
|
+
# _(singular, opts) => translated message
|
53
|
+
# _(singlular, plural, opts) => translated message
|
54
|
+
# _(date, format) => localized date
|
55
|
+
# _(number) => localized number
|
56
|
+
#
|
57
|
+
# Translate a string.
|
58
|
+
# ==== Parameters
|
59
|
+
# singular<String>:: A string to translate
|
60
|
+
# plural<String>:: A plural form of string
|
61
|
+
# opts<Hash>:: An options hash (see below)
|
62
|
+
# date<~strftime>:: A date to localize
|
63
|
+
# format<String>:: A format of string (should be compatibile with strftime)
|
64
|
+
# number<Numeric>:: A numeber to localize
|
65
|
+
#
|
66
|
+
# ==== Options (opts)
|
67
|
+
# :locale<Locale>:: A language to translate on
|
68
|
+
# :n<Fixnum>:: A number of objects (for messages)
|
69
|
+
#
|
70
|
+
# ==== Returns
|
71
|
+
# translated<String>:: A translated string
|
72
|
+
#
|
73
|
+
# ==== Example
|
74
|
+
# <tt>render _('%d file deleted', '%d files deleted', :n => del) % del</tt>
|
75
|
+
def _(*args)
|
76
|
+
opts = {:locale => Merb::Global::Locale.current, :n => 1}
|
77
|
+
opts.merge! args.pop if args.last.is_a? Hash
|
78
|
+
if args.first.respond_to? :strftime
|
79
|
+
if args.size == 2
|
80
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], args[0], args[1]
|
81
|
+
else
|
82
|
+
raise ArgumentError, "wrong number of arguments (#{args.size} for 2)"
|
83
|
+
end
|
84
|
+
elsif args.first.is_a? Numeric
|
85
|
+
if args.size == 1
|
86
|
+
Merb::Global::NumericProviders.provider.localize opts[:locale], args.first
|
87
|
+
else
|
88
|
+
raise ArgumentError, "wrong number of arguments (#{args.size} for 1)"
|
89
|
+
end
|
90
|
+
elsif args.first.is_a? String
|
91
|
+
if args.size == 1
|
92
|
+
Merb::Global::MessageProviders.provider.localize args[0], nil, opts[:n], opts[:locale]
|
93
|
+
elsif args.size == 2
|
94
|
+
Merb::Global::MessageProviders.provider.localize args[0], args[1], opts[:n], opts[:locale]
|
95
|
+
else
|
96
|
+
raise ArgumentError,
|
97
|
+
"wrong number of arguments (#{args.size} for 1-2)"
|
98
|
+
end
|
99
|
+
else
|
100
|
+
raise ArgumentError,
|
101
|
+
"wrong type of arguments - see documentation for details"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Merb
|
2
|
+
module Global
|
3
|
+
@@config = nil
|
4
|
+
# call-seq:
|
5
|
+
# config(key) => value
|
6
|
+
# config([key1, key2, ...]) => value
|
7
|
+
# config(key, default) => value
|
8
|
+
# config([key1, key2, ...], default) => value
|
9
|
+
#
|
10
|
+
# Lookup the configuration
|
11
|
+
# ==== Params
|
12
|
+
# key<Symbol>:: A key
|
13
|
+
# keys<Array[Symbol]>:: Keys
|
14
|
+
# default<Object>:: A default value
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# value<Object>:: Object read from configuration or default
|
18
|
+
#
|
19
|
+
# ==== Examples
|
20
|
+
# <tt>Merb::Global.config [:gettext, :domain], 'merbapp'</tt>
|
21
|
+
def self.config(keys, default = nil)
|
22
|
+
keys = [keys] unless keys.is_a? Array
|
23
|
+
#if @@config.nil?
|
24
|
+
@@config = Merb::Plugins.config[:merb_global].dup
|
25
|
+
unless Merb::Plugins.config[:merb_global][Merb.env].nil?
|
26
|
+
@@config.merge! Merb::Plugins.config[:merb_global][Merb.env]
|
27
|
+
end
|
28
|
+
#end
|
29
|
+
current = @@config
|
30
|
+
while current.respond_to?(:[]) and not keys.empty?
|
31
|
+
current = current[keys.shift]
|
32
|
+
end
|
33
|
+
(keys.empty? and not current.nil?) ? current : default
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|