webconsole 0.1.13 → 0.1.14

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: 3fcc746a3b332008cbc7f7767e5c7879b968b639
4
- data.tar.gz: d2debc54d64a67a3555db9164e012f2e2d59a883
3
+ metadata.gz: 9e712ea11ce5791366f105b2d18844411e518eed
4
+ data.tar.gz: fc922fee0c1caaf3311852407dd88df9a10773a7
5
5
  SHA512:
6
- metadata.gz: 2e195df3b04bdff44650930f4e1e00ea1cb4839dde2e771d1ce1e482b5c6a0f31e9917cfcc9395bcdfdf97148be98310534b21fc8c65fe4ca2ee622106d4b5b6
7
- data.tar.gz: c18edf9c671929b543e95171fc6b683eea64a19990a7bab4afd74b2b5d61b441d779099bcd003fad7e720c3b8c2e582bfc66acb9a49f2c8fdbc9bb33c3ea6ccb
6
+ metadata.gz: 4e5b661a9a07b2bf07000d4dcf56688c87b94e64483e8149400ed7bc49a1d4cc50511ca225e7e6d5daa89ee088272ca31236a3461a1552e4b5b6bef7c75843b4
7
+ data.tar.gz: 6954f172fc4e463f0f135edd94cabed2cd9783d2d7a7602acb9f9a298e176abbadab9fddd41ba6db4f74882649548b0fd1e4b066c4f1f75062fdd912b4df7928
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/webconsole.rb CHANGED
@@ -3,7 +3,6 @@ module WebConsole
3
3
  require_relative "webconsole/lib/window"
4
4
  require_relative "webconsole/lib/controller"
5
5
  require_relative "webconsole/lib/view"
6
- require_relative "webconsole/lib/logger"
7
6
  require_relative "webconsole/lib/module"
8
7
  end
9
8
 
@@ -29,6 +29,14 @@ module WebConsole
29
29
  result.chomp!
30
30
  return result
31
31
  end
32
+
33
+ RUN_PLUGIN_IN_SPLIT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "run_plugin_in_split.scpt")
34
+ def self.run_plugin_in_split(name, window_id, split_id)
35
+ parameters = [name, window_id, split_id]
36
+ result = self.run_applescript(RUN_PLUGIN_IN_SPLIT_SCRIPT, parameters)
37
+ result.chomp!
38
+ return result
39
+ end
32
40
 
33
41
  PLUGIN_HAS_WINDOWS_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "plugin_has_windows.scpt")
34
42
  def self.plugin_has_windows(name)
@@ -48,6 +56,33 @@ module WebConsole
48
56
  return result
49
57
  end
50
58
 
59
+ SPLIT_ID_IN_WINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "split_id_in_window.scpt")
60
+ def self.split_id_in_window(window_id, pluginName = nil)
61
+ arguments = [window_id]
62
+
63
+ if pluginName
64
+ arguments.push(pluginName)
65
+ end
66
+
67
+ result = self.run_applescript(SPLIT_ID_IN_WINDOW_SCRIPT, arguments)
68
+ result.chomp!
69
+
70
+ if result.empty?
71
+ # TODO: Remove this when doing `run_applescript` refactor
72
+ return nil
73
+ end
74
+
75
+ return result
76
+ end
77
+
78
+ SPLIT_ID_IN_WINDOW_LAST_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "split_id_in_window_last.scpt")
79
+ def self.split_id_in_window_last(window_id)
80
+ arguments = [window_id]
81
+ result = self.run_applescript(SPLIT_ID_IN_WINDOW_LAST_SCRIPT, arguments)
82
+ result.chomp!
83
+ return result
84
+ end
85
+
51
86
  CREATE_WINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "create_window.scpt")
52
87
  def self.create_window
53
88
  result = self.run_applescript(CREATE_WINDOW_SCRIPT)
@@ -106,6 +141,14 @@ module WebConsole
106
141
  end
107
142
  }
108
143
  end
109
- return `#{command}`
144
+
145
+ result = `#{command}`
146
+
147
+ # TODO: Figure out a better way to do this when doing `run_applescript` refactor
148
+ # if result.chomp.empty?
149
+ # return nil
150
+ # end
151
+
152
+ return result
110
153
  end
111
154
  end
@@ -7,6 +7,10 @@ module WebConsole
7
7
  class View < Window
8
8
 
9
9
  # Properties
