Class: Frontline::Controllers

Inherits:
E
  • Object
show all
Includes:
EL::Ace
Defined in:
lib/frontline/controllers/controllers.rb

Instance Method Summary collapse

Instance Method Details

#delete_controllerObject

return a command that will delete given controller. ‘@name` variable are set by the triggered hooks(see frontline/app.rb for hooks)



27
28
29
# File 'lib/frontline/controllers/controllers.rb', line 27

def delete_controller
  'delete:controller:yes %s' % @name
end

#delete_route(controller) ⇒ Object

return a command that will delete the given route of given controller. ‘@name` variable are set by the triggered hooks(see frontline/app.rb for hooks)



39
40
41
# File 'lib/frontline/controllers/controllers.rb', line 39

def delete_route controller
  'delete:route:yes %s %s' % [controller, @name]
end

#get_route_editor(controller, route) ⇒ Object

renders a editor for given route. editor will allow to edit the route file, the route views and the route specs



8
9
10
11
12
13
14
15
16
17
# File 'lib/frontline/controllers/controllers.rb', line 8

def get_route_editor controller, route
  @controller = controllers[controller] ||
    halt(400, '"%s" controller not found' % escape_html(controller))
  @route = (@controller[:routes].find {|(n)| n == route} ||
    halt(400, '"%s#%s" route not found' % [controller, escape_html(route)])).last
  @files = ([@route[:file]] + @route[:views] + @route[:specs]).inject([]) do |m,f|
    m << [f, File.basename(f), f.gsub(/\W/, '_'), f == @route[:file]]
  end
  render_p action_name
end

#post_controllerObject

return a command that will generate a new controller. ‘@name` and `@setups` variables are set by the triggered hooks(see frontline/app.rb for hooks)



21
22
23
# File 'lib/frontline/controllers/controllers.rb', line 21

def post_controller
  'g:c %s %s' % [@name, @setups]
end

#post_route(controller) ⇒ Object

return a command that will generate a new route for given controller. ‘@name` and `@setups` variables are set by the triggered hooks(see frontline/app.rb for hooks)



33
34
35
# File 'lib/frontline/controllers/controllers.rb', line 33

def post_route controller
  'g:r %s %s %s' % [controller, @name, @setups]
end

#post_run_specsObject

run specs for given controllers or for all if no controllers given and stream results to browser.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/frontline/controllers/controllers.rb', line 45

def post_run_specs
  @uuid = params[:uuid]
  controllers = (c = params[:controller]) ? [c] : controllers().keys
  stream do
    failed = false
    pty_stream 'modal', 'show'

    controllers.each do |controller|
      cmd = 'bundle exec rake test:' << controller
      passed, failure_id = pty_spawn(cmd)
      unless passed
        failed = true
        pty_stream 'failures', failure_id
      end
    end
    pty_stream 'modal', 'hide' unless failed
  end
end

#route_layout(controller) ⇒ Object



64
65
66
67
68
# File 'lib/frontline/controllers/controllers.rb', line 64

def route_layout controller
  controller = controllers[controller] ||
    halt(400, '"%s" controller does not exists' % escape_html(controller))
  render_p controller: controller
end