class Frontline::Index
Public Instance Methods
set effective application session. before setting session it is checking whether application given name exists and application path is a valid Espresso application root.
# File lib/frontline/controllers/index.rb, line 33 def get_application application = applications.find {|(name)| name == params[:name]} || styled_halt(500, '"%s" application does not exists' % escape_html(params[:name])) Enginery::Generator.new(application[1]).in_app_folder? || styled_halt(500, '"%s" does not look like a Espresso application' % escape_html(application[1])) session[:application] = application clear_registry_cache! redirect Frontline::Controllers.base_url end
displays a list of existing applications as well as a form to build/load new ones. also it will clear controllers and models cache and unset effective application session.
# File lib/frontline/controllers/index.rb, line 24 def get_applications session.delete :application clear_registry_cache! render :applications end
renders a source code editor for given file. path to file are taken from `@file` variable set earlier by corresponding hook.
# File lib/frontline/controllers/index.rb, line 56 def get_file render_f 'editor.slim' end
backend for EventSource requests. it is storing the socket into memory so it can be used later to send data to browser. sockets are identified by the given ID.
# File lib/frontline/controllers/index.rb, line 47 def get_streamer uuid evented_stream do |s| STREAMS[uuid] = s s.errback { STREAMS.delete uuid } end end
# File lib/frontline/controllers/index.rb, line 16 def index get_applications end
generates a brand new application and streaming result to browser.
required params:
:uuid for streaming to work the UUID of a socket that was earlier set via `get_streamer` is required. :name application name to be used within Frontline. basically a unique label that will allow users to identify apps by. :path full path to the folder that will hold generated application. if it is a existing folder it should be empty. if given folder does not exists it will be created. :preview_url the root URL generated application will be available on. used to preview generated routes.
# File lib/frontline/controllers/index.rb, line 83 def post_application__generate @uuid = params.delete('uuid') name, path, preview_url = params.values_at(:name, :path, :preview_url) FileUtils.mkdir_p path settings = Rack::Utils.parse_nested_query(params[:settings]) settings['host'] = settings[:host].to_s.strip.split*',' input = settings.reject {|k,v| v.to_s.strip.empty?}.map {|kv| kv*':' }*' ' stream do pty_stream 'modal', 'show' cmd = '%s g %s' % [Enginery::EXECUTABLE, input] passed, failure_id = pty_spawn(cmd, root: path) if passed pty_stream 'persist_application', stringify_application(name, path, preview_url) pty_stream 'reload' else pty_stream 'failures', failure_id end end end
check whether given folder contains a valid Espresso application
# File lib/frontline/controllers/index.rb, line 106 def post_application__load path = params[:path].to_s File.directory?(path) || halt(400, '"%s" should be a directory' % escape_html(path)) Enginery::Generator.new(path).in_app_folder? || halt(400, '"%s" does not look like a Espresso application root' % escape_html(path)) true end
run given Bundler task and stream result to browser.
# File lib/frontline/controllers/index.rb, line 116 def post_bundler task = 'install' %w[install update].include?(task) || halt(400, 'Unknown bundle task "%s"' % escape_html(task)) @uuid = params.delete('uuid') cmd = 'bundle ' + task stream do pty_stream 'modal', 'show' passed, failure_id = pty_spawn(cmd) if passed pty_stream 'modal', 'hide' else pty_stream 'failures', failure_id end end end
run given Git task and stream result to browser.
# File lib/frontline/controllers/index.rb, line 136 def post_git command case command when 'init' cmd = 'git init' when 'origin' url = params[:url] || halt(400, 'Please provide remote URL') cmd = 'git remote add origin "%s"' % url.gsub('"', '\"') when 'commit' message = params[:message] || halt(400, 'Can not deploy without a deploy message') cmd = 'git add . && git commit -am "%s"' % message.gsub('"', '\"') when 'push' cmd = 'git push' else halt(400, 'Unknown command "%s"' % command) end @uuid = params.delete('uuid') stream do pty_stream 'modal', 'show' passed, failure_id = pty_spawn(cmd) if passed pty_stream 'modal', 'hide' else pty_stream 'failures', failure_id end end end
updating given file with given content. path to file are taken from `@file` variable set earlier by corresponding hook.
# File lib/frontline/controllers/index.rb, line 62 def put_file File.open(@file, 'w') {|f| f << params[:content]} end