10
+ def initialize(window_id = nil, view_id = nil)
11
+ super(window_id)
12
+ @view_id = view_id
13
+ end
10
14
 
11
15
  def view_id
12
16
  if !@view_id
@@ -60,16 +60,8 @@ module WebConsole
60
60
  end
61
61
 
62
62
  SPLIT_ID_IN_WINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "split_id_in_window.scpt")
63
- def split_id(pluginName = nil)
64
- arguments = [window_id]
65
-
66
- if pluginName
67
- arguments.push(pluginName)
68
- end
69
-
70
- result = WebConsole::run_applescript(SPLIT_ID_IN_WINDOW_SCRIPT, arguments)
71
- result.chomp!
72
- return result
63
+ def split_id
64
+ return WebConsole::split_id_in_window(window_id)
73
65
  end
74
66
 
75
67
  private
@@ -0,0 +1,83 @@
1
+ require_relative 'extension_constants'
2
+ require WEBCONSOLE_FILE
3
+
4
+ module WebConsole
5
+
6
+ class Logger
7
+ MESSAGE_PREFIX = 'MESSAGE '
8
+ ERROR_PREFIX = 'ERROR '
9
+ LOG_PLUGIN_NAME = 'Log'
10
+
11
+ # Toggle
12
+
13
+ SHOW_LOG_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "show_log.scpt")
14
+ def show
15
+ WebConsole::run_applescript(SHOW_LOG_SCRIPT, [window_id])
16
+ end
17
+
18
+ HIDE_LOG_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "hide_log.scpt")
19
+ def hide
20
+ WebConsole::run_applescript(HIDE_LOG_SCRIPT, [window_id])
21
+ end
22
+
23
+ TOGGLE_LOG_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "toggle_log.scpt")
24
+ def toggle
25
+ WebConsole::run_applescript(TOGGLE_LOG_SCRIPT, [window_id])
26
+ end
27
+
28
+ # Messages
29
+
30
+ def info(message)
31
+ message = message.dup
32
+ message.gsub!(%r{^}, MESSAGE_PREFIX) # Prefix all lines
33
+ # Strip trailing white space
34
+ # Add a line break
35
+ log_message(message)
36
+ end
37
+
38
+ def error(message)
39
+ message = message.dup
40
+ message.gsub!(%r{^}, ERROR_PREFIX)
41
+ log_message(message)
42
+ end
43
+
44
+ # Properties
45
+
46
+ def window_id
47
+ if !@window_id
48
+ if ENV.has_key?(WINDOW_ID_KEY)
49
+ @window_id = ENV[WINDOW_ID_KEY]
50
+ else
51
+ @window_id = WebConsole::create_window
52
+ end
53
+ end
54
+ return @window_id
55
+ end
56
+
57
+ def view_id
58
+ if !@view_id
59
+ # First see if there's an existing log plugin
60
+ @view_id = WebConsole::split_id_in_window(window_id, LOG_PLUGIN_NAME)
61
+
62
+ # If not, run one
63
+ if !@view_id
64
+ @view_id = WebConsole::split_id_in_window_last(window_id)
65
+ WebConsole::run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
66
+ end
67
+
68
+ end
69
+
70
+ return @view_id
71
+ end
72
+
73
+ private
74
+
75
+ READ_FROM_STANDARD_INPUT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "read_from_standard_input.scpt")
76
+ def log_message(message)
77
+ message.rstrip!
78
+ message += "\n"
79
+ WebConsole::run_applescript(READ_FROM_STANDARD_INPUT_SCRIPT, [message, window_id, view_id])
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,20 @@
1
+ require 'shellwords'
2
+ require 'webconsole'
3
+ require WebConsole::shared_test_resource("ruby/test_constants")
4
+ require WebConsole::Tests::TEST_HELPER_FILE
5
+
6
+ task :default => ['logger:tests']
7
+
8
+ namespace :logger do
9
+
10
+ task :tests => [:clean_up]
11
+
12
+ task :test_logger do
13
+ logger_tests_file = File.join(File.dirname(__FILE__), "tc_logger.rb")
14
+ ruby Shellwords.escape(logger_tests_file)
15
+ end
16
+
17
+ task :clean_up => [:test_logger] do
18
+ WebConsole::Tests::Helper::quit
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ function innerTextOfBodyChildAtIndex(index) {
2
+ return document.body.children[index].innerText;
3
+ }
@@ -0,0 +1,8 @@
1
+ require_relative "../../../extension_constants"
2
+
3
+ TEST_CLASS_JAVASCRIPT = "document.body.lastChild.classList[0]"
4
+ TEST_MESSAGE_JAVASCRIPT = "document.body.lastChild.innerText"
5
+ TEST_MESSAGE_COUNT_JAVASCRIPT = "document.body.children.length"
6
+
7
+ TEST_JAVASCRIPT_DIRECTORY = File.join(File.dirname(__FILE__), "..", "js")
8
+ TEST_JAVASCRIPT_FILE = File.join(TEST_JAVASCRIPT_DIRECTORY, "test_view_helper.js")
@@ -0,0 +1,28 @@
1
+ require_relative 'test_constants'
2
+
3
+ class TestViewHelper
4
+
5
+ def initialize(window_id, view_id)
6
+ @view = WebConsole::View.new(window_id, view_id)
7
+ javascript = File.read(TEST_JAVASCRIPT_FILE)
8
+ @view.do_javascript(javascript)
9
+ end
10
+
11
+ def log_message_at_index(index)
12
+ return @view.do_javascript_function('innerTextOfBodyChildAtIndex', [index])
13
+ end
14
+
15
+ def number_of_log_messages
16
+ # TODO: Do JavaScript should coerce types
17
+ return @view.do_javascript(TEST_MESSAGE_COUNT_JAVASCRIPT).chomp.to_i
18
+ end
19
+
20
+ def last_log_message
21
+ return @view.do_javascript(TEST_MESSAGE_JAVASCRIPT).chomp
22
+ end
23
+
24
+ def last_log_class
25
+ return @view.do_javascript(TEST_CLASS_JAVASCRIPT).chomp
26
+ end
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ rake
@@ -0,0 +1,175 @@
1
+ #!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
2
+
3
+ require "test/unit"
4
+
5
+ require_relative "lib/test_constants"
6
+ require WEBCONSOLE_FILE
7
+ require WebConsole::shared_test_resource("ruby/test_constants")
8
+ require WebConsole::Tests::TEST_HELPER_FILE
9
+
10
+ require_relative "lib/test_view_helper"
11
+ require_relative "../../logger"
12
+
13
+
14
+ class TestConstants < Test::Unit::TestCase
15
+
16
+ def test_constants
17
+ message_prefix = WebConsole::Logger::MESSAGE_PREFIX
18
+ assert_not_nil(message_prefix, "The message prefix should not be nil.")
19
+ error_prefix = WebConsole::Logger::ERROR_PREFIX
20
+ assert_not_nil(message_prefix, "The error prefix should not be nil.")
21
+ end
22
+
23
+ end
24
+
25
+
26
+ class TestUnintializedLogger < Test::Unit::TestCase
27
+
28
+ def teardown
29
+ WebConsole::Tests::Helper::quit
30
+ WebConsole::Tests::Helper::confirm_dialog
31
+ assert(!WebConsole::Tests::Helper::is_running, "The application should not be running.")
32
+ end
33
+
34
+ def test_uninitialized_logger
35
+ logger = WebConsole::Logger.new
36
+
37
+ # Test Message
38
+ message = "Testing log message"
39
+ logger.info(message)
40
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
41
+
42
+ # Make sure the log messages before accessing the logger's `view_id` and `window_id` because those run the logger.
43
+ # This test should test logging a message and running the logger itself simultaneously.
44
+ # This is why the `TestViewHelper` is intialized after logging the message.
45
+ test_view_helper = TestViewHelper.new(logger.window_id, logger.view_id)
46
+
47
+ test_message = test_view_helper.last_log_message
48
+ assert_equal(message, test_message, "The messages should match")
49
+ test_class = test_view_helper.last_log_class
50
+ assert_equal("message", test_class, "The classes should match")
51
+
52
+ end
53
+
54
+ end
55
+
56
+
57
+ class TestLogger < Test::Unit::TestCase
58
+
59
+ def setup
60
+ @logger = WebConsole::Logger.new
61
+ @logger.show
62
+ @test_view_helper = TestViewHelper.new(@logger.window_id, @logger.view_id)
63
+ end
64
+
65
+ def teardown
66
+ WebConsole::Tests::Helper::quit
67
+ WebConsole::Tests::Helper::confirm_dialog
68
+ assert(!WebConsole::Tests::Helper::is_running, "The application should not be running.")
69
+ end
70
+
71
+ def test_logger
72
+ test_count = 0
73
+
74
+ # Test Error
75
+ message = "Testing log error"
76
+ @logger.error(message)
77
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
78
+ test_message = @test_view_helper.last_log_message
79
+ assert_equal(message, test_message, "The messages should match")
80
+ test_class = @test_view_helper.last_log_class
81
+ assert_equal("error", test_class, "The classes should match")
82
+ result_count = @test_view_helper.number_of_log_messages
83
+ test_count += 1
84
+ assert_equal(test_count, result_count, "The number of log messages should match")
85
+
86
+ # Test Message
87
+ message = "Testing log message"
88
+ @logger.info(message)
89
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
90
+ test_message = @test_view_helper.last_log_message
91
+ assert_equal(message, test_message, "The messages should match")
92
+ test_class = @test_view_helper.last_log_class
93
+ assert_equal("message", test_class, "The classes should match")
94
+ result_count = @test_view_helper.number_of_log_messages
95
+ test_count += 1
96
+ assert_equal(test_count, result_count, "The number of log messages should match")
97
+
98
+ # Test Only Error Prefix
99
+ message = WebConsole::Logger::ERROR_PREFIX.rstrip # Note the trailing whitespace is trimmed
100
+ @logger.info(message)
101
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
102
+ test_message = @test_view_helper.last_log_message
103
+ assert_equal(message, test_message, "The messages should match")
104
+ test_class = @test_view_helper.last_log_class
105
+ assert_equal("message", test_class, "The classes should match")
106
+ result_count = @test_view_helper.number_of_log_messages
107
+ test_count += 1
108
+ assert_equal(test_count, result_count, "The number of log messages should match")
109
+
110
+ # Test Only Message Prefix
111
+ message = WebConsole::Logger::MESSAGE_PREFIX.rstrip # Note the trailing whitespace is trimmed
112
+ @logger.info(message)
113
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
114
+ test_message = @test_view_helper.last_log_message
115
+ assert_equal(message, test_message, "The messages should match")
116
+ test_class = @test_view_helper.last_log_class
117
+ assert_equal("message", test_class, "The classes should match")
118
+ result_count = @test_view_helper.number_of_log_messages
119
+ test_count += 1
120
+ assert_equal(test_count, result_count, "The number of log messages should match")
121
+
122
+ # Test Blank Spaces
123
+ @logger.info(" \t")
124
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
125
+ test_message = @test_view_helper.last_log_message()
126
+ assert_equal(message, test_message, "The messages should match")
127
+ test_class = @test_view_helper.last_log_class()
128
+ assert_equal("message", test_class, "The classes should match")
129
+
130
+ # Test Empty String
131
+ @logger.info("")
132
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
133
+ test_message = @test_view_helper.last_log_message()
134
+ assert_equal(message, test_message, "The messages should match")
135
+ test_class = @test_view_helper.last_log_class()
136
+ assert_equal("message", test_class, "The classes should match")
137
+
138
+ # TODO: Also add the following tests the `Log.wcplugin`
139
+
140
+ # Test Whitespace
141
+ # White space to the left should be preserved, whitespace to the right should be removed
142
+ # This test fails because retrieving the `innerText` doesn't preserve whitepace.
143
+
144
+ # message = "\t Testing log message"
145
+ # @logger.info(message + "\t ")
146
+ # sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
147
+ # test_message = @test_view_helper.last_log_message
148
+ # assert_equal(message, test_message, "The messages should match")
149
+ # test_class = @test_view_helper.last_log_class
150
+ # assert_equal("message", test_class, "The classes should match")
151
+ # result_count = @test_view_helper.number_of_log_messages
152
+ # test_count += 1
153
+ # assert_equal(test_count, result_count, "The number of log messages should match")
154
+ end
155
+
156
+ def test_long_input
157
+ message = %q(
158
+ Line 1
159
+
160
+ Line 2
161
+ Line 3
162
+ )
163
+ @logger.info(message)
164
+ sleep WebConsole::Tests::TEST_PAUSE_TIME # Pause for output to be processed
165
+ result_count = @test_view_helper.number_of_log_messages
166
+ assert_equal(result_count, 3, "The number of log messages should match")
167
+
168
+ (1..3).each { |i|
169
+ result = @test_view_helper.log_message_at_index(i - 1)
170
+ test_result = "Line #{i}"
171
+ assert_equal(result, test_result, "The number of log messages should match")
172
+ }
173
+ end
174
+
175
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roben Kleene
@@ -20,6 +20,7 @@ files:
20
20
  - lib/applescript/create_window.scpt
