Class: Frontline::Index
- Inherits:
-
E
- Object
- E
- Frontline::Index
- Includes:
- EL::Ace
- Defined in:
- lib/frontline/controllers/index.rb
Instance Method Summary collapse
-
#get_application ⇒ Object
set effective application session.
-
#get_applications ⇒ Object
displays a list of existing applications as well as a form to build/load new ones.
-
#get_file ⇒ Object
renders a source code editor for given file.
-
#get_streamer(uuid) ⇒ Object
backend for EventSource requests.
- #index ⇒ Object
-
#post_application__generate ⇒ Object
generates a brand new application and streaming result to browser.
-
#post_application__load ⇒ Object
check whether given folder contains a valid Espresso application.
-
#post_bundler(task = 'install') ⇒ Object
run given Bundler task and stream result to browser.
-
#post_git(command) ⇒ Object
run given Git task and stream result to browser.
-
#put_file ⇒ Object
updating given file with given content.
Instance Method Details
#get_application ⇒ Object
set effective application session. before setting session it is checking whether application given name exists and application path is a valid Espresso application root.
33 34 35 36 37 38 39 40 41 |
# 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 |
#get_applications ⇒ Object
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.
24 25 26 27 28 |
# File 'lib/frontline/controllers/index.rb', line 24 def get_applications session.delete :application clear_registry_cache! render :applications end |
#get_file ⇒ Object
renders a source code editor for given file. path to file are taken from ‘@file` variable set earlier by corresponding hook.
56 57 58 |
# File 'lib/frontline/controllers/index.rb', line 56 def get_file render_f 'editor.slim' end |
#get_streamer(uuid) ⇒ Object
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.
47 48 49 50 51 52 |
# 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 |
#index ⇒ Object
16 17 18 |
# File 'lib/frontline/controllers/index.rb', line 16 def index get_applications end |
#post_application__generate ⇒ Object
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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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 |
#post_application__load ⇒ Object
check whether given folder contains a valid Espresso application
106 107 108 109 110 111 112 113 |
# 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 |
#post_bundler(task = 'install') ⇒ Object
run given Bundler task and stream result to browser.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 |
#post_git(command) ⇒ Object
run given Git task and stream result to browser.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# 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' = params[:message] || halt(400, 'Can not deploy without a deploy message') cmd = 'git add . && git commit -am "%s"' % .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 |
#put_file ⇒ Object
updating given file with given content. path to file are taken from ‘@file` variable set earlier by corresponding hook.
62 63 64 |
# File 'lib/frontline/controllers/index.rb', line 62 def put_file File.open(@file, 'w') {|f| f << params[:content]} end |