Class: I18nYamlEditor::App
- Inherits:
-
Object
- Object
- I18nYamlEditor::App
- Defined in:
- lib/i18n_yaml_editor/app.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(path) ⇒ App
constructor
A new instance of App.
- #load_translations ⇒ Object
- #save_translations ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(path) ⇒ App
Returns a new instance of App.
12 13 14 15 16 |
# File 'lib/i18n_yaml_editor/app.rb', line 12 def initialize path @path = File.(path) @store = Store.new I18nYamlEditor.app = self end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
18 19 20 |
# File 'lib/i18n_yaml_editor/app.rb', line 18 def store @store end |
Instance Method Details
#load_translations ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/i18n_yaml_editor/app.rb', line 31 def load_translations files = Dir[@path + "/**/*.yml"] files.each {|file| yaml = YAML.load_file(file) store.from_yaml(yaml, file) } end |
#save_translations ⇒ Object
39 40 41 42 43 44 |
# File 'lib/i18n_yaml_editor/app.rb', line 39 def save_translations files = store.to_yaml files.each {|file, yaml| File.open(file, "w", encoding: "utf-8") {|f| f << yaml.to_yaml} } end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i18n_yaml_editor/app.rb', line 20 def start $stdout.puts " * Loading translations from #{@path}" load_translations $stdout.puts " * Creating missing translations" store.create_missing_keys $stdout.puts " * Starting web editor at port 5050" Rack::Server.start :app => Web, :Port => 5050 end |