shoes-core 4.0.0.pre9 → 4.0.0.pre10

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
- SHA1:
3
- metadata.gz: 4ba64133e02f0c5a97f98f1f9eff7a68b32fba38
4
- data.tar.gz: c3ee4b52936eb0125cf87f8c21b318ada8ca949f
2
+ SHA256:
3
+ metadata.gz: f9dde3be80d20738ebbc4be46c36877fbf22b937220502390e1535dfe2b78073
4
+ data.tar.gz: e870b37ec97751911c6a2ca0aa793ef78b2a903ef57e36c6dc7e9cb3751cb2b8
5
5
  SHA512:
6
- metadata.gz: 399a8a7dc9fe4057095a926b7fb9a41c442a5bfb96295a6b21122dab8f829968f34841a94e4b836be4927bd197582ef544e0c768383dc57152f46ff38f214e76
7
- data.tar.gz: 161b478d23e6949f3c5ce41fd7178c7f75ed3ef6da3a52b1e9f57f6daddfa61d86a3dcdeb2aa9a927b5eae167ea098a7eb880a1d841d41f0019c196bb7eaa5d9
6
+ metadata.gz: 547f206603c5e78dab96fc40b6a8b95f0b884484bf01378cec2625a92700b2f69c35a8a6b97343eb70941569fc531bf134018e7021b16841b509ead5cff42ae9
7
+ data.tar.gz: 8d18cfe318b66e676a6d592da37ab007b4544df7c4972b99c4e83ef338822296039a48245ac76e210ccd8e7f2be1d369acb66efad677e2a9d427c7a352820227
data/lib/shoes/app.rb CHANGED
@@ -45,6 +45,7 @@ class Shoes
45
45
  #
46
46
  # @see Dimension#initialize
47
47
  def initialize(opts = {}, &blk)
48
+ ensure_app_dir_set
48
49
  @__app__ = Shoes::InternalApp.new(self, opts, &blk)
49
50
  @__app__.setup_gui
50
51
  Shoes.register self
@@ -105,6 +106,15 @@ class Shoes
105
106
 
106
107
  private
107
108
 
109
+ # If we didn't arrive by any of our executables (shoes or packaging)
110
+ # treat the starting directory in our call tree as the app directory.
111
+ def ensure_app_dir_set
112
+ return if Shoes.configuration.app_dir
113
+
114
+ path, *_ = caller.last.split(":")
115
+ Shoes.configuration.app_dir = File.dirname(path)
116
+ end
117
+
108
118
  def inspect_details
109
119
  " \"#{@__app__.app_title}\""
110
120
  end
@@ -2,6 +2,8 @@
2
2
  class Shoes
3
3
  class Color
4
4
  module DSLHelpers
5
+ include Common::ImageHandling
6
+
5
7
  def pattern(*args)
6
8
  if args.length == 1
7
9
  arg = args.first
@@ -81,7 +83,11 @@ class Shoes
81
83
  end
82
84
 
83
85
  def image_pattern(path)
86
+ path = absolute_file_path(path)
84
87
  Shoes::ImagePattern.new path if File.exist?(path)
88
+ rescue FileNotFoundError => e
89
+ Shoes.logger.error(e.message)
90
+ return nil
85
91
  end
86
92
  end
87
93
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module Common
4
+ module ImageHandling
5
+ def absolute_file_path(path)
6
+ if Pathname(path).absolute?
7
+ search_for(File.basename(path), File.dirname(path))
8
+ else
9
+ search_for(path, *default_search_paths)
10
+ end
11
+ end
12
+
13
+ def search_for(path, *locations)
14
+ found = locations.map { |dir| File.join(dir, path) }
15
+ .find { |candidate| File.exist?(candidate) }
16
+
17
+ unless found
18
+ raise FileNotFoundError, "#{path} not found. Searched #{locations.join(',')}"
19
+ end
20
+
21
+ found
22
+ end
23
+
24
+ def default_search_paths
25
+ [Dir.pwd, Shoes.configuration.app_dir, File.join(Shoes::DIR, "static")]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,7 @@
2
2
  class Shoes
3
3
  class Configuration
4
4
  class << self
5
+ attr_accessor :app_dir
5
6
  attr_writer :fail_fast
6
7
 
7
8
  def fail_fast
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Shoes
4
4
  module Core
5
- VERSION = "4.0.0.pre9"
5
+ VERSION = "4.0.0.pre10"
6
6
  end
7
7
  end
data/lib/shoes/dsl.rb CHANGED
@@ -37,6 +37,7 @@ require 'shoes/core/version'
37
37
  require 'shoes/packager'
38
38
 
