lunar_shell 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a73b7e46f828543f4db5cf0e02dbda8d89e31b64
4
- data.tar.gz: 39bffe232f768b73b812a94494ca4e5cc01f257a
3
+ metadata.gz: cefb1c858a8b4dca7f75fc5b058924f1e4e067ea
4
+ data.tar.gz: 8166dc6a4bf78373c2c817480fe70e20d32f2da1
5
5
  SHA512:
6
- metadata.gz: 420fafe926a111d3983ad8c7a6a2aaff65db3c8f51bb88cc6ce51a3cf39892cfdfb34f9b34b2d5785464032ad9d282c397299284b1459bb1dedcc8e0d169872b
7
- data.tar.gz: e2f34f1a349eb2c1f6946a1088fb2beb4bd825bbaae0d8671f5360789d9da69b6f12c7def27e0775c19bba15598a7bf9f696478f6cc842e86f88d932d4ecb05e
6
+ metadata.gz: 714ae445a5805758b6c819013a9571ff83279436f7a3c6a6a19d91a2d6ed66574ad0833a611c41898396d0a5a3e3253192704d295021ff9417d46fdad2425441
7
+ data.tar.gz: 6150bc84fb0a45d494570567dad1fc16150b7fee1babde11a6ab7bf936fff001764660b4ea41d4744ec9766658023ec4fee554cef94a62effdd984777d642e1c
@@ -5,12 +5,7 @@ module LunarShell
5
5
  before_action :log_command!
6
6
 
7
7
  def run
8
- render 'no_command'
9
- end
10
-
11
- def error
12
8
  render 'no_command' and return unless command
13
- render 'clear' and return if command == 'clear'
14
9
  render 'command_not_found'
15
10
  end
16
11
 
@@ -30,6 +25,11 @@ module LunarShell
30
25
  end
31
26
  helper_method :parameters
32
27
 
28
+ def parameters?
29
+ parameters.present?
30
+ end
31
+ helper_method :parameters?
32
+
33
33
  def log_command!
34
34
  return if !command || command == 'history'
35
35
  session[:history] << "#{command} #{parameters.try :join, ' '}".strip
data/config/routes.rb CHANGED
@@ -10,8 +10,11 @@ LunarShell::Engine.routes.draw do
10
10
  end
11
11
  resource :quit, only: []
12
12
  resource :su, only: [:create]
13
+
14
+ # catch all
15
+ post '*error', action: 'run'
16
+ post :run
13
17
  end
14
- post 'satellites/*error', to: 'satellites#error'
15
18
 
16
19
  root 'shells#show'