21
21
  - lib/applescript/do_javascript.scpt
22
22
  - lib/applescript/exists.scpt
23
+ - lib/applescript/hide_log.scpt
23
24
  - lib/applescript/load_html.scpt
24
25
  - lib/applescript/load_html_with_base_url.scpt
25
26
  - lib/applescript/load_plugin.scpt
@@ -29,10 +30,11 @@ files:
29
30
  - lib/applescript/resource_url_for_plugin.scpt
30
31
  - lib/applescript/run_plugin.scpt
31
32
  - lib/applescript/run_plugin_in_split.scpt
33
+ - lib/applescript/show_log.scpt
32
34
  - lib/applescript/split_id_in_window.scpt
35
+ - lib/applescript/split_id_in_window_last.scpt
36
+ - lib/applescript/toggle_log.scpt
33
37
  - lib/applescript/window_id_for_plugin.scpt
34
- - lib/webconsole.rb
35
- - lib/webconsole/dependencies.rb
36
38
  - lib/webconsole/dependencies/css/style.css
37
39
  - lib/webconsole/dependencies/js/wcdependencies.js
38
40
  - lib/webconsole/dependencies/lib/controller.rb
@@ -40,23 +42,31 @@ files:
40
42
  - lib/webconsole/dependencies/lib/tester.rb
