Class: Moirai::TranslationFilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/moirai/translation_files_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate

Instance Method Details

#create_or_updateObject



22
23
24
25
26
27
28
# File 'app/controllers/moirai/translation_files_controller.rb', line 22

def create_or_update
  if (translation = Translation.find_by(key: translation_params[:key], locale: translation_params[:locale]))
    handle_update(translation)
  else
    handle_create
  end
end

#indexObject



6
7
8
9
10
11
12
13
14
# File 'app/controllers/moirai/translation_files_controller.rb', line 6

def index
  @files = @file_handler.file_paths.map do |path|
    {
      id: Digest::SHA256.hexdigest(path),
      name: File.basename(path),
      path: path
    }
  end
end

#open_prObject



30
31
32
33
34
35
# File 'app/controllers/moirai/translation_files_controller.rb', line 30

def open_pr
  flash.notice = "I created an amazing Pull Request"
  changes = Moirai::TranslationDumper.new.call
  Moirai::PullRequestCreator.new.create_pull_request(changes)
  redirect_back_or_to(root_path)
end

#showObject



16
17
18
19
20
# File 'app/controllers/moirai/translation_files_controller.rb', line 16

def show
  @translation_keys = @file_handler.parse_file(@file_path)
  @locale = @file_handler.get_first_key(@file_path)
  @translations = Moirai::Translation.by_file_path(@file_path)
end