39
39
  require 'shoes/renamed_delegate'
40
+ require 'shoes/common/image_handling'
40
41
  require 'shoes/common/inspect'
41
42
  require 'shoes/dimension'
42
43
  require 'shoes/dimensions'
data/lib/shoes/image.rb CHANGED
@@ -3,6 +3,7 @@ class Shoes
3
3
  class Image < Common::UIElement
4
4
  include Common::Clickable
5
5
  include Common::Hover
6
+ include Common::ImageHandling
6
7
 
7
8
  BINARY_ENCODING = Encoding.find('binary')
8
9
 
@@ -38,11 +39,5 @@ class Shoes
38
39
  return path_or_data if url?(path_or_data)
39
40
  absolute_file_path(path_or_data)
40
41
  end
41
-
42
- def absolute_file_path(path)
43
- path = File.join(Dir.pwd, path) unless Pathname(path).absolute?
44
- raise FileNotFoundError, "#{path} not found." unless File.exist?(path)
45
- path
46
- end
47
42
  end
48
43
  end
data/lib/shoes/mock.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
3
+ class Shoes
4
+ module Mock
5
+ def self.initialize_backend(*_)
6
+ end
7
+ end
8
+ end
9
+
2
10
  require 'shoes/mock/common_methods'
3
11
  require 'shoes/mock/clickable'
4
12
 
@@ -4,12 +4,14 @@ class Shoes
4
4
  class Packager
5
5
  attr_accessor :gems
6
6
 
7
- def initialize(_dsl)
8
- @packages = []
7
+ def initialize(*_)
9
8
  end
10
9
 
11
- def create_package(_, package)
12
- @packages << package
10
+ def options
11
+ OptionParser.new
12
+ end
13
+
14
+ def create_package(*_)
13
15
  end
14
16
  end
15
17
  end
@@ -1,24 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
  class Shoes
3
3
  class Packager
4
- attr_reader :packages, :backend
4
+ attr_reader :backend
5
5
 
6
6
  def initialize
7
- begin
8
- @backend = Shoes.backend_for(self)
9
- configure_gems
10
- rescue ArgumentError
11
- # Packaging unsupported by this backend
12
- end
13
- @packages = []
7
+ @backend = Shoes.backend_for(self)
8
+ configure_gems
9
+ rescue ArgumentError
10
+ # Packaging unsupported by this backend
14
11
  end
15
12
 
16
- def create_package(program_name, package)
17
- @packages << @backend.create_package(program_name, package)
13
+ def options
14
+ @backend.options
18
15
  end
19
16
 
20
- def should_package?
21
- @packages.any?
17
+ def parse!(args)
18
+ options.parse!(args)
22
19
  end
23
20
 
24
21
  def run(path)
@@ -36,10 +33,5 @@ class Shoes
36
33
  rescue => e
37
34
  Shoes.logger.error "Looking up gems for packaging failed:\n#{e.message}"
38
35
  end
39
-
40
- def help(program_name)
41
- return "" if @backend.nil?
42
- @backend.help(program_name)
43
- end
44
36
  end
45
37
  end
data/lib/shoes/ui/cli.rb CHANGED
@@ -2,79 +2,44 @@
2
2
  require 'optparse'
3
3
  require 'shoes'
4
4
 
5
- class Shoes
6
- class CLI
7
- attr_reader :packager
8
-
9
- def initialize(backend)
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- backend_const = Shoes.load_backend(backend)
12
- backend_const.initialize_backend
13
-
14
- @packager = Shoes::Packager.new
15
- end
16
-
17
- def parse!(args)
18
- options = OptionParser.new do |opts|
19
- opts.program_name = 'shoes'
20
- opts.banner = <<-EOS
21
- Usage: #{opts.program_name} [-h] [-p package] file
22
- EOS
23
- opts.separator ''
24
- opts.separator 'Options:'
25
-
26
- opts.on('-p', '--package PACKAGE_TYPE', 'Package as BACKEND:PACKAGE') do |package|
27
- @packager.create_package(opts.program_name, package)
28
- end
29
-
30
- opts.on('-v', '--version', 'Shoes version') do
31
- puts "Shoes #{Shoes::Core::VERSION}"
32
- exit
33
- end
34
-
35
- opts.on('-m', '--manual', 'Run the Shoes manual') do
36
- require 'shoes/manual'
37
- Shoes::Manual.run "English"
38
- exit
39
- end
40
-
41
- opts.on('-b', '--backend [BACKEND]', 'Select a Shoes backend') do |backend|
42
- require 'shoes/ui/picker'
43
- Shoes::UI::Picker.new.run(ENV["SHOES_BIN_DIR"], backend)
44
- exit
45
- end
46
-
47
- opts.on('-f', '--fail-fast', 'Crash on exceptions in Shoes code') do
48
- Shoes.configuration.fail_fast = true
49
- end
5
+ require 'shoes/ui/cli/base_command'
6
+ require 'shoes/ui/cli/default_command'
7
+ require 'shoes/ui/cli/help_command'
8
+ require 'shoes/ui/cli/manual_command'
9
+ require 'shoes/ui/cli/package_command'
10
+ require 'shoes/ui/cli/select_backend_command'
11
+ require 'shoes/ui/cli/version_command'
50
12
 