17
20
  end
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Creates a new Lunar shell satellite
3
+
4
+ Example:
5
+ rails generate lunar_shell:satellite thing
6
+
7
+ This will create:
8
+ app/controllers/lunar_shell/satellites/thing_controller.rb
9
+ app/views/lunar_shell/satellites/thing/run.js.erb
10
+
11
+ And add this route:
12
+ namespace :satellites do
13
+ resource :thing, only: []
14
+ end
@@ -0,0 +1,72 @@
1
+ module LunarShell
2
+ class SatelliteGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ class_option :include_test, aliases: '-t', desc: 'Include test file'
6
+
7
+ def copy_satellite_files
8
+ template 'controller.rb', controller_path
9
+ template 'view.rb', view_path
10
+ template 'test.rb', test_path if options[:include_test]
11
+ end
12
+
13
+ def add_route
14
+ satellite_route singular_name
15
+ end
16
+
17
+ private
18
+
19
+ def base_path(type)
20
+ "app/#{type}/lunar_shell/satellites/#{singular_name}"
21
+ end
22
+
23
+ def controller_path
24
+ "#{base_path :controllers}_controller.rb"
25
+ end
26
+
27
+ def test_path
28
+ "test/integration/#{singular_name}_test.rb"
29
+ end
30
+
31
+ def view_path
32
+ "#{base_path :views}/run.js.erb"
33
+ end
34
+
35
+ def satellite_route(name)
36
+ route = "resource :#{name}, only: []\n"
37
+ log :route, route.strip
38
+
39
+ scopes = [{sentinel: /\.routes\.draw do\s*\n/m}]
40
+
41
+ mp = LunarShell::Engine.mount_path.gsub(/^\//, '')
42
+ scopes << satellite_scope("scope :#{mp}", scopes.count) if mp.present?
43
+
44
+ ["scope module: :lunar_shell", 'namespace :satellites'].each do |name|
45
+ scopes << satellite_scope(name, scopes.count)
46
+ end
47
+
48
+ scopes << { name: "#{' ' * scopes.count}#{route}" }
49
+
50
+ in_root do
51
+ scopes.drop(1).each_with_index do |scope, i|
52
+ content = File.binread("#{destination_root}/config/routes.rb")
53
+ next if content =~ scope[:sentinel]
54
+ inject_into_file 'config/routes.rb',
55
+ scope[:name],
56
+ after: scopes[i][:sentinel],
57
+ verbose: false
58
+ end
59
+ end
60
+ end
61
+
62
+ def satellite_scope(name, level = 0)
63
+ spaces = ' ' * level
64
+ scope_start = "#{spaces}#{name} do\n"
65
+ scope_end = "#{spaces}end\n"
66
+ {
67
+ name: "#{scope_start}#{scope_end}",
68
+ sentinel: /^#{scope_start}/m
69
+ }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,8 @@
1
+ module LunarShell
2
+ module Satellites
3
+ class <%= class_name %>Controller < LunarShell::SatellitesController
4
+ def run
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < SatelliteIntegrationTest
4
+ test "<%= singular_name %>" do
5
+ run_command '<%= singular_name %>'
6
+ page.has_content? 'Just ran "<%= singular_name %>"!'
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ $('#shell-history').append('<div class="output">Just ran "<%= singular_name %>"!</div>');
2
+ $('#shell-cli').html('<%%= j render('lunar_shell/shells/cli') %>');
@@ -5,5 +5,23 @@ module LunarShell
5
5
  initializer 'lunar_shell.add_middleware' do |app|
6
6
  app.middleware.insert_after Rack::ETag, LunarShell::Middleware::Interpreter
7
7
  end
8
+
9
+ initializer "lunar_shell.assets.precompile" do |app|
10
+ app.config.assets.precompile += %w(lunar_shell.coffee lunar_shell.sass)
11
+ end
12
+
13
+ config.app_generators.satellite :satellite
14
+
15
+ def mount_path
16
+ @mount_path ||= routes.url_helpers.root_path[0..-2]
17
+ end
18
+
19
+ def run_command_path(command)
20
+ run_path.gsub('run', "#{command}/run")
21
+ end
22
+
23
+ def run_path
24
+ @run_path ||= routes.url_helpers.satellites_run_path
25
+ end
8
26
  end
9
27
  end
@@ -16,7 +16,7 @@ module LunarShell
16
16
  request.update_param('parameters', params) if params.any?
17
17
  request.update_param('command', command)
18
18
 
19
- env['PATH_INFO'] = "/satellites/#{command}/run"
19
+ env['PATH_INFO'] = LunarShell::Engine.run_command_path(command)
20
20
  end
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  module LunarShell
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -131599,3 +131599,14 @@ Started GET "/assets/lunar_shell/satellites/su.self-626d3eb61573185dcf5a0a5e7c8a
131599
131599
 
131600
131600
 
131601
131601
  Started GET "/assets/lunar_shell/application.self-377610cd7c1509e934744c810e3b4cf672dfbcacac3274e7d039827e2ae0fcc7.js?body=1" for ::1 at 2016-06-25 01:50:55 -0700
131602
+
131603
+
131604
+ Started POST "/satellites/run" for ::1 at 2016-06-25 02:07:33 -0700
131605
+ Processing by LunarShell::SatellitesController#error as JS
131606
+ Parameters: {"utf8"=>"✓", "command"=>"backspin", "error"=>"backspin/run"}
131607
+ Rendered /Users/dave/Playground/lunar_shell/app/views/lunar_shell/satellites/_command_not_found.html.erb (0.1ms)
131608
+ LunarShell::User Load (0.3ms) SELECT "lunar_shell_users".* FROM "lunar_shell_users" WHERE (id = NULL OR username = NULL) ORDER BY "lunar_shell_users"."id" ASC LIMIT 1
131609
+ Rendered /Users/dave/Playground/lunar_shell/app/views/lunar_shell/shells/_prompt.html.erb (1.1ms)
131610
+ Rendered /Users/dave/Playground/lunar_shell/app/views/lunar_shell/shells/_cli.html.erb (14.5ms)
131611
+ Rendered /Users/dave/Playground/lunar_shell/app/views/lunar_shell/satellites/command_not_found.js.erb (39.3ms)
131612
+ Completed 200 OK in 57ms (Views: 56.0ms | ActiveRecord: 0.3ms)