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.
23 24 25 |
# File 'lib/lokale/config.rb', line 23 def actions @actions end |
#base_lang ⇒ Object (readonly)
Returns the value of attribute base_lang.
67 68 69 |
# File 'lib/lokale/lokalefile.rb', line 67 def base_lang @base_lang end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
66 67 68 |
# File 'lib/lokale/lokalefile.rb', line 66 def macros @macros end |
#main_lang ⇒ Object (readonly)
Returns the value of attribute main_lang.
67 68 69 |
# File 'lib/lokale/lokalefile.rb', line 67 def main_lang @main_lang end |
#project_name ⇒ Object
Returns the value of attribute project_name.
24 25 26 |
# File 'lib/lokale/config.rb', line 24 def project_name @project_name end |
#project_path ⇒ Object
Returns the value of attribute project_path.
24 25 26 |
# File 'lib/lokale/config.rb', line 24 def project_path @project_path end |
Class Method Details
.get ⇒ Object
74 75 76 77 |
# File 'lib/lokale/config.rb', line 74 def self.get init if @config.nil? @config end |
.init ⇒ Object
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 68 69 70 71 72 |
# File 'lib/lokale/config.rb', line 26 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("-p", "--add-to-project", "Creates project strings file") do |n| actions << Action.add_to_proj 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
50 51 52 53 54 55 56 57 58 |
# File 'lib/lokale/lokalefile.rb', line 50 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
75 76 77 78 79 80 81 82 |
# File 'lib/lokale/lokalefile.rb', line 75 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
60 61 62 |
# File 'lib/lokale/lokalefile.rb', line 60 def lokalefile_path File.join(@project_path, ".lokale") end |
#read_config_from_file(file_path) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/lokale/lokalefile.rb', line 43 def read_config_from_file(file_path) content = File.read(file_path) reset_config instance_eval(content) fill_defaults end |
#read_default_config ⇒ Object
38 39 40 41 |
# File 'lib/lokale/lokalefile.rb', line 38 def read_default_config reset_config instance_eval(DEFAULT_LOKALEFILE) end |
#read_lokalefile ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lokale/lokalefile.rb', line 30 def read_lokalefile if File.file? lokalefile_path read_config_from_file(lokalefile_path) else read_default_config end end |
#reset_config ⇒ Object
69 70 71 72 73 |
# File 'lib/lokale/lokalefile.rb', line 69 def reset_config @macros = nil @main_lang = nil @base_lang = nil end |