Class: I18n::Edit::EditController

Inherits:
ApplicationController show all
Defined in:
app/controllers/i18n/edit/edit_controller.rb

Instance Method Summary collapse

Instance Method Details

#check_tokenObject



96
97
98
# File 'app/controllers/i18n/edit/edit_controller.rb', line 96

def check_token
  render plain: 'OK', status: 200, layout: false
end


100
101
102
103
104
105
# File 'app/controllers/i18n/edit/edit_controller.rb', line 100

def menu
  @style = "top: #{params[:y]}px; left: #{params[:x]}px;"
  @i18n = JSON.parse(params[:i18n])

  render 'menu', layout: false
end

#updateObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/i18n/edit/edit_controller.rb', line 107

def update
  key = params[:key]
  text = params[:text]
  old_text = params[:old_text]
  path = KeyLocations[key.to_sym]
  
  if text.gsub(/\s/, '').blank?
    render plain: "Erasing the entire locale text isn't allowed.", layout: false, status: 202
    return
  end
  
  if path.nil?
    render plain: "No locale file in your project for #{key}, your edit was not written.", layout: false, status: 201
    return
  end
  
  return if !write_file(path, key, old_text, text)
  
  message = "Wrote #{path} for #{key}"
  logger.info(message)
  render plain: message, layout: false, status: 200
end