41
43
  - lib/webconsole/dependencies/lib/view.rb
42
44
  - lib/webconsole/dependencies/views/view.html.erb
45
+ - lib/webconsole/dependencies.rb
43
46
  - lib/webconsole/extension_constants.rb
44
47
  - lib/webconsole/lib/constants.rb
45
48
  - lib/webconsole/lib/controller.rb
46
- - lib/webconsole/lib/logger.rb
47
49
  - lib/webconsole/lib/module.rb
48
- - lib/webconsole/lib/view.rb
49
50
  - lib/webconsole/lib/view/erb.rb
50
51
  - lib/webconsole/lib/view/javascript.rb
51
52
  - lib/webconsole/lib/view/resources.rb
53
+ - lib/webconsole/lib/view.rb
52
54
  - lib/webconsole/lib/window.rb
53
- - lib/webconsole/repl.rb
55
+ - lib/webconsole/logger/test/js/test_view_helper.js
56
+ - lib/webconsole/logger/test/lib/test_constants.rb
57
+ - lib/webconsole/logger/test/lib/test_view_helper.rb
58
+ - lib/webconsole/logger/test/Rakefile
59
+ - lib/webconsole/logger/test/run_tests.sh
60
+ - lib/webconsole/logger/test/tc_logger.rb
61
+ - lib/webconsole/logger.rb
54
62
  - lib/webconsole/repl/css/style.css
