Class: Lokale::Config
- Inherits:
-
Object
- Object
- Lokale::Config
- Defined in:
- lib/lokale/config.rb,
lib/lokale/lokalefile.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#base_lang ⇒ Object
readonly
Returns the value of attribute base_lang.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#main_lang ⇒ Object
readonly
Returns the value of attribute main_lang.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Class Method Summary collapse
Instance Method Summary collapse
- #create_default_file ⇒ Object
- #fill_defaults ⇒ Object
- #lokalefile_path ⇒ Object
- #read_config_from_file(file_path) ⇒ Object
- #read_default_config ⇒ Object
- #read_lokalefile ⇒ Object
- #reset_config ⇒ Object
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
22 23 24 |
# File 'lib/lokale/config.rb', line 22 def actions @actions end |
#base_lang ⇒ Object (readonly)
Returns the value of attribute base_lang.
66 67 68 |
# File 'lib/lokale/lokalefile.rb', line 66 def base_lang @base_lang end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
65 66 67 |
# File 'lib/lokale/lokalefile.rb', line 65 def macros @macros end |
#main_lang ⇒ Object (readonly)
Returns the value of attribute main_lang.
66 67 68 |
# File 'lib/lokale/lokalefile.rb', line 66 def main_lang @main_lang end |
#project_name ⇒ Object
Returns the value of attribute project_name.
23 24 25 |
# File 'lib/lokale/config.rb', line 23 def project_name @project_name end |
#project_path ⇒ Object
Returns the value of attribute project_path.
23 24 25 |
# File 'lib/lokale/config.rb', line 23 def project_path @project_path end |
Class Method Details
.get ⇒ Object
69 70 71 72 |
# File 'lib/lokale/config.rb', line 69 def self.get init if @config.nil? @config end |
.init ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lokale/config.rb', line 25 def self.init return unless @config.nil? actions = [] OptionParser.new do |opts| opts. = "Usage: lokale [-bsh]" opts.on("-b", "--copy-base", "Copies 'en' localization files to 'Base'") do |n| actions << Action.copy_base end opts.on("-s", "--summary", "Prints project summary") do |n| actions << Action.summary end opts.on("-a", "--append", "Appends new strings to english localization file") do |n| actions << Action.append end opts.on("-e", "--export", "Creates xliff files with missing localization") do |n| actions << Action.export end opts.on("-i", "--import", "Looks for xliffs in project dir and imports whatever possible") do |n| actions << Action.import end opts.on("-f", "--create-config-file", "Create default `.lokale` config file") do |n| actions << Action.create_config end opts.on("-h", "--help", "Prints this help") do puts opts exit end end.parse! actions << Action.summary if actions.empty? @config = Config.new @config.actions = actions end |
Instance Method Details
#create_default_file ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/lokale/lokalefile.rb', line 49 def create_default_file if File.file? lokalefile_path puts "Config file `#{lokalefile_path.blue}` already exists." else File.write(lokalefile_path, DEFAULT_LOKALEFILE) puts "Created config file at `#{lokalefile_path.blue}`" end end |
#fill_defaults ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/lokale/lokalefile.rb', line 74 def fill_defaults default = Config.new default.read_default_config @macros ||= default.macros @main_lang ||= default.main_lang @base_lang ||= default.base_lang end |
#lokalefile_path ⇒ Object
59 60 61 |
# File 'lib/lokale/lokalefile.rb', line 59 def lokalefile_path File.join(@project_path, ".lokale") end |
#read_config_from_file(file_path) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/lokale/lokalefile.rb', line 42 def read_config_from_file(file_path) content = File.read(file_path) reset_config instance_eval(content) fill_defaults end |
#read_default_config ⇒ Object
37 38 39 40 |
# File 'lib/lokale/lokalefile.rb', line 37 def read_default_config reset_config instance_eval(DEFAULT_LOKALEFILE) end |
#read_lokalefile ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/lokale/lokalefile.rb', line 29 def read_lokalefile if File.file? lokalefile_path read_config_from_file(lokalefile_path) else read_default_config end end |
#reset_config ⇒ Object
68 69 70 71 72 |
# File 'lib/lokale/lokalefile.rb', line 68 def reset_config @macros = nil @main_lang = nil @base_lang = nil end |