51
- opts.separator @packager.help(opts.program_name)
13
+ class Shoes
14
+ module UI
15
+ class CLI
16
+ SUPPORTED_COMMANDS = {
17
+ help: HelpCommand,
18
+ manual: ManualCommand,
19
+ package: PackageCommand,
20
+ select_backend: SelectBackendCommand,
21
+ version: VersionCommand,
22
+ }.freeze
23
+
24
+ def initialize(backend)
25
+ $LOAD_PATH.unshift(Dir.pwd)
26
+ backend_const = Shoes.load_backend(backend)
27
+ backend_const.initialize_backend
52
28
  end
53
29
 
54
- options.parse!(args)
55
- options
56
- end
57
-
58
- # Execute a shoes app.
59
- #
60
- # @param [String] app the location of the app to run
61
- # @param [String] backend name of backend to load with the app
62
- def execute_app(app)
63
- load app
64
- end
30
+ def run(args)
31
+ if args.empty?
32
+ Shoes::UI::CLI::HelpCommand.new([]).run
33
+ exit(1)
34
+ end
65
35
 
66
- def run(args)
67
- opts = parse!(args)
68
- if args.empty?
69
- puts opts.banner
70
- puts "Try '#{opts.program_name} --help' for more information"
71
- exit(0)
36
+ command = create_command(*args)
37
+ command.run
72
38
  end
73
39
 
74
- if @packager.should_package?
75
- @packager.run(args.shift)
76
- else
77
- execute_app(args.first)
40
+ def create_command(*args)
41
+ command_class = SUPPORTED_COMMANDS[args.first.to_sym] || DefaultCommand
42
+ command_class.new(args.dup)
78
43
  end
79
44
  end
80
45
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class BaseCommand
6
+ attr_reader :args
7
+
8
+ def initialize(args)
9
+ @args = args
10
+ end
11
+
12
+ def warn_on_unexpected_parameters(expected_size = 1)
13
+ return unless args.size > expected_size
14
+
15
+ unexpected = args[expected_size..-1].join(" ")
16
+ Shoes.logger.warn("Unexpected extra parameters '#{unexpected}'")
17
+ end
18
+
19
+ def self.help
20
+ nil
21
+ end
22
+
23
+ def self.help_from_options(command, options)
24
+ lines = ["#{command}\n"] + options.summarize
25
+ lines.join("")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class DefaultCommand < BaseCommand
6
+ def run
7
+ if parse!(args)
8
+ warn_on_unexpected_parameters
9
+
10
+ path = args.first
11
+ if path
12
+ $LOAD_PATH.unshift(File.dirname(path))
13
+ Shoes.configuration.app_dir = File.dirname(path)
14
+ load path
15
+ end
16
+ end
17
+ end
18
+
19
+ def parse!(args)
20
+ self.class.options.parse!(args)
21
+ true
22
+ rescue OptionParser::InvalidOption => e
23
+ puts "Whoops! #{e.message}"
24
+ puts
25
+ puts self.class.help
26
+
27
+ false
28
+ end
29
+
30
+ def self.options
31
+ OptionParser.new do |opts|
32
+ # Keep around command dashed options
33
+ opts.on('-v', '--version', 'Shoes version') do
34
+ Shoes::UI::CLI::VersionCommand.new([]).run
35
+ exit
36
+ end
37
+
38
+ opts.on('-h', '--help', 'Shoes help') do
39
+ Shoes::UI::CLI::HelpCommand.new([]).run
40
+ exit
41
+ end
42
+
43
+ # Also, we have some real runtime options!
44
+ opts.on('-f', '--fail-fast', 'Crash on exceptions in Shoes code') do
45
+ Shoes.configuration.fail_fast = true
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.help
51
+ help_from_options("shoes [options] file", options)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class HelpCommand < BaseCommand
6
+ def run
7
+ warn_on_unexpected_parameters
8
+
9
+ puts "Shoes is the best little GUI toolkit for Ruby."
10
+ puts
11
+
12
+ command_classes = [DefaultCommand]
13
+ command_classes.concat(SUPPORTED_COMMANDS.map(&:last))
14
+
15
+ command_classes.each do |command_class|
16
+ text = command_class.help.to_s
17
+ unless text.empty?
18
+ puts text
19
+ puts
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.help
25
+ <<-EOS
26
+ shoes help
27
+ Displays this help text
28
+ EOS
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class ManualCommand < BaseCommand
6
+ def run
7
+ require 'shoes/manual'
8
+ Shoes::Manual.run "English"
9
+ end
10
+
11
+ def self.help
12
+ <<-EOS
13
+ shoes manual
14
+ Run the interactive Shoes manual
15
+ EOS
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class PackageCommand < BaseCommand
6
+ def run
7
+ @packager = Shoes::Packager.new
8
+ @packager.parse!(args)
9
+
10
+ warn_on_unexpected_parameters(2)
11
+
12
+ path = args[1]
13
+ @packager.run(path)
14
+ rescue OptionParser::InvalidOption => e
15
+ puts "Whoops! #{e.message}"
16
+ puts
17
+ puts self.class.help
18
+
19
+ false
20
+ end
21
+
22
+ def self.help
23
+ help_from_options("shoes package [options] file",
24
+ Shoes::Packager.new.options) + <<-EOS
25
+
26
+ Packages may be built either from a single .rb file, or a .yaml file with
27
+ more options defined.
28
+ EOS
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class SelectBackendCommand < BaseCommand
6
+ def run
7
+ require 'shoes/ui/picker'
8
+ backend = args[1]
9
+ Shoes::UI::Picker.new.run(ENV["SHOES_BIN_DIR"], backend)
10
+ end
11
+
12
+ def self.help
13
+ <<-EOS
14
+ shoes select_backend [backend]
15
+ Select a Shoes backend to use. A backend can be specified, or Shoes will
16
+ attempt to auto-detect available backends to select from.
17
+ EOS
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module UI
4
+ class CLI
5
+ class VersionCommand < BaseCommand
6
+ def run
7
+ puts "Shoes #{Shoes::Core::VERSION}"
8
+ end
9
+
10
+ def self.help
11
+ <<-EOS
12
+ shoes version
13
+ Prints the current Shoes version
14
+ EOS
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/shoes/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Shoes
4
- VERSION = "4.0.0.pre9"
4
+ VERSION = "4.0.0.pre10"
5
5
  end
metadata CHANGED
@@ -1,16 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoes-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.pre9
4
+ version: 4.0.0.pre10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Shoes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-24 00:00:00.000000000 Z
11
+ date: 2017-06-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Shoes is the best little GUI toolkit for Ruby. Shoes makes building for Mac, Windows, and Linux super simple. This is the DSL for writing your app. You'll need a backend to run it.
13
+ description: Shoes is the best little GUI toolkit for Ruby. Shoes makes building for
14
+ Mac, Windows, and Linux super simple. This is the DSL for writing your app. You'll
15
+ need a backend to run it.
14
16
  email:
15
17
  - shoes@lists.mvmanila.com
16
18
  executables:
@@ -44,6 +46,7 @@ files:
44
46
  - lib/shoes/common/clickable.rb
45
47
  - lib/shoes/common/fill.rb
46
48
  - lib/shoes/common/hover.rb
49
+ - lib/shoes/common/image_handling.rb
47
50
  - lib/shoes/common/inspect.rb
48
51
  - lib/shoes/common/link_finder.rb
49
52
  - lib/shoes/common/positioning.rb
@@ -141,6 +144,13 @@ files:
141
144
  - lib/shoes/text_block_dimensions.rb
142
145
  - lib/shoes/timer.rb
143
146
  - lib/shoes/ui/cli.rb
147
+ - lib/shoes/ui/cli/base_command.rb
148
+ - lib/shoes/ui/cli/default_command.rb
149
+ - lib/shoes/ui/cli/help_command.rb
150
+ - lib/shoes/ui/cli/manual_command.rb
151
+ - lib/shoes/ui/cli/package_command.rb
152
+ - lib/shoes/ui/cli/select_backend_command.rb
153
+ - lib/shoes/ui/cli/version_command.rb
144
154
  - lib/shoes/ui/picker.rb
145
155
  - lib/shoes/url.rb
146
156
  - lib/shoes/version.rb
@@ -170,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
180
  version: 1.3.1
171
181
  requirements: []
172
182
  rubyforge_project:
173
- rubygems_version: 2.6.10
183
+ rubygems_version: 2.6.11
174
184
  signing_key:
175
185
  specification_version: 4
176
186
  summary: The best little DSL for the best little GUI toolkit for Ruby.