vedeu 0.4.36 → 0.4.37

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: 2ecad92f4001170f4fa870a5738639b549bd5030
4
- data.tar.gz: aebc0c775c358a62c309bdfba93d58d01077c662
3
+ metadata.gz: e29978c4b64039fc130cc5bad584e48e4ab08a6d
4
+ data.tar.gz: b88b3581a5d9db259b16536802ce766ac00fd524
5
5
  SHA512:
6
- metadata.gz: 2fe008b535bc415a6a7c6829ebf256bc0913edf2fe5d2abc4808e8e8ea67d9ee7e8ca9e14286de8d5829617abd381f47dfe070117190194468f796b2f707dc25
7
- data.tar.gz: d822a5e46f9c3897c49eb7edb65f4ecb2c32b61a5bc0c62ac1f2b6080febebcfc439d80e81e0e8832ca392f08b6fa9b6fc375e1ff15b08cc22e29f7154aeccc5
6
+ metadata.gz: c2d7cf78b2fe8c5282fd1f3c4f3d25210d258a2db632d1cb7cdf6214c743e54141b104af5868f33fab97a0de017e0e17db663511ffb4d49ef805fa48032c3d12
7
+ data.tar.gz: d880b25648befe1cabb5441c2e62a5b08b2391abfdf684b25c8063233784c36252a86460dfeb0c52217d2600b1e318cb5ef8a20b22f22a6c640692a58a6c8b7c
data/bin/vedeu CHANGED
@@ -37,7 +37,8 @@ begin
37
37
  print "\n\e[33mVedeu v#{Vedeu::VERSION}\e[39m\n\n"
38
38
  print "\e[4m\e[36mUsage:\e[39m\e[24m\n\n"
39
39
  print "\e[32m vedeu new [app_name]\e[39m\n"
40
- print " Creates the skeleton file and directory structure for a new Vedeu client application.\n\n"
40
+ print ' Creates the skeleton file and directory structure for a new '
41
+ print "Vedeu client application.\n\n"
41
42
  print "\e[32m vedeu view [view_name]\e[39m\n"
42
43
  print " Creates a new view for Vedeu.\n"
43
44
  print "\n\n"
data/lib/vedeu/api.rb CHANGED
@@ -126,7 +126,11 @@ module Vedeu
126
126
 
127
127
  # @!method log
128
128
  # @see Vedeu::Log.log
129
- def_delegators Vedeu::Log, :log
129
+ # @!method log_stdout
130
+ # @see Vedeu::Log.log_stdout
131
+ # @!method log_stderr
132
+ # @see Vedeu::Log.log_stderr
133
+ def_delegators Vedeu::Log, :log, :log_stdout, :log_stderr
130
134
 
131
135
  # @!method keypress
132
136
  # @see Vedeu::Mapper.keypress
@@ -55,17 +55,19 @@ module Vedeu
55
55
  # @param path [String]
56
56
  # @return [String]
57
57
  def load(path)
58
+ loadables(path).each { |file| Kernel.load(file) }
59
+
60
+ path
61
+ end
62
+
63
+ # @param path [String]
64
+ # @return [Array<String>]
65
+ def loadables(path)
58
66
  files = send(path)
59
67
 
60
68
  Dir.glob(files).select do |file|
61
69
  File.file?(file) && File.extname(file) == '.rb'
62
-
63
- end.each do |file|
64
- Kernel.load(file)
65
-
66
70
  end
67
-
68
- path
69
71
  end
70
72
 
71
73
  end # Bootstrap
@@ -91,14 +91,20 @@ module Vedeu
91
91
  # @param name [String] The name of interface for which this template's
92
92
  # content belongs to.
93
93
  # @param filename [String] The filename (including path) to the template
94
- # to be used.
94
+ # to be used. Yoy can use `File.dirname(__FILE__)` to use relative
95
+ # paths.
95
96
  # @param object [Object] The object for which the values of template's
96
97
  # variables can be obtained.
97
98
  # @param options [Hash] See {Vedeu::Wordwrap}
98
99
  # @return [Vedeu::Interfaces<Vedeu::Interface>]
99
100
  def template_for(name, filename, object = nil, options = {})
100
- content = Vedeu::Template.parse(object, filename)
101
- lines = Vedeu::Wordwrap.for(content, options)
101
+ fail MissingRequired, 'Cannot render template without the name of ' \
102
+ 'the view.' unless name
103
+ fail MissingRequired, "Cannot render template for '#{name}', without " \
104
+ 'a filename.' unless filename
105
+
106
+ content = Vedeu::Template.parse(object, filename)
107
+ lines = Vedeu::Wordwrap.for(content, options)
102
108
 
103
109
  new_model = model.member.build(template_attributes(name, lines))
104
110
 
@@ -37,16 +37,9 @@ module Vedeu
37
37
 
38
38
  # @return [void]
39
39
  def make_directory_structure
