vedeu_cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rubocop.yml +182 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/.yardopts +4 -0
  7. data/Gemfile +4 -0
  8. data/Guardfile +8 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +66 -0
  11. data/Rakefile +10 -0
  12. data/config/rubocop_disabled.yml +50 -0
  13. data/config/rubocop_enabled.yml +1039 -0
  14. data/lib/vedeu/cli/application.rb +133 -0
  15. data/lib/vedeu/cli/helpers.rb +139 -0
  16. data/lib/vedeu/cli/main.rb +39 -0
  17. data/lib/vedeu/cli/templates/application/.gitignore +1 -0
  18. data/lib/vedeu/cli/templates/application/.ruby-version +1 -0
  19. data/lib/vedeu/cli/templates/application/Gemfile +4 -0
  20. data/lib/vedeu/cli/templates/application/LICENSE.txt +24 -0
  21. data/lib/vedeu/cli/templates/application/README.md +18 -0
  22. data/lib/vedeu/cli/templates/application/app/controllers/application_controller.erb +7 -0
  23. data/lib/vedeu/cli/templates/application/app/controllers/name.erb +22 -0
  24. data/lib/vedeu/cli/templates/application/app/helpers/application_helper.erb +9 -0
  25. data/lib/vedeu/cli/templates/application/app/helpers/name.erb +11 -0
  26. data/lib/vedeu/cli/templates/application/app/models/keymaps/_global_.rb +8 -0
  27. data/lib/vedeu/cli/templates/application/app/models/keymaps/name.erb +3 -0
  28. data/lib/vedeu/cli/templates/application/app/views/interfaces/name.erb +67 -0
  29. data/lib/vedeu/cli/templates/application/app/views/name.erb +36 -0
  30. data/lib/vedeu/cli/templates/application/app/views/templates/name.erb +0 -0
  31. data/lib/vedeu/cli/templates/application/application.erb +22 -0
  32. data/lib/vedeu/cli/templates/application/bin/name +9 -0
  33. data/lib/vedeu/cli/templates/application/config/app_name.erb +1 -0
  34. data/lib/vedeu/cli/templates/application/config/configuration.erb +33 -0
  35. data/lib/vedeu/cli/templates/application/lib/.gitkeep +0 -0
  36. data/lib/vedeu/cli/templates/application/test/.gitkeep +0 -0
  37. data/lib/vedeu/cli/templates/application/vendor/.gitkeep +0 -0
  38. data/lib/vedeu/cli/version.rb +10 -0
  39. data/lib/vedeu/cli/view.rb +86 -0
  40. data/lib/vedeu_cli.rb +21 -0
  41. data/test/lib/vedeu/cli/application_test.rb +37 -0
  42. data/test/lib/vedeu/cli/helpers_test.rb +197 -0
  43. data/test/lib/vedeu/cli/main_test.rb +60 -0
  44. data/test/lib/vedeu/cli/version_test.rb +12 -0
  45. data/test/lib/vedeu/cli/view_test.rb +38 -0
  46. data/test/lib/vedeu_cli_test.rb +11 -0
  47. data/test/test_helper.rb +46 -0
  48. data/vedeu_cli.gemspec +36 -0
  49. metadata +288 -0
