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,86 @@
1
+ module Vedeu
2
+
3
+ module CLI
4
+
5
+ # Generates a view for the client application.
6
+ #
7
+ # @example
8
+ # ```bash
9
+ # vedeu view main_screen
10
+ # ```
11
+ #
12
+ # :nocov:
13
+ class View
14
+
15
+ include Vedeu::CLI::Helpers
16
+
17
+ # @see Vedeu::CLI::View#initialize
18
+ def self.generate(name)
19
+ new(name).generate
20
+ end
21
+
22
+ # Returns a new instance of Vedeu::CLI::View.
23
+ #
24
+ # @param name [String] The name of the view.
25
+ # @return [Vedeu::CLI::View]
26
+ def initialize(name)
27
+ @name = name
28
+ end
29
+
30
+ # @return [void]
31
+ def generate
32
+ make_controller_file
33
+ make_helper_file
34
+ make_keymap_file
35
+ make_interface_file
36
+ make_template_file
37
+ make_view_class_file
38
+
39
+ output("Please update the 'root' setting in 'config/configuration.rb'" \
40
+ " to '#{app_name}::#{name_as_class}Controller.new' to start " \
41
+ 'Vedeu at this controller.')
42
+ end
43
+
44
+ private
45
+
46
+ # @return [void]
47
+ def make_controller_file
48
+ make_file(source + '/app/controllers/name.erb',
49
+ '.' + "/app/controllers/#{name}_controller.rb")
50
+ end
51
+
52
+ # @return [void]
53
+ def make_helper_file
54
+ make_file(source + '/app/helpers/name.erb',
55
+ '.' + "/app/helpers/#{name}_helper.rb")
56
+ end
57
+
58
+ # @return [void]
59
+ def make_keymap_file
60
+ make_file(source + '/app/models/keymaps/name.erb',
61
+ '.' + "/app/models/keymaps/#{name}.rb")
62
+ end
63
+
64
+ # @return [void]
65
+ def make_interface_file
66
+ make_file(source + '/app/views/interfaces/name.erb',
67
+ '.' + "/app/views/interfaces/#{name}.rb")
68
+ end
69
+
70
+ # @return [void]
71
+ def make_template_file
72
+ touch_file('.' + "/app/views/templates/#{name}.erb")
73
+ end
74
+
75
+ # @return [void]
76
+ def make_view_class_file
77
+ make_file(source + '/app/views/name.erb',
78
+ '.' + "/app/views/#{name}.rb")
79
+ end
80
+
81
+ end # View
82
+ # :nocov:
83
+
84
+ end # CLI
85
+
86
+ end # Vedeu
data/lib/vedeu_cli.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+ require 'vedeu'
3
+
4
+ require 'vedeu/cli/version'
5
+ require 'vedeu/cli/helpers'
6
+ require 'vedeu/cli/application'
7
+ require 'vedeu/cli/view'
8
+ require 'vedeu/cli/main'
9
+
10
+ # Vedeu is a GUI framework for terminal/console applications written in Ruby.
11
+ #
12
+ module Vedeu
13
+
14
+ # Vedeu plugin to provide the mechanism to build client application code
15
+ # suitable for use with Vedeu.
16
+ #
17
+ module CLI
18
+
19
+ end # CLI
20
+
21
+ end # Vedeu
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module CLI
6
+
7
+ describe Application do
8
+
9
+ let(:described) { Vedeu::CLI::Application }
10
+ let(:instance) { described.new(_name) }
11
+ let(:_name) { 'my_first_app' }
12
+
13
+ describe '#initialize' do
14
+ it { instance.must_be_instance_of(described) }
15
+ it { instance.instance_variable_get('@name').must_equal(_name) }
16
+ end
17
+
18
+ describe '.generate' do
19
+ # before do
20
+ # FileUtils.stubs(:cp_r)
21
+ # FileUtils.stubs(:mkdir)
22
+ # end
23
+
24
+ subject { instance.generate(_name) }
25
+
26
+ # @todo Add more tests.
27
+ end
28
+
29
+ describe '#generate' do
30
+ it { instance.must_respond_to(:generate) }
31
+ end
32
+
33
+ end # Application
34
+
35
+ end # CLI
36
+
37
+ end # Vedeu
@@ -0,0 +1,197 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module CLI
6
+
7
+ class HelpersTestClass
8
+
9
+ include Vedeu::CLI::Helpers
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+
15
+ end # HelpersTestClass
16
+
17
+ describe Helpers do
18
+
19
+ let(:described) { Vedeu::CLI::Helpers }
20
+ let(:instance) { Vedeu::CLI::HelpersTestClass.new(_name) }
21
+ let(:_name) { 'my_first_app' }
22
+
23
+ describe '#app_name' do
24
+ before { File.stubs(:read).returns('MyFirstApp') }
25
+
26
+ subject { instance.app_name }
27
+
28
+ it { subject.must_equal('MyFirstApp') }
29
+ end
30
+
31
+ describe '#make_directory' do
32
+ let(:destination) {}
33
+
34
+ before { Vedeu.stubs(:log_stdout) }
35
+
36
+ subject { instance.make_directory(destination) }
37
+
38
+ it {
39
+ FileUtils.expects(:mkdir_p).with(destination)
40
+ subject
41
+ }
42
+ end
43
+
44
+ describe '#copy_file' do
45
+ let(:source) {}
46
+ let(:destination) {}
47
+
48
+ before {
49
+ File.stubs(:exist?).returns(false)
50
+ Vedeu.stubs(:log_stdout)
51
+ }
52
+
53
+ subject { instance.copy_file(source, destination) }
54
+
55
+ context 'when the file exists' do
56
+ before { File.stubs(:exist?).returns(true) }
57
+
58
+ it {
59
+ Vedeu.expects(:log_stdout)
60
+ subject
61
+ }
62
+ end
63
+
64
+ context 'when the file does not exist' do
65
+ it {
66
+ FileUtils.expects(:cp).with(source, destination)
67
+ subject
68
+ }
69
+ end
70
+ end
71
+
72
+ describe '#make_file' do
73
+ let(:source) {}
74
+ let(:destination) {}
75
+
76
+ before {
77
+ File.stubs(:exist?).returns(false)
78
+ Vedeu.stubs(:log_stdout)
79
+ }
80
+
81
+ subject { instance.make_file(source, destination) }
82
+
83
+ context 'when the file exists' do
84
+ before { File.stubs(:exist?).returns(true) }
85
+
86
+ it {
87
+ Vedeu.expects(:log_stdout)
88
+ subject
89
+ }
90
+ end
91
+
92
+ context 'when the file does not exist' do
93
+ # @todo Add more tests.
94
+ # it { skip }
95
+ end
96
+ end
97
+
98
+ describe '#skipped_file' do
99
+ let(:destination) { 'some_file.txt' }
100
+
101
+ before { Vedeu.stubs(:log_stdout) }
102
+
103
+ subject { instance.skipped_file(destination) }
104
+
105
+ it {
106
+ Vedeu.expects(:log_stdout).
107
+ with(type: :create,
108
+ message: "some_file.txt \e[31malready exists, skipped.\e[39m")
109
+ subject
110
+ }
111
+ end
112
+
113
+ describe '#touch_file' do
114
+ let(:destination) {}
115
+
116
+ before { Vedeu.stubs(:log_stdout) }
117
+
118
+ subject { instance.touch_file(destination) }
119
+
120
+ it {
121
+ FileUtils.expects(:touch).with(destination)
122
+ subject
123
+ }
124
+ end
125
+
126
+ describe '#name' do
127
+ let(:_name) { 'My_First_APP' }
128
+
129
+ subject { instance.name }
130
+
131
+ it { subject.must_be_instance_of(String) }
132
+
133
+ it { subject.must_equal('my_first_app') }
134
+ end
135
+
136
+ describe '#name_as_class' do
137
+ subject { instance.name_as_class }
138
+
139
+ context 'when the name is a single value' do
140
+ let(:_name) { 'VEDEU' }
141
+
142
+ it { subject.must_equal('Vedeu') }
143
+ end
144
+
145
+ context 'when the name is an underscored value' do
146
+ it { subject.must_equal('MyFirstApp') }
147
+ end
148
+
149
+ context 'when the name contains hyphens' do
150
+ let(:_name) { 'hyphenated-APP' }
151
+
152
+ it { subject.must_equal('HyphenatedApp')}
153
+ end
154
+ end
155
+
156
+ describe '#output' do
157
+ let(:_message) { 'This is a test message.' }
158
+
159
+ before { Vedeu.stubs(:log_stdout) }
160
+
161
+ subject { instance.output(_message) }
162
+
163
+ it { subject.must_be_instance_of(String) }
164
+
165
+ it {
166
+ Vedeu.expects(:log_stdout).
167
+ with(type: :info, message: _message)
168
+ subject
169
+ }
170
+
171
+ it { subject.must_equal(_message) }
172
+ end
173
+
174
+ describe '#parse' do
175
+ let(:source) {}
176
+
177
+ subject { instance.parse(source) }
178
+
179
+ it {
180
+ Vedeu::Templating::Template.expects(:parse).with(instance, source)
181
+ subject
182
+ }
183
+ end
184
+
185
+ describe '#source' do
186
+ subject { instance.source }
187
+
188
+ it { subject.must_be_instance_of(String) }
189
+
190
+ it { subject.must_match('vedeu/cli/templates/application/.') }
191
+ end
192
+
193
+ end # Helpers
194
+
195
+ end # CLI
196
+
197
+ end # Vedeu
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module CLI
6
+
7
+ describe Main do
8
+
9
+ let(:described) { Vedeu::CLI::Main }
10
+ let(:instance) { described.new }
11
+
12
+ # describe '#new' do
13
+ # let(:_name) { 'app_name' }
14
+
15
+ # before do
16
+ # instance.stubs(:say).returns('')
17
+ # Vedeu::CLI::Application.stubs(:generate).returns('')
18
+ # end
19
+
20
+ # subject { instance.new(_name) }
21
+
22
+ # it {
23
+ # instance.expects(:say)
24
+ # subject
25
+ # }
26
+ # end
27
+
28
+ # describe '#view' do
29
+ # let(:_name) { 'view_name' }
30
+
31
+ # before do
32
+ # instance.stubs(:say).returns('')
33
+ # Vedeu::CLI::View.stubs(:generate).returns('')
34
+ # end
35
+
36
+ # subject { instance.view(_name) }
37
+
38
+ # it {
39
+ # Vedeu::CLI::View.expects(:generate).with(_name)
40
+ # subject
41
+ # }
42
+ # end
43
+
44
+ describe '#version' do
45
+ before { instance.stubs(:say) }
46
+
47
+ subject { instance.version }
48
+
49
+ it {
50
+ instance.expects(:say)
51
+ #.with("vedeu #{Vedeu::VERSION} (vedeu_cli #{Vedeu::CLI::VERSION})")
52
+ subject
53
+ }
54
+ end
55
+
56
+ end # Main
57
+
58
+ end # CLI
59
+
60
+ end # Vedeu
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module CLI
6
+
7
+ # @todo Add more tests.
8
+ # it { skip }
9
+
10
+ end # CLI
11
+
12
+ end # Vedeu
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module CLI
6
+
7
+ describe View do
8
+
9
+ let(:described) { Vedeu::CLI::View }
10
+ let(:instance) { described.new(_name) }
11
+ let(:_name) { 'my_first_view' }
12
+
13
+ describe '#initialize' do
14
+ it { instance.must_be_instance_of(described) }
15
+ it { instance.instance_variable_get('@name').must_equal(_name) }
16
+ end
17
+
18
+ describe '.generate' do
19
+ # before do
20
+ # FileUtils.stubs(:cp_r)
21
+ # FileUtils.stubs(:mkdir)
22
+ # end
23
+
24
+ subject { described.generate(_name) }
25
+
26
+ # @todo
27
+ # it { skip }
28
+ end
29
+
30
+ describe '#generate' do
31
+ it { described.must_respond_to(:generate) }
32
+ end
33
+
34
+ end # View
35
+
36
+ end # CLI
37
+
38
+ end # Vedeu
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ describe Vedeu do
4
+
5
+ # ...
6
+ # @todo Add more tests.
7
+ # it { skip }
8
+
9
+ end # Vedeu
10
+
11
+
@@ -0,0 +1,46 @@
1
+ require 'simplecov'
2
+ require 'simplecov-console' if ENV['CONSOLE_COVERAGE']
3
+ require 'pry'
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride' unless ENV['NO_COLOR']
6
+ require 'minitest/hell'
7
+
8
+ module VedeuMiniTestPlugin
9
+ # def before_setup
10
+ # super
11
+ # end
12
+
13
+ # def after_setup
14
+ # super
15
+ # end
16
+
17
+ # def before_teardown
18
+ # super
19
+ # end
20
+
21
+ # def after_teardown
22
+ # super
23
+ # end
24
+ end # VedeuMiniTestPlugin
25
+
26
+ module MiniTest
27
+
28
+ class Spec
29
+
30
+ # parallelize_me! # uncomment to unleash hell
31
+ # i_suck_and_my_tests_are_order_dependent! # just incase
32
+
33
+ include VedeuMiniTestPlugin
34
+
35
+ class << self
36
+
37
+ alias_method :context, :describe
38
+
39
+ end # Eigenclass
40
+
41
+ end # Spec
42
+
43
+ end # MiniTest
44
+
45
+ require 'mocha/setup'
46
+ require 'vedeu_cli'
data/vedeu_cli.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vedeu/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vedeu_cli'
8
+ spec.version = Vedeu::CLI::VERSION
9
+ spec.authors = ['Gavin Laking']
10
+ spec.email = ['gavinlaking@gmail.com']
11
+
12
+ spec.summary = 'A plugin for Vedeu.'
13
+ spec.description = 'Provides client application generators for Vedeu.'
14
+ spec.homepage = 'http://github.com/gavinlaking/vedeu_cli'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'guard', '2.13.0'
22
+ spec.add_development_dependency 'guard-minitest', '2.4.4'
23
+ spec.add_development_dependency 'minitest', '5.8.0'
24
+ spec.add_development_dependency 'minitest-reporters', '1.0.19'
25
+ spec.add_development_dependency 'mocha', '1.1.0'
26
+ spec.add_development_dependency 'pry', '0.10.1'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '0.33.0'
29
+ spec.add_development_dependency 'ruby-prof', '0.15.8'
30
+ spec.add_development_dependency 'simplecov', '0.10.0'
31
+ spec.add_development_dependency 'simplecov-console', '0.2.0'
32
+ spec.add_development_dependency 'yard', '0.8.7.6'
33
+
34
+ spec.add_dependency 'thor', '0.19.1'
35
+ spec.add_dependency 'vedeu'
36
+ end