40
- FileUtils.mkdir_p(name + '/app/controllers')
41
- FileUtils.mkdir_p(name + '/app/helpers')
42
- FileUtils.mkdir_p(name + '/app/models/keymaps')
43
- FileUtils.mkdir_p(name + '/app/views/interfaces')
44
- FileUtils.mkdir_p(name + '/app/views/templates')
45
- FileUtils.mkdir_p(name + '/bin')
46
- FileUtils.mkdir_p(name + '/config')
47
- FileUtils.mkdir_p(name + '/lib')
48
- FileUtils.mkdir_p(name + '/test')
49
- FileUtils.mkdir_p(name + '/vendor')
40
+ directories.each do |directory|
41
+ FileUtils.mkdir_p(name + directory)
42
+ end
50
43
  end
51
44
 
52
45
  # @return [void]
@@ -101,6 +94,22 @@ module Vedeu
101
94
  "#{name}/app/models/keymaps/_system_.rb")
102
95
  end
103
96
 
97
+ # @return [Array<String>]
98
+ def directories
99
+ [
100
+ '/app/controllers',
101
+ '/app/helpers',
102
+ '/app/models/keymaps',
103
+ '/app/views/interfaces',
104
+ '/app/views/templates',
105
+ '/bin',
106
+ '/config',
107
+ '/lib',
108
+ '/test',
109
+ '/vendor',
110
+ ]
111
+ end
112
+
104
113
  end # Application
105
114
 
106
115
  end # Generator
@@ -24,6 +24,8 @@ module Vedeu
24
24
  # @param destination [String]
25
25
  # @return [void]
26
26
  def make_file(source, destination)
27
+ Vedeu.log_stdout(type: :create, message: "Writing: '#{destination}'")
28
+
27
29
  File.write(destination, parse(source))
28
30
  end
29
31
 
@@ -38,30 +38,30 @@ module Vedeu
38
38
  # @return [void]
39
39
  def make_controller_file
40
40
  make_file(source + '/app/controllers/name.erb',
41
- app_name + "/app/controllers/#{name}.rb")
41
+ '.' + "/app/controllers/#{name}_controller.rb")
42
42
  end
43
43
 
44
44
  # @return [void]
45
45
  def make_helper_file
46
46
  make_file(source + '/app/helpers/name.erb',
47
- app_name + "/app/helpers/#{name}.rb")
47
+ '.' + "/app/helpers/#{name}_helper.rb")
48
48
  end
49
49
 
50
50
  # @return [void]
51
51
  def make_interface_file
52
52
  make_file(source + '/app/views/interfaces/name.erb',
53
- app_name + "/app/views/interfaces/#{name}.rb")
53
+ '.' + "/app/views/interfaces/#{name}.rb")
54
54
  end
55
55
 
56
56
  # @return [void]
57
57
  def make_template_file
58
- FileUtils.touch(app_name + "/app/views/templates/#{name}.erb")
58
+ FileUtils.touch('.' + "/app/views/templates/#{name}.erb")
59
59
  end
60
60
 
61
61
  # @return [void]
62
62
  def make_view_class_file
63
63
  make_file(source + '/app/views/name.erb',
64
- app_name + "/app/views/#{name}.rb")
64
+ '.' + "/app/views/#{name}.rb")
65
65
  end
66
66
 
67
67
  end # View
@@ -40,7 +40,23 @@ module Vedeu
40
40
  # @param value []
41
41
  # @return [Object]
42
42
  def self.coerce(value)
43
- Vedeu::ColourCoercer.coerce(value)
43
+ # Vedeu::ColourCoercer.coerce(value)
44
+ return value if value.is_a?(self)
45
+ return new unless value.is_a?(Hash)
46
+
47
+ if value[:colour]
48
+ return value[:colour] if value[:colour].is_a?(self)
49
+ return new unless value[:colour].is_a?(Hash)
50
+ return new(value[:colour]) if value[:colour][:background] ||
51
+ value[:colour][:foreground]
52
+
53
+ elsif value[:background] || value[:foreground]
54
+ new(value)
55
+
56
+ else
57
+ new
58
+
59
+ end
44
60
  end
45
61
 
46
62
  # Returns a new instance of Vedeu::Colour.
@@ -11,11 +11,11 @@ module Vedeu
11
11
  # STDOUT, STDERR or an open file).
12
12
  #
13
13
  def initialize(logdev)
14
- @level = DEBUG
14
+ @level = DEBUG
15
15
  @default_formatter = Formatter.new
16
- @formatter = nil
17
- @logdev = nil
18
- @logdev = LocklessLogDevice.new(logdev) if logdev
16
+ @formatter = nil
17
+ @logdev = nil
18
+ @logdev = LocklessLogDevice.new(logdev) if logdev
19
19
  end
20
20
 
21
21
  # Ensures we can always write to the log file by creating a lock-less
@@ -28,14 +28,14 @@ module Vedeu
28
28
  # @param log []
29
29
  # @return []
30
30
  def initialize(log = nil)
31
- @dev = nil
31
+ @dev = nil
32
32
  @filename = nil
33
33
 
34
34
  if log.respond_to?(:write) && log.respond_to?(:close)
35
35
  @dev = log