@@ -0,0 +1,133 @@
1
+ module Vedeu
2
+
3
+ module CLI
4
+
5
+ # Generates the client application directory and file structure.
6
+ #
7
+ # @example
8
+ # ```bash
9
+ # vedeu new your_app_name_here
10
+ # ```
11
+ #
12
+ # :nocov:
13
+ class Application
14
+
15
+ include Vedeu::CLI::Helpers
16
+
17
+ # @param name [String] The name of the application.
18
+ # @return [Vedeu::CLI::Application]
19
+ def self.generate(name)
20
+ new(name).generate
21
+ end
22
+
23
+ # Returns a new instance of Vedeu::CLI::Application.
24
+ #
25
+ # @param name [String] The name of the application.
26
+ # @return [Vedeu::CLI::Application]
27
+ def initialize(name)
28
+ @name = name
29
+ end
30
+
31
+ # @return [void]
32
+ def generate
33
+ make_directory_structure
34
+
35
+ copy_app_root_files
36
+ copy_application_bootstrapper
37
+ copy_application_controller
38
+ copy_application_helper
39
+ copy_global_keymap
40
+ copy_application_executable
41
+ make_application_executable
42
+ copy_configuration
43
+ copy_app_name
44
+ end
45
+
46
+ private
47
+
48
+ # @return [void]
49
+ def make_directory_structure
50
+ directories.each { |directory| make_directory(name + directory) }
51
+ end
52
+
53
+ # @return [void]
54
+ def copy_application_bootstrapper
55
+ make_file(source + '/application.erb',
56
+ app_root_path + '/application.rb')
57
+ end
58
+
59
+ # @return [void]
60
+ def copy_application_controller
61
+ make_file(source + '/app/controllers/application_controller.erb',
62
+ app_controllers_path + 'application_controller.rb')
63
+ end
64
+
65
+ # @return [void]
66
+ def copy_application_executable
67
+ copy_file(source + '/bin/name', app_bin_path + "#{name}")
68
+ end
69
+
70
+ # @return [void]
71
+ def copy_application_helper
72
+ make_file(source + '/app/helpers/application_helper.erb',
73
+ app_helpers_path + 'application_helper.rb')
74
+ end
75
+
76
+ # @return [void]
77
+ def copy_configuration
78
+ make_file(source + '/config/configuration.erb',
79
+ app_config_path + 'configuration.rb')
80
+ end
81
+
82
+ # @return [void]
83
+ def copy_app_name
84
+ make_file(source + '/config/app_name.erb',
85
+ app_config_path + 'app_name')
86
+ end
87
+
88
+ # @return [void]
89
+ def copy_app_root_files
90
+ [
91
+ '/Gemfile',
92
+ '/.gitignore',
93
+ '/LICENSE.txt',
94
+ '/README.md',
95
+ '/.ruby-version',
96
+ ].each do |file|
97
+ copy_file((source + file), (app_root_path + file))
98
+ end
99
+ end
100
+
101
+ # @return [void]
102
+ def make_application_executable
103
+ FileUtils.chmod(0755, "#{name}/bin/#{name}")
104
+ end
105
+
106
+ # @return [void]
107
+ def copy_global_keymap
108
+ copy_file(source + '/app/models/keymaps/_global_.rb',
109
+ app_keymaps_path + '_global_.rb')
110
+ end
111
+
112
+ # @return [Array<String>]
113
+ def directories
114
+ [
115
+ '/app/controllers',
116
+ '/app/helpers',
117
+ '/app/models/keymaps',
118
+ '/app/views/interfaces',
119
+ '/app/views/templates',
120
+ '/bin',
121
+ '/config',
122
+ '/lib',
123
+ '/test',
124
+ '/vendor',
125
+ ]
126
+ end
127
+
128
+ end # Application
129
+ # :nocov:
130
+
131
+ end # CLI
132
+
133
+ end # Vedeu
@@ -0,0 +1,139 @@
1
+ module Vedeu
2
+
3
+ module CLI
4
+
5
+ # Provides functionality used by the generators to build the client
6
+ # application.
7
+ #
8
+ # :nocov:
9
+ module Helpers
10
+
11
+ include Vedeu::Common
12
+
13
+ # @return [String]
14
+ def app_name
15
+ @app_name ||= File.read('./config/app_name')
16
+ end
17
+
18
+ # @return [String]
19
+ def app_bin_path
20
+ name + '/bin/'
21
+ end
22
+
23
+ # @return [String]
24
+ def app_config_path
25
+ name + '/config/'
26
+ end
27
+
28
+ # @return [String]
29
+ def app_controllers_path
30
+ name + '/app/controllers/'
31
+ end
32
+
33
+ # @return [String]
34
+ def app_helpers_path
35
+ name + '/app/helpers/'
36
+ end
37
+
38
+ # @return [String]
39
+ def app_models_path
40
+ name + '/app/models/'
41
+ end
42
+
43
+ # @return [String]
44
+ def app_keymaps_path
45
+ name + '/app/models/keymaps/'
46
+ end
47
+
48
+ # @return [String]
49
+ def app_views_path
50
+ name + '/app/views/'
51
+ end
52
+
53
+ # @param destination [String]
54
+ # @return [void]
55
+ def make_directory(destination)
56
+ Vedeu.log_stdout(type: :create, message: "#{destination}")
57
+
58
+ FileUtils.mkdir_p(destination)
59
+ end
60
+
61
+ # @param source [String]
62
+ # @param destination [String]
63
+ # @return [void]
64
+ def copy_file(source, destination)
65
+ if File.exist?(destination)
66
+ skipped_file(destination)
67
+
68
+ else
69
+ Vedeu.log_stdout(type: :create, message: "#{destination}")
70
+
71
+ FileUtils.cp(source, destination)
72
+ end
73
+ end
74
+
75
+ # @param source [String]
76
+ # @param destination [String]
77
+ # @return [void]
78
+ def make_file(source, destination)
79
+ if File.exist?(destination)
80
+ skipped_file(destination)
81
+
82
+ else
83
+ Vedeu.log_stdout(type: :create, message: "#{destination}")
84
+
85
+ File.write(destination, parse(source))
86
+ end
87
+ end
88
+
89
+ # @param destination [String]
90
+ # @return [void]
91
+ def skipped_file(destination)
92
+ Vedeu.log_stdout(type: :create,
93
+ message: "#{destination} " +
94
+ Esc.red { 'already exists, skipped.' })
95
+ end
96
+
97
+ # @param destination [String]
98
+ # @return [void]
99
+ def touch_file(destination)
100
+ Vedeu.log_stdout(type: :create, message: "#{destination}")
101
+
102
+ FileUtils.touch(destination)
103
+ end
104
+
105
+ # @return [String]
106
+ def name
107
+ @_name ||= @name.downcase
108
+ end
109
+ alias_method :app_root_path, :name
110
+
111
+ # @return [String]
112
+ def name_as_class
113
+ name.downcase.split(/_|-/).map(&:capitalize).join
114
+ end
115
+
116
+ # @return [String]
117
+ def output(message = '')
118
+ Vedeu.log_stdout(type: :info, message: message)
119
+
120
+ message
121
+ end
122
+
123
+ # @param source [String]
124
+ # @return [String]
125
+ def parse(source)
126
+ Vedeu::Templating::Template.parse(self, source)
127
+ end
128
+
129
+ # @return [String]
130
+ def source
131
+ File.dirname(__FILE__) + '/templates/application/.'
132
+ end
133
+
134
+ end # Helpers
135
+ # :nocov:
136
+
137
+ end # CLI
138
+
139
+ end # Vedeu
@@ -0,0 +1,39 @@
1
+ module Vedeu
2
+
3
+ # Provide a command line interface to Vedeu.
4
+ #
5
+ module CLI
6
+
7
+ # The main command line interface commands.
8
+ #
9
+ class Main < Thor
10
+
11
+ desc 'new <name>', 'Create a skeleton Vedeu client application.'
12
+ # @param name [String]
13
+ # @return [String]
14
+ def new(name)
15
+ say(Vedeu::CLI::Application.generate(name))
16
+ end
17
+
18
+ # 'Specify the interface name lowercase snakecase; e.g. main_interface'
19
+
20
+ desc 'view <name>',
21
+ 'Create a new interface within the client application.'
22
+ # @param name [String]
23
+ # @return [String]
24
+ def view(name)
25
+ Vedeu::CLI::View.generate(name)
26
+ end
27
+
28
+ desc 'version',
29
+ 'Print the version.'
30
+ # @return [String]
31
+ def version
32
+ say("vedeu #{Vedeu::VERSION} (vedeu_cli #{Vedeu::CLI::VERSION})")
33
+ end
34
+
35
+ end # Main
36
+
37
+ end # CLI
38
+
39
+ end # Vedeu
@@ -0,0 +1 @@
1
+ log/**/*
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'vedeu'
4
+ # gem 'ruby-prof' # uncomment when using the `debug!` configuration option.
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2014 Your Name Here
2
+
3
+ Note: You may wish to change this license to suit your legal needs.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # <%= object.name_as_class %>
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Dependencies
9
+
10
+ * Installation
11
+
12
+ * Configuration
13
+
14
+ * Runtime instructions
15
+
16
+ * How to contribute
17
+
18
+ * Author information
@@ -0,0 +1,7 @@
1
+ module <%= object.name_as_class %>
2
+
3
+ class ApplicationController < Vedeu::ApplicationController
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'application_controller'
2
+ require_relative '../views/<%= object.name %>'
3
+
4
+ module <%= object.app_name %>
5
+
6
+ class <%= object.name_as_class %>Controller < <%= object.app_name -%>::ApplicationController
7
+
8
+ controller :<%= object.name %>
9
+ action :list
10
+ action :show
11
+ # add more actions and implement or remove existing actions
12
+
13
+ def list
14
+ end
15
+
16
+ def show
17
+ <%= object.app_name %>::<%= object.name_as_class %>View.render(params)
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,9 @@
1
+ module <%= object.name_as_class %>
2
+
3
+ module ApplicationHelper
4
+
5
+ include Vedeu::ApplicationHelper
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'application_helper'
2
+
3
+ module <%= object.app_name %>
4
+
5
+ module <%= object.name_as_class %>Helper
6
+
7
+ include <%= object.app_name -%>::ApplicationHelper
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ Vedeu.keymap('_global_') do
2
+ # see http://www.rubydoc.info/gems/vedeu/Vedeu/DSL/Keymap
3
+
4
+ key('q') { Vedeu.trigger(:_exit_) }
5
+ key(:esc) { Vedeu.trigger(:_mode_switch_) }
6
+ key(:shift_tab) { Vedeu.trigger(:_focus_previous_) }
7
+ key(:tab) { Vedeu.trigger(:_focus_next_) }
8
+ end
@@ -0,0 +1,3 @@
1
+ Vedeu.keymap('<%= object.name %>') do
2
+ # see http://www.rubydoc.info/gems/vedeu/Vedeu/DSL/Keymap
3
+ end
@@ -0,0 +1,67 @@
1
+ Vedeu.interface '<%= object.name %>' do
2
+ # border do
3
+ # Define colour and style of border
4
+ # colour foreground: '#ffffff', background: '#000000'
5
+ # style 'normal'
6
+
7
+ # Define visibility of border
8
+ #
9
+ # Uncomment one of these:
10
+ # enable!
11
+ # disable!
12
+ #
13
+ # Individually control each border:
14
+ # hide_bottom!
15
+ # hide_left!
16
+ # hide_right!
17
+ # hide_top!
18
+ # show_bottom!
19
+ # show_left!
20
+ # show_right!
21
+ # show_top!
22
+
23
+ # Define characters used to draw border
24
+ # bottom_right '+'
25
+ # bottom_left '+'
26
+ # horizontal '-'
27
+ # top_right '+'
28
+ # top_left '+'
29
+ # vertical '|'
30
+
31
+ # Define the title of the interface
32
+ # title '<%= object.name %>'
33
+ # end
34
+
35
+ # background
36
+
37
+ # colour
38
+
39
+ # cursor!
40
+
41
+ # See Vedeu::DSL::Interface#delay
42
+ # delay 1.0
43
+
44
+ # focus!
45
+
46
+ # foreground
47
+
48
+ # geometry do
49
+ # centred!
50
+ # x 1
51
+ # y 1
52
+ # xn 11
53
+ # yn 11
54
+ # height 10
55
+ # width 10
56
+ # end
57
+
58
+ # group ''
59
+
60
+ # hide!
61
+
62
+ # show!
63
+
64
+ # style
65
+
66
+ # zindex
67
+ end
@@ -0,0 +1,36 @@
1
+ module <%= object.app_name %>
2
+
3
+ class <%= object.name_as_class %>View < Vedeu::ApplicationView
4
+
5
+ def render
6
+ Vedeu.renders do
7
+
8
+ # Build up the view programmatically...
9
+ #
10
+ # view '<%= object.name %>' do
11
+ # lines do
12
+ # line 'some content...'
13
+ # end
14
+ # end
15
+
16
+ # ...or use the template in 'app/views/templates/<%= object.name %>'
17
+ #
18
+ template_for('<%= object.name %>',
19
+ template('<%= object.name %>'),
20
+ object,
21
+ options)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def object
28
+ end
29
+
30
+ def options
31
+ {}
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'config/configuration'
2
+ # When manually setting the entry point below, uncomment this line:
3
+ # require_relative 'app/controllers/some_controller'
4
+
5
+ module <%= object.name_as_class %>
6
+
7
+ class Application
8
+
9
+ # Change this to be the controller you would like to start the
10
+ # application from.
11
+ #
12
+ # def self.entry_point
13
+ # <%= object.name_as_class %>::SomeController.new
14
+ # end
15
+
16
+ # Vedeu::Bootstrap.start(ARGV, entry_point)
17
+
18
+ Vedeu::Bootstrap.start(ARGV)
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
+
5
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
6
+
7
+ require 'vedeu'
8
+
9
+ require_relative '../application'
@@ -0,0 +1 @@
1
+ <%= object.name_as_class -%>
@@ -0,0 +1,33 @@
1
+ Vedeu.configure do
2
+ # base_path
3
+
4
+ # colour_mode 16_777_216 # Some terminals don't render colour at all when this
5
+ # value is not one of 8, 16, 256 or 16777216.
6
+
7
+ # compression false
8
+
9
+ # debug! # Requires "gem 'ruby-prof'" in your Gemfile.
10
+ # drb!
11
+ # drb_host 'localhost'
12
+ # drb_port 21420
13
+ # drb_width 80
14
+ # drb_height 25
15
+
16
+ # terminal_mode :raw
17
+ # cooked!
18
+ # raw!
19
+
20
+ log "/tmp/<%= object.name %>.log"
21
+
22
+ # renderers
23
+
24
+ # run_once!
25
+
26
+ # interactive!
27
+ # standalone!
28
+
29
+ # Not used yet
30
+ # stdin File.open("/dev/tty", "r")
31
+ # stdout File.open("/dev/tty", "w")
32
+ # stderr File.open("/tmp/vedeu_error.log", "w+")
33
+ end
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ module Vedeu
2
+
3
+ module CLI
4
+
5
+ # The current version of Vedeu CLI.
6
+ VERSION = '0.0.1'
7
+
8
+ end # CLI
9
+
10
+ end # Vedeu