55
63
  - lib/webconsole/repl/js/wcrepl.js
56
64
  - lib/webconsole/repl/lib/input_controller.rb
57
65
  - lib/webconsole/repl/lib/output_controller.rb
58
66
  - lib/webconsole/repl/lib/view.rb
59
67
  - lib/webconsole/repl/view/view.html.erb
68
+ - lib/webconsole/repl.rb
69
+ - lib/webconsole.rb
60
70
  homepage:
61
71
  licenses: []
62
72
  metadata: {}
@@ -66,17 +76,17 @@ require_paths:
66
76
  - lib
67
77
  required_ruby_version: !ruby/object:Gem::Requirement
68
78
  requirements:
69
- - - "~>"
79
+ - - ~>
70
80
  - !ruby/object:Gem::Version
71
81
  version: '2.0'
72
82
  required_rubygems_version: !ruby/object:Gem::Requirement
73
83
  requirements:
74
- - - ">="
84
+ - - '>='
75
85
  - !ruby/object:Gem::Version
76
86
  version: '0'
77
87
  requirements: []
78
88
  rubyforge_project:
79
- rubygems_version: 2.2.2
89
+ rubygems_version: 2.0.3
80
90
  signing_key:
81
91
  specification_version: 4
82
92
  summary: Web Console helper gem
@@ -1,19 +0,0 @@
1
-
2
-
3
- module WebConsole
4
-
5
- class Logger < View
6
- MESSAGE_PREFIX = 'MESSAGE '
7
- ERROR_PREFIX = 'ERROR '
8
-
9
- def info(message)
10
- end
11
-
12
- def warning(message)
13
- end
14
-
15
- def error(message)
16
- end
17
- end
18
-
19
- end