36
36
 
37
37
  else
38
- @dev = open_logfile(log)
38
+ @dev = open_logfile(log)
39
39
  @dev.sync = true
40
40
  @filename = log
41
41
 
@@ -101,6 +101,16 @@ module Vedeu
101
101
  message_body(type, message)]) if enabled? || force
102
102
  end
103
103
 
104
+ # @return [TrueClass]
105
+ def log_stdout(type: :info, message:)
106
+ $stdout.puts [message_type(type), message_body(type, message)].join
107
+ end
108
+
109
+ # @return [TrueClass]
110
+ def log_stderr(type: :info, message:)
111
+ $stderr.puts [message_type(type), message_body(type, message)].join
112
+ end
113
+
104
114
  # @return [TrueClass]
105
115
  def logger
106
116
  MonoLogger.new(log_file).tap do |log|
@@ -1,3 +1,5 @@
1
- Dir[File.expand_path('../*.rake', __FILE__)].delete_if do |task_file|
1
+ tasks = Dir[File.expand_path('../*.rake', __FILE__)].delete_if do |task_file|
2
2
  task_file =~ /vedeu\.rake$/
3
- end.each { |task_file| load task_file }
3
+ end
4
+
5
+ tasks.each { |task_file| load task_file }
data/lib/vedeu/traps.rb CHANGED
@@ -5,9 +5,15 @@ module Vedeu
5
5
  # @api private
6
6
  module Traps
7
7
 
8
- Signal.trap('INT') { puts; exit(1) }
8
+ Signal.trap('INT') do
9
+ puts
10
+ exit(1)
11
+ end
9
12
 
10
- Signal.trap('TERM') { puts; exit(1) }
13
+ Signal.trap('TERM') do
14
+ puts
15
+ exit(1)
16
+ end
11
17
 
12
18
  Signal.trap('TTIN') {}
13
19
  Signal.trap('USR1') {}
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.4.36'
4
+ VERSION = '0.4.37'
5
5
 
6
6
  end
@@ -32,6 +32,8 @@ module Vedeu
32
32
  it { Vedeu.must_respond_to(:interfaces) }
33
33
  it { Vedeu.must_respond_to(:keymaps) }
34
34
  it { Vedeu.must_respond_to(:log) }
35
+ it { Vedeu.must_respond_to(:log_stdout) }
36
+ it { Vedeu.must_respond_to(:log_stderr) }
35
37
  it { Vedeu.must_respond_to(:keypress) }
36
38
  it { Vedeu.must_respond_to(:menu) }
37
39
  it { Vedeu.must_respond_to(:menus) }
@@ -46,14 +46,31 @@ module Vedeu
46
46
  ]
47
47
  }
48
48
 
49
- before do
50
- Vedeu::Template.expects(:parse).
51
- with(object, filename).returns(content)
49
+ subject { instance.template_for(_name, filename, object) }
50
+
51
+ context 'when the name of the view is not given' do
52
+ let(:filename) { 'my_interface.erb' }
53
+
54
+ it { proc { subject }.must_raise(MissingRequired) }
52
55
  end
53
56
 
54
- subject { instance.template_for(_name, filename, object) }
57
+ context 'when the filename of the template is not given' do
58
+ let(:_name) { 'my_interface' }
55
59
 
56
- it { subject.must_be_instance_of(Vedeu::Interfaces) }
60
+ it { proc { subject }.must_raise(MissingRequired) }
61
+ end
62
+
63
+ context 'when the name and filename are given' do
64
+ let(:_name) { 'my_interface' }
65
+ let(:filename) { 'my_interface.erb' }
66
+
67
+ before do
68
+ Vedeu::Template.expects(:parse).
69
+ with(object, filename).returns(content)
70
+ end
71
+
72
+ it { subject.must_be_instance_of(Vedeu::Interfaces) }
73
+ end
57
74
  end
58
75
 
59
76
  end # Composition
@@ -27,6 +27,32 @@ module Vedeu
27
27
  end
28
28
  end
29
29
 
30
+ describe '.log_stdout' do
31
+ let(:type) { :create }
32
+ let(:_message) { 'Logging to stdout...' }
33
+
34
+ subject { described.log_stdout(type: type, message: _message) }
35
+
36
+ it {
37
+ capture_io { subject }.must_equal(
38
+ ["\e[92m[create] \e[39m\e[32mLogging to stdout...\e[39m\n", ""]
39
+ )
40
+ }
41
+ end
42
+
43
+ describe '.log_stdout' do
44
+ let(:type) { :debug }
45
+ let(:_message) { 'Logging to stderr...' }
46
+
47
+ subject { described.log_stderr(type: type, message: _message) }
48
+
49
+ it {
50
+ capture_io { subject }.must_equal(
51
+ ["", "\e[91m[debug] \e[39m\e[31mLogging to stderr...\e[39m\n"]
52
+ )
53
+ }
54
+ end
55
+
30
56
  describe '.logger' do
31
57
  subject { described.logger }
32
58
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.36
4
+ version: 0.4.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba