bridgetown-core 0.19.2 → 0.21.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core.rb +37 -29
  4. data/lib/bridgetown-core/cleaner.rb +9 -3
  5. data/lib/bridgetown-core/collection.rb +177 -78
  6. data/lib/bridgetown-core/commands/base.rb +9 -0
  7. data/lib/bridgetown-core/commands/build.rb +0 -11
  8. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  9. data/lib/bridgetown-core/commands/configure.rb +8 -3
  10. data/lib/bridgetown-core/commands/console.rb +4 -0
  11. data/lib/bridgetown-core/commands/doctor.rb +1 -19
  12. data/lib/bridgetown-core/commands/new.rb +2 -2
  13. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  14. data/lib/bridgetown-core/commands/serve.rb +0 -14
  15. data/lib/bridgetown-core/component.rb +178 -0
  16. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  17. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  18. data/lib/bridgetown-core/concerns/site/configurable.rb +10 -10
  19. data/lib/bridgetown-core/concerns/site/content.rb +56 -15
  20. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  21. data/lib/bridgetown-core/concerns/site/processable.rb +6 -4
  22. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  23. data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
  24. data/lib/bridgetown-core/concerns/validatable.rb +2 -5
  25. data/lib/bridgetown-core/configuration.rb +51 -30
  26. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  27. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  28. data/lib/bridgetown-core/configurations/tailwindcss.rb +1 -3
  29. data/lib/bridgetown-core/converter.rb +23 -0
  30. data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
  31. data/lib/bridgetown-core/converters/identity.rb +0 -9
  32. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  33. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  34. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +5 -38
  35. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  36. data/lib/bridgetown-core/converters/smartypants.rb +3 -1
  37. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  38. data/lib/bridgetown-core/current.rb +10 -0
  39. data/lib/bridgetown-core/document.rb +9 -16
  40. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  41. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  42. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  43. data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
  44. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  45. data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
  46. data/lib/bridgetown-core/entry_filter.rb +17 -28
  47. data/lib/bridgetown-core/errors.rb +0 -2
  48. data/lib/bridgetown-core/filters.rb +3 -26
  49. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  50. data/lib/bridgetown-core/filters/url_filters.rb +12 -0
  51. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  52. data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
  53. data/lib/bridgetown-core/helpers.rb +48 -9
  54. data/lib/bridgetown-core/layout.rb +28 -13
  55. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  56. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  57. data/lib/bridgetown-core/model/base.rb +138 -0
  58. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  59. data/lib/bridgetown-core/model/origin.rb +38 -0
  60. data/lib/bridgetown-core/model/repo_origin.rb +126 -0
  61. data/lib/bridgetown-core/page.rb +11 -2
  62. data/lib/bridgetown-core/plugin_manager.rb +1 -3
  63. data/lib/bridgetown-core/publisher.rb +8 -2
  64. data/lib/bridgetown-core/reader.rb +37 -22
  65. data/lib/bridgetown-core/readers/data_reader.rb +5 -5
  66. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  67. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  68. data/lib/bridgetown-core/readers/post_reader.rb +5 -4
  69. data/lib/bridgetown-core/regenerator.rb +9 -2
  70. data/lib/bridgetown-core/related_posts.rb +9 -6
  71. data/lib/bridgetown-core/renderer.rb +6 -13
  72. data/lib/bridgetown-core/resource/base.rb +313 -0
  73. data/lib/bridgetown-core/resource/destination.rb +49 -0
  74. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  75. data/lib/bridgetown-core/resource/relations.rb +132 -0
  76. data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
  77. data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
  78. data/lib/bridgetown-core/resource/transformer.rb +177 -0
  79. data/lib/bridgetown-core/ruby_template_view.rb +11 -11
  80. data/lib/bridgetown-core/site.rb +13 -6
  81. data/lib/bridgetown-core/static_file.rb +33 -10
  82. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  83. data/lib/bridgetown-core/tags/include.rb +1 -1
  84. data/lib/bridgetown-core/tags/post_url.rb +2 -2
  85. data/lib/bridgetown-core/url.rb +1 -0
  86. data/lib/bridgetown-core/utils.rb +49 -43
  87. data/lib/bridgetown-core/utils/require_gems.rb +60 -0
  88. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  89. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  90. data/lib/bridgetown-core/version.rb +2 -2
  91. data/lib/bridgetown-core/watcher.rb +1 -1
  92. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  93. data/lib/site_template/package.json.erb +2 -2
  94. data/lib/site_template/plugins/site_builder.rb +1 -1
  95. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  96. data/lib/site_template/webpack.config.js.erb +26 -6
  97. metadata +39 -40
  98. data/lib/bridgetown-core/external.rb +0 -58
  99. data/lib/bridgetown-core/page_without_a_file.rb +0 -17
  100. data/lib/bridgetown-core/path_manager.rb +0 -31
  101. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  102. data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
  103. data/lib/bridgetown-core/utils/exec.rb +0 -26
  104. data/lib/bridgetown-core/utils/internet.rb +0 -37
  105. data/lib/bridgetown-core/utils/platforms.rb +0 -80
  106. data/lib/bridgetown-core/utils/thread_event.rb +0 -31
  107. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
4
+ version: 0.21.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -206,20 +220,6 @@ dependencies:
206
220
  - - "~>"
207
221
  - !ruby/object:Gem::Version
208
222
  version: '3.0'
209
- - !ruby/object:Gem::Dependency
210
- name: pathutil
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: '0.9'
216
- type: :runtime
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: '0.9'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: rouge
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -234,20 +234,6 @@ dependencies:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
236
  version: '3.0'
237
- - !ruby/object:Gem::Dependency
238
- name: safe_yaml
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '1.0'
244
- type: :runtime
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - "~>"
249
- - !ruby/object:Gem::Version
250
- version: '1.0'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: terminal-table
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -327,6 +313,7 @@ files:
327
313
  - lib/bridgetown-core/commands/concerns/actions.rb
328
314
  - lib/bridgetown-core/commands/concerns/build_options.rb
329
315
  - lib/bridgetown-core/commands/concerns/configuration_overridable.rb
316
+ - lib/bridgetown-core/commands/concerns/git_helpers.rb
330
317
  - lib/bridgetown-core/commands/concerns/summarizable.rb
331
318
  - lib/bridgetown-core/commands/configure.rb
332
319
  - lib/bridgetown-core/commands/console.rb
@@ -336,7 +323,9 @@ files:
336
323
  - lib/bridgetown-core/commands/registrations.rb
337
324
  - lib/bridgetown-core/commands/serve.rb
338
325
  - lib/bridgetown-core/commands/serve/servlet.rb
326
+ - lib/bridgetown-core/component.rb
339
327
  - lib/bridgetown-core/concerns/data_accessible.rb
328
+ - lib/bridgetown-core/concerns/front_matter_importer.rb
340
329
  - lib/bridgetown-core/concerns/layout_placeable.rb
341
330
  - lib/bridgetown-core/concerns/liquid_renderable.rb
342
331
  - lib/bridgetown-core/concerns/publishable.rb
@@ -369,7 +358,10 @@ files:
369
358
  - lib/bridgetown-core/converters/liquid_templates.rb
370
359
  - lib/bridgetown-core/converters/markdown.rb
371
360
  - lib/bridgetown-core/converters/markdown/kramdown_parser.rb
361
+ - lib/bridgetown-core/converters/ruby_templates.rb
372
362
  - lib/bridgetown-core/converters/smartypants.rb
363
+ - lib/bridgetown-core/core_ext/psych.rb
364
+ - lib/bridgetown-core/current.rb
373
365
  - lib/bridgetown-core/deprecator.rb
374
366
  - lib/bridgetown-core/document.rb
375
367
  - lib/bridgetown-core/drops/bridgetown_drop.rb
@@ -378,6 +370,8 @@ files:
378
370
  - lib/bridgetown-core/drops/drop.rb
379
371
  - lib/bridgetown-core/drops/excerpt_drop.rb
380
372
  - lib/bridgetown-core/drops/page_drop.rb
373
+ - lib/bridgetown-core/drops/relations_drop.rb
374
+ - lib/bridgetown-core/drops/resource_drop.rb
381
375
  - lib/bridgetown-core/drops/site_drop.rb
382
376
  - lib/bridgetown-core/drops/static_file_drop.rb
383
377
  - lib/bridgetown-core/drops/unified_payload_drop.rb
@@ -385,10 +379,10 @@ files:
385
379
  - lib/bridgetown-core/entry_filter.rb
386
380
  - lib/bridgetown-core/errors.rb
387
381
  - lib/bridgetown-core/excerpt.rb
388
- - lib/bridgetown-core/external.rb
389
382
  - lib/bridgetown-core/filters.rb
390
383
  - lib/bridgetown-core/filters/condition_helpers.rb
391
384
  - lib/bridgetown-core/filters/date_filters.rb
385
+ - lib/bridgetown-core/filters/from_liquid.rb
392
386
  - lib/bridgetown-core/filters/grouping_filters.rb
393
387
  - lib/bridgetown-core/filters/url_filters.rb
394
388
  - lib/bridgetown-core/frontmatter_defaults.rb
@@ -405,24 +399,31 @@ files:
405
399
  - lib/bridgetown-core/log_adapter.rb
406
400
  - lib/bridgetown-core/log_writer.rb
407
401
  - lib/bridgetown-core/mime.types
402
+ - lib/bridgetown-core/model/base.rb
403
+ - lib/bridgetown-core/model/builder_origin.rb
404
+ - lib/bridgetown-core/model/origin.rb
405
+ - lib/bridgetown-core/model/repo_origin.rb
408
406
  - lib/bridgetown-core/page.rb
409
- - lib/bridgetown-core/page_without_a_file.rb
410
- - lib/bridgetown-core/path_manager.rb
411
407
  - lib/bridgetown-core/plugin.rb
412
408
  - lib/bridgetown-core/plugin_manager.rb
413
409
  - lib/bridgetown-core/publisher.rb
414
410
  - lib/bridgetown-core/reader.rb
415
- - lib/bridgetown-core/readers/collection_reader.rb
416
411
  - lib/bridgetown-core/readers/data_reader.rb
417
412
  - lib/bridgetown-core/readers/defaults_reader.rb
418
413
  - lib/bridgetown-core/readers/layout_reader.rb
419
414
  - lib/bridgetown-core/readers/page_reader.rb
420
415
  - lib/bridgetown-core/readers/plugin_content_reader.rb
421
416
  - lib/bridgetown-core/readers/post_reader.rb
422
- - lib/bridgetown-core/readers/static_file_reader.rb
423
417
  - lib/bridgetown-core/regenerator.rb
424
418
  - lib/bridgetown-core/related_posts.rb
425
419
  - lib/bridgetown-core/renderer.rb
420
+ - lib/bridgetown-core/resource/base.rb
421
+ - lib/bridgetown-core/resource/destination.rb
422
+ - lib/bridgetown-core/resource/permalink_processor.rb
423
+ - lib/bridgetown-core/resource/relations.rb
424
+ - lib/bridgetown-core/resource/taxonomy_term.rb
425
+ - lib/bridgetown-core/resource/taxonomy_type.rb
426
+ - lib/bridgetown-core/resource/transformer.rb
426
427
  - lib/bridgetown-core/ruby_template_view.rb
427
428
  - lib/bridgetown-core/site.rb
428
429
  - lib/bridgetown-core/static_file.rb
@@ -439,14 +440,12 @@ files:
439
440
  - lib/bridgetown-core/url.rb
440
441
  - lib/bridgetown-core/utils.rb
441
442
  - lib/bridgetown-core/utils/ansi.rb
442
- - lib/bridgetown-core/utils/exec.rb
443
- - lib/bridgetown-core/utils/internet.rb
444
- - lib/bridgetown-core/utils/platforms.rb
443
+ - lib/bridgetown-core/utils/require_gems.rb
445
444
  - lib/bridgetown-core/utils/ruby_exec.rb
446
- - lib/bridgetown-core/utils/thread_event.rb
447
- - lib/bridgetown-core/utils/win_tz.rb
445
+ - lib/bridgetown-core/utils/ruby_front_matter.rb
448
446
  - lib/bridgetown-core/version.rb
449
447
  - lib/bridgetown-core/watcher.rb
448
+ - lib/bridgetown-core/yaml_parser.rb
450
449
  - lib/site_template/.gitignore
451
450
  - lib/site_template/Gemfile.erb
452
451
  - lib/site_template/README.md
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module External
5
- class << self
6
- #
7
- # Require a gem or file if it's present, otherwise silently fail.
8
- #
9
- # names - a string gem name or array of gem names
10
- #
11
- def require_if_present(names)
12
- Array(names).each do |name|
13
- require name
14
- rescue LoadError
15
- Bridgetown.logger.debug "Couldn't load #{name}. Skipping."
16
- yield(name, version_constraint(name)) if block_given?
17
- false
18
- end
19
- end
20
-
21
- #
22
- # The version constraint required to activate a given gem.
23
- #
24
- # Returns a String version constraint in a parseable form for
25
- # RubyGems.
26
- def version_constraint
27
- "> 0"
28
- end
29
-
30
- #
31
- # Require a gem or gems. If it's not present, show a very nice error
32
- # message that explains everything and is much more helpful than the
33
- # normal LoadError.
34
- #
35
- # names - a string gem name or array of gem names
36
- #
37
- def require_with_graceful_fail(names)
38
- Array(names).each do |name|
39
- Bridgetown.logger.debug "Requiring:", name.to_s
40
- require name
41
- rescue LoadError => e
42
- Bridgetown.logger.error "Dependency Error:", <<~MSG
43
- Yikes! It looks like you don't have #{name} or one of its dependencies installed.
44
- In order to use Bridgetown as currently configured, you'll need to install this gem.
45
-
46
- If you've run Bridgetown with `bundle exec`, ensure that you have included the #{name}
47
- gem in your Gemfile as well.
48
-
49
- The full error message from Ruby is: '#{e.message}'
50
-
51
- If you run into trouble, you can find helpful resources at https://www.bridgetownrb.com/docs/community/
52
- MSG
53
- raise Bridgetown::Errors::MissingDependencyException, name
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- # A Bridgetown::Page subclass to handle processing files without reading it to
5
- # determine the page-data and page-content based on Front Matter delimiters.
6
- #
7
- # The class instance is basically just a bare-bones entity with just
8
- # attributes "dir", "name", "path", "url" defined on it.
9
- class PageWithoutAFile < Page
10
- Bridgetown.logger.warn "NOTICE: the PageWithoutAFile class is deprecated and" \
11
- " will be removed in Bridgetown 0.20."
12
-
13
- def read_yaml(*)
14
- @data ||= {}
15
- end
16
- end
17
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- # A singleton class that caches frozen instances of path strings returned from its methods.
5
- #
6
- # NOTE:
7
- # This class exists because `File.join` allocates an Array and returns a new String on every
8
- # call using **the same arguments**. Caching the result means reduced memory usage.
9
- # However, the caches are never flushed so that they can be used even when a site is
10
- # regenerating. The results are frozen to deter mutation of the cached string.
11
- #
12
- # Therefore, employ this class only for situations where caching the result is necessary
13
- # for performance reasons.
14
- #
15
- class PathManager
16
- # This class cannot be initialized from outside
17
- private_class_method :new
18
-
19
- # Wraps `File.join` to cache the frozen result.
20
- # Reassigns `nil`, empty strings and empty arrays to a frozen empty string beforehand.
21
- #
22
- # Returns a frozen string.
23
- def self.join(base, item)
24
- base = "" if base.nil? || base.empty?
25
- item = "" if item.nil? || item.empty?
26
- @join ||= {}
27
- @join[base] ||= {}
28
- @join[base][item] ||= File.join(base, item).freeze
29
- end
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- class CollectionReader
5
- SPECIAL_COLLECTIONS = %w(posts data).freeze
6
-
7
- attr_reader :site, :content
8
-
9
- def initialize(site)
10
- @site = site
11
- @content = {}
12
- end
13
-
14
- # Read in all collections specified in the configuration
15
- #
16
- # Returns nothing.
17
- def read
18
- site.collections.each_value do |collection|
19
- collection.read unless SPECIAL_COLLECTIONS.include?(collection.label)
20
- end
21
- end
22
- end
23
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- class StaticFileReader
5
- attr_reader :site, :dir, :unfiltered_content
6
-
7
- def initialize(site, dir)
8
- @site = site
9
- @dir = dir
10
- @unfiltered_content = []
11
- end
12
-
13
- # Create a new StaticFile object for every entry in a given list of basenames.
14
- #
15
- # files - an array of file basenames.
16
- #
17
- # Returns an array of static files.
18
- def read(files)
19
- files.each do |file|
20
- @unfiltered_content << StaticFile.new(@site, @site.source, @dir, file)
21
- end
22
- @unfiltered_content
23
- end
24
- end
25
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
-
5
- module Bridgetown
6
- module Utils
7
- module Exec
8
- extend self
9
-
10
- # Runs a program in a sub-shell.
11
- #
12
- # *args - a list of strings containing the program name and arguments
13
- #
14
- # Returns a Process::Status and a String of output in an array in
15
- # that order.
16
- def run(*args)
17
- stdin, stdout, stderr, process = Open3.popen3(*args)
18
- out = stdout.read.strip
19
- err = stderr.read.strip
20
-
21
- [stdin, stdout, stderr].each(&:close)
22
- [process.value, out + err]
23
- end
24
- end
25
- end
26
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Utils
5
- module Internet
6
- # Public: Determine whether the present device has a connection to
7
- # the Internet. This allows plugin writers which require the outside
8
- # world to have a neat fallback mechanism for offline building.
9
- #
10
- # Example:
11
- # if Internet.connected?
12
- # Typhoeus.get("https://pages.github.com/versions.json")
13
- # else
14
- # Bridgetown.logger.warn "Warning:", "Version check has been disabled."
15
- # Bridgetown.logger.warn "", "Connect to the Internet to enable it."
16
- # nil
17
- # end
18
- #
19
- # Returns true if a DNS call can successfully be made, or false if not.
20
-
21
- module_function
22
-
23
- def connected?
24
- !dns("example.com").nil?
25
- end
26
-
27
- def dns(domain)
28
- require "resolv"
29
- Resolv::DNS.open do |resolver|
30
- resolver.getaddress(domain)
31
- end
32
- rescue Resolv::ResolvError, Resolv::ResolvTimeout
33
- nil
34
- end
35
- end
36
- end
37
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Utils
5
- module Platforms
6
- extend self
7
-
8
- # TODO: jruby is NOT supported by Bridgetown. This should probably
9
- # get removed.
10
- { jruby?: "jruby", mri?: "ruby" }.each do |k, v|
11
- define_method k do
12
- ::RUBY_ENGINE == v
13
- end
14
- end
15
-
16
- # --
17
- # Allows you to detect "real" Windows, or what we would consider
18
- # "real" Windows. That is, that we can pass the basic test and the
19
- # /proc/version returns nothing to us.
20
- # --
21
-
22
- def vanilla_windows?
23
- RbConfig::CONFIG["host_os"] =~ %r!mswin|mingw|cygwin!i && \
24
- !proc_version
25
- end
26
-
27
- # --
28
- # XXX: Remove in 4.0
29
- # --
30
-
31
- alias_method :really_windows?, \
32
- :vanilla_windows?
33
-
34
- #
35
-
36
- def bash_on_windows?
37
- RbConfig::CONFIG["host_os"] =~ %r!linux! && \
38
- proc_version =~ %r!microsoft!i
39
- end
40
-
41
- #
42
-
43
- def windows?
44
- vanilla_windows? || bash_on_windows?
45
- end
46
-
47
- #
48
-
49
- def linux?
50
- RbConfig::CONFIG["host_os"] =~ %r!linux! && \
51
- proc_version !~ %r!microsoft!i
52
- end
53
-
54
- # Provides windows?, linux?, osx?, unix? so that we can detect
55
- # platforms. This is mostly useful for `bridgetown doctor` and for testing
56
- # where we kick off certain tests based on the platform.
57
-
58
- { osx?: %r!darwin|mac os!, unix?: %r!solaris|bsd! }.each do |k, v|
59
- define_method k do
60
- !!(
61
- RbConfig::CONFIG["host_os"] =~ v
62
- )
63
- end
64
- end
65
-
66
- #
67
-
68
- private
69
-
70
- def proc_version
71
- @proc_version ||=
72
- begin
73
- File.read("/proc/version")
74
- rescue Errno::ENOENT, Errno::EACCES
75
- nil
76
- end
77
- end
78
- end
79
- end
80
- end