bridgetown-core 0.19.0 → 0.21.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +6 -0
  3. data/bridgetown-core.gemspec +3 -4
  4. data/lib/bridgetown-core.rb +34 -12
  5. data/lib/bridgetown-core/cleaner.rb +7 -1
  6. data/lib/bridgetown-core/collection.rb +176 -77
  7. data/lib/bridgetown-core/commands/apply.rb +4 -3
  8. data/lib/bridgetown-core/commands/base.rb +9 -0
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
  10. data/lib/bridgetown-core/commands/configure.rb +66 -0
  11. data/lib/bridgetown-core/commands/console.rb +4 -0
  12. data/lib/bridgetown-core/commands/new.rb +8 -0
  13. data/lib/bridgetown-core/commands/plugins.rb +1 -0
  14. data/lib/bridgetown-core/component.rb +178 -0
  15. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  16. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  17. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
  18. data/lib/bridgetown-core/concerns/site/content.rb +56 -15
  19. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  20. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  21. data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
  22. data/lib/bridgetown-core/concerns/validatable.rb +1 -4
  23. data/lib/bridgetown-core/configuration.rb +49 -28
  24. data/lib/bridgetown-core/configurations/.keep +0 -0
  25. data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
  26. data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
  27. data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
  28. data/lib/bridgetown-core/configurations/netlify.rb +6 -0
  29. data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
  30. data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
  31. data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
  32. data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
  33. data/lib/bridgetown-core/configurations/swup.rb +37 -0
  34. data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
  35. data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
  36. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
  37. data/lib/bridgetown-core/configurations/turbo.rb +16 -0
  38. data/lib/bridgetown-core/converter.rb +23 -0
  39. data/lib/bridgetown-core/converters/erb_templates.rb +50 -41
  40. data/lib/bridgetown-core/converters/identity.rb +0 -9
  41. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  42. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +3 -0
  43. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  44. data/lib/bridgetown-core/current.rb +10 -0
  45. data/lib/bridgetown-core/document.rb +6 -14
  46. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  47. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  48. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  49. data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
  50. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  51. data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
  52. data/lib/bridgetown-core/entry_filter.rb +10 -23
  53. data/lib/bridgetown-core/errors.rb +0 -2
  54. data/lib/bridgetown-core/filters.rb +3 -2
  55. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  56. data/lib/bridgetown-core/generator.rb +2 -1
  57. data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
  58. data/lib/bridgetown-core/helpers.rb +48 -9
  59. data/lib/bridgetown-core/layout.rb +28 -13
  60. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  61. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  62. data/lib/bridgetown-core/model/base.rb +138 -0
  63. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  64. data/lib/bridgetown-core/model/origin.rb +38 -0
  65. data/lib/bridgetown-core/model/repo_origin.rb +126 -0
  66. data/lib/bridgetown-core/page.rb +9 -1
  67. data/lib/bridgetown-core/plugin.rb +2 -26
  68. data/lib/bridgetown-core/plugin_manager.rb +0 -2
  69. data/lib/bridgetown-core/publisher.rb +7 -1
  70. data/lib/bridgetown-core/reader.rb +26 -13
  71. data/lib/bridgetown-core/readers/data_reader.rb +3 -4
  72. data/lib/bridgetown-core/readers/post_reader.rb +1 -1
  73. data/lib/bridgetown-core/regenerator.rb +8 -1
  74. data/lib/bridgetown-core/related_posts.rb +1 -1
  75. data/lib/bridgetown-core/renderer.rb +6 -13
  76. data/lib/bridgetown-core/resource/base.rb +317 -0
  77. data/lib/bridgetown-core/resource/destination.rb +49 -0
  78. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  79. data/lib/bridgetown-core/resource/relations.rb +132 -0
  80. data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
  81. data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
  82. data/lib/bridgetown-core/resource/transformer.rb +175 -0
  83. data/lib/bridgetown-core/ruby_template_view.rb +12 -4
  84. data/lib/bridgetown-core/site.rb +9 -1
  85. data/lib/bridgetown-core/static_file.rb +33 -10
  86. data/lib/bridgetown-core/url.rb +1 -0
  87. data/lib/bridgetown-core/utils.rb +48 -41
  88. data/lib/bridgetown-core/utils/platforms.rb +1 -0
  89. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  90. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  91. data/lib/bridgetown-core/version.rb +2 -2
  92. data/lib/bridgetown-core/watcher.rb +1 -1
  93. data/lib/site_template/README.md +70 -0
  94. data/lib/site_template/package.json.erb +2 -2
  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 +55 -39
  98. data/lib/bridgetown-core/page_without_a_file.rb +0 -17
  99. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  100. data/lib/bridgetown-core/utils/exec.rb +0 -26
  101. data/lib/bridgetown-core/utils/internet.rb +0 -37
  102. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -30,8 +30,8 @@
30
30
  "postcss-loader": "^4.1.0",
31
31
  "postcss-preset-env": "^6.7.0",
32
32
  <% else %>
33
- "node-sass": "^4.13.1",
34
- "sass-loader": "^8.0.2",
33
+ "sass": "^1.32.8",
34
+ "sass-loader": "^8.0.2",
35
35
  <% end %>
36
36
  "webpack": "^4.44.2",
37
37
  "webpack-cli": "^3.3.11",
@@ -21,6 +21,6 @@ def print_hi(name)
21
21
  end
22
22
  print_hi('Tom')
23
23
  #=> prints 'Hi, Tom' to STDOUT.
24
- ````
24
+ ```
25
25
 
26
26
  Check out the [Bridgetown docs](https://bridgetownrb.com/docs/) for more info on how to get the most out of Bridgetown. File all bugs/feature requests at [Bridgetown’s GitHub repo](https://github.com/bridgetownrb/bridgetown). If you have questions, you can ask them on [Bridgetown Discussions on GitHub](https://github.com/bridgetownrb/bridgetown/discussions).
@@ -3,7 +3,9 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3
3
  const ManifestPlugin = require("webpack-manifest-plugin");
4
4
 
5
5
  module.exports = {
6
- entry: "./frontend/javascript/index.js",
6
+ entry: {
7
+ main: "./frontend/javascript/index.js"
8
+ },
7
9
  devtool: "source-map",
8
10
  // Set some or all of these to true if you want more verbose logging:
9
11
  stats: {
@@ -14,7 +16,7 @@ module.exports = {
14
16
  },
15
17
  output: {
16
18
  path: path.resolve(__dirname, "output", "_bridgetown", "static", "js"),
17
- filename: "all.[contenthash].js",
19
+ filename: "[name].[contenthash].js",
18
20
  },
19
21
  resolve: {
20
22
  extensions: [".js", ".jsx"],
@@ -29,7 +31,7 @@ module.exports = {
29
31
  },
30
32
  plugins: [
31
33
  new MiniCssExtractPlugin({
32
- filename: "../css/all.[contenthash].css",
34
+ filename: "../css/[name].[contenthash].css",
33
35
  }),
34
36
  new ManifestPlugin({
35
37
  fileName: path.resolve(__dirname, ".bridgetown-webpack", "manifest.json"),
@@ -64,22 +66,30 @@ module.exports = {
64
66
  {
65
67
  loader: "css-loader",
66
68
  options: {
69
+ url: url => !url.startsWith('/'),
67
70
  importLoaders: 1
68
71
  }
69
72
  },
70
73
  "postcss-loader"
71
74
  ],
72
- },
75
+ },
73
76
  <% else %>
74
77
  {
75
78
  test: /\.(s[ac]|c)ss$/,
76
79
  use: [
77
80
  MiniCssExtractPlugin.loader,
78
- "css-loader",
81
+ {
82
+ loader: "css-loader",
83
+ options: {
84
+ url: url => !url.startsWith('/')
85
+ }
86
+ },
79
87
  {
80
88
  loader: "sass-loader",
81
89
  options: {
90
+ implementation: require("sass"),
82
91
  sassOptions: {
92
+ fiber: false,
83
93
  includePaths: [
84
94
  path.resolve(__dirname, "src/_components")
85
95
  ],
@@ -90,13 +100,23 @@ module.exports = {
90
100
  },
91
101
  <% end %>
92
102
  {
93
- test: /\.woff2?$|\.ttf$|\.eot$|\.svg$/,
103
+ test: /\.woff2?$|\.ttf$|\.eot$/,
94
104
  loader: "file-loader",
95
105
  options: {
106
+ name: "[name]-[contenthash].[ext]",
96
107
  outputPath: "../fonts",
97
108
  publicPath: "../fonts",
98
109
  },
99
110
  },
111
+ {
112
+ test: /\.png?$|\.gif$|\.jpg$|\.svg$/,
113
+ loader: "file-loader",
114
+ options: {
115
+ name: "[path][name]-[contenthash].[ext]",
116
+ outputPath: "../",
117
+ publicPath: "../",
118
+ },
119
+ },
100
120
  ],
101
121
  },
102
122
  };
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.0
4
+ version: 0.21.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-22 00:00:00.000000000 Z
11
+ date: 2021-04-25 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
@@ -170,14 +184,14 @@ dependencies:
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '4.0'
187
+ version: '5.0'
174
188
  type: :runtime
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '4.0'
194
+ version: '5.0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: liquid-component
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -192,20 +206,6 @@ dependencies:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0.1'
195
- - !ruby/object:Gem::Dependency
196
- name: liquid-render-tag
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '0.2'
202
- type: :runtime
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: '0.2'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: listen
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -220,20 +220,6 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '3.0'
223
- - !ruby/object:Gem::Dependency
224
- name: pathutil
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: '0.9'
230
- type: :runtime
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: '0.9'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: rouge
239
225
  requirement: !ruby/object:Gem::Requirement
@@ -282,14 +268,14 @@ dependencies:
282
268
  requirements:
283
269
  - - "~>"
284
270
  - !ruby/object:Gem::Version
285
- version: '1.0'
271
+ version: '1.1'
286
272
  type: :runtime
287
273
  prerelease: false
288
274
  version_requirements: !ruby/object:Gem::Requirement
289
275
  requirements:
290
276
  - - "~>"
291
277
  - !ruby/object:Gem::Version
292
- version: '1.0'
278
+ version: '1.1'
293
279
  - !ruby/object:Gem::Dependency
294
280
  name: tilt
295
281
  requirement: !ruby/object:Gem::Requirement
@@ -342,6 +328,7 @@ files:
342
328
  - lib/bridgetown-core/commands/concerns/build_options.rb
343
329
  - lib/bridgetown-core/commands/concerns/configuration_overridable.rb
344
330
  - lib/bridgetown-core/commands/concerns/summarizable.rb
331
+ - lib/bridgetown-core/commands/configure.rb
345
332
  - lib/bridgetown-core/commands/console.rb
346
333
  - lib/bridgetown-core/commands/doctor.rb
347
334
  - lib/bridgetown-core/commands/new.rb
@@ -349,7 +336,9 @@ files:
349
336
  - lib/bridgetown-core/commands/registrations.rb
350
337
  - lib/bridgetown-core/commands/serve.rb
351
338
  - lib/bridgetown-core/commands/serve/servlet.rb
339
+ - lib/bridgetown-core/component.rb
352
340
  - lib/bridgetown-core/concerns/data_accessible.rb
341
+ - lib/bridgetown-core/concerns/front_matter_importer.rb
353
342
  - lib/bridgetown-core/concerns/layout_placeable.rb
354
343
  - lib/bridgetown-core/concerns/liquid_renderable.rb
355
344
  - lib/bridgetown-core/concerns/publishable.rb
@@ -362,13 +351,29 @@ files:
362
351
  - lib/bridgetown-core/concerns/site/writable.rb
363
352
  - lib/bridgetown-core/concerns/validatable.rb
364
353
  - lib/bridgetown-core/configuration.rb
354
+ - lib/bridgetown-core/configurations/.keep
355
+ - lib/bridgetown-core/configurations/bt-postcss.rb
356
+ - lib/bridgetown-core/configurations/bt-postcss/postcss.config.js
357
+ - lib/bridgetown-core/configurations/minitesting.rb
358
+ - lib/bridgetown-core/configurations/netlify.rb
359
+ - lib/bridgetown-core/configurations/netlify/netlify.sh
360
+ - lib/bridgetown-core/configurations/netlify/netlify.toml
361
+ - lib/bridgetown-core/configurations/purgecss.rb
362
+ - lib/bridgetown-core/configurations/stimulus.rb
363
+ - lib/bridgetown-core/configurations/swup.rb
364
+ - lib/bridgetown-core/configurations/tailwindcss.rb
365
+ - lib/bridgetown-core/configurations/tailwindcss/css_imports.css
366
+ - lib/bridgetown-core/configurations/tailwindcss/postcss.config.js
367
+ - lib/bridgetown-core/configurations/turbo.rb
365
368
  - lib/bridgetown-core/converter.rb
366
369
  - lib/bridgetown-core/converters/erb_templates.rb
367
370
  - lib/bridgetown-core/converters/identity.rb
368
371
  - lib/bridgetown-core/converters/liquid_templates.rb
369
372
  - lib/bridgetown-core/converters/markdown.rb
370
373
  - lib/bridgetown-core/converters/markdown/kramdown_parser.rb
374
+ - lib/bridgetown-core/converters/ruby_templates.rb
371
375
  - lib/bridgetown-core/converters/smartypants.rb
376
+ - lib/bridgetown-core/current.rb
372
377
  - lib/bridgetown-core/deprecator.rb
373
378
  - lib/bridgetown-core/document.rb
374
379
  - lib/bridgetown-core/drops/bridgetown_drop.rb
@@ -377,6 +382,8 @@ files:
377
382
  - lib/bridgetown-core/drops/drop.rb
378
383
  - lib/bridgetown-core/drops/excerpt_drop.rb
379
384
  - lib/bridgetown-core/drops/page_drop.rb
385
+ - lib/bridgetown-core/drops/relations_drop.rb
386
+ - lib/bridgetown-core/drops/resource_drop.rb
380
387
  - lib/bridgetown-core/drops/site_drop.rb
381
388
  - lib/bridgetown-core/drops/static_file_drop.rb
382
389
  - lib/bridgetown-core/drops/unified_payload_drop.rb
@@ -388,6 +395,7 @@ files:
388
395
  - lib/bridgetown-core/filters.rb
389
396
  - lib/bridgetown-core/filters/condition_helpers.rb
390
397
  - lib/bridgetown-core/filters/date_filters.rb
398
+ - lib/bridgetown-core/filters/from_liquid.rb
391
399
  - lib/bridgetown-core/filters/grouping_filters.rb
392
400
  - lib/bridgetown-core/filters/url_filters.rb
393
401
  - lib/bridgetown-core/frontmatter_defaults.rb
@@ -404,14 +412,16 @@ files:
404
412
  - lib/bridgetown-core/log_adapter.rb
405
413
  - lib/bridgetown-core/log_writer.rb
406
414
  - lib/bridgetown-core/mime.types
415
+ - lib/bridgetown-core/model/base.rb
416
+ - lib/bridgetown-core/model/builder_origin.rb
417
+ - lib/bridgetown-core/model/origin.rb
418
+ - lib/bridgetown-core/model/repo_origin.rb
407
419
  - lib/bridgetown-core/page.rb
408
- - lib/bridgetown-core/page_without_a_file.rb
409
420
  - lib/bridgetown-core/path_manager.rb
410
421
  - lib/bridgetown-core/plugin.rb
411
422
  - lib/bridgetown-core/plugin_manager.rb
412
423
  - lib/bridgetown-core/publisher.rb
413
424
  - lib/bridgetown-core/reader.rb
414
- - lib/bridgetown-core/readers/collection_reader.rb
415
425
  - lib/bridgetown-core/readers/data_reader.rb
416
426
  - lib/bridgetown-core/readers/defaults_reader.rb
417
427
  - lib/bridgetown-core/readers/layout_reader.rb
@@ -422,6 +432,13 @@ files:
422
432
  - lib/bridgetown-core/regenerator.rb
423
433
  - lib/bridgetown-core/related_posts.rb
424
434
  - lib/bridgetown-core/renderer.rb
435
+ - lib/bridgetown-core/resource/base.rb
436
+ - lib/bridgetown-core/resource/destination.rb
437
+ - lib/bridgetown-core/resource/permalink_processor.rb
438
+ - lib/bridgetown-core/resource/relations.rb
439
+ - lib/bridgetown-core/resource/taxonomy_term.rb
440
+ - lib/bridgetown-core/resource/taxonomy_type.rb
441
+ - lib/bridgetown-core/resource/transformer.rb
425
442
  - lib/bridgetown-core/ruby_template_view.rb
426
443
  - lib/bridgetown-core/site.rb
427
444
  - lib/bridgetown-core/static_file.rb
@@ -438,16 +455,15 @@ files:
438
455
  - lib/bridgetown-core/url.rb
439
456
  - lib/bridgetown-core/utils.rb
440
457
  - lib/bridgetown-core/utils/ansi.rb
441
- - lib/bridgetown-core/utils/exec.rb
442
- - lib/bridgetown-core/utils/internet.rb
443
458
  - lib/bridgetown-core/utils/platforms.rb
444
459
  - lib/bridgetown-core/utils/ruby_exec.rb
460
+ - lib/bridgetown-core/utils/ruby_front_matter.rb
445
461
  - lib/bridgetown-core/utils/thread_event.rb
446
- - lib/bridgetown-core/utils/win_tz.rb
447
462
  - lib/bridgetown-core/version.rb
448
463
  - lib/bridgetown-core/watcher.rb
449
464
  - lib/site_template/.gitignore
450
465
  - lib/site_template/Gemfile.erb
466
+ - lib/site_template/README.md
451
467
  - lib/site_template/bridgetown.config.yml
452
468
  - lib/site_template/frontend/javascript/index.js.erb
453
469
  - lib/site_template/frontend/styles/index.css
@@ -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,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,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,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Utils
5
- module WinTZ
6
- extend self
7
-
8
- # Public: Calculate the Timezone for Windows when the config file has a defined
9
- # 'timezone' key.
10
- #
11
- # timezone - the IANA Time Zone specified in "_config.yml"
12
- #
13
- # Returns a string that ultimately re-defines ENV["TZ"] in Windows
14
- def calculate(timezone)
15
- External.require_with_graceful_fail("tzinfo") unless defined?(TZInfo)
16
- tz = TZInfo::Timezone.get(timezone)
17
- difference = Time.now.to_i - tz.now.to_i
18
- #
19
- # POSIX style definition reverses the offset sign.
20
- # e.g. Eastern Standard Time (EST) that is 5Hrs. to the 'west' of Prime Meridian
21
- # is denoted as:
22
- # EST+5 (or) EST+05:00
23
- # Reference: http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
24
- sign = difference.negative? ? "-" : "+"
25
- offset = sign == "-" ? "+" : "-" unless difference.zero?
26
- #
27
- # convert the difference (in seconds) to hours, as a rational number, and perform
28
- # a modulo operation on it.
29
- modulo = modulo_of(rational_hour(difference))
30
- #
31
- # Format the hour as a two-digit number.
32
- # Establish the minutes based on modulo expression.
33
- hh = format("%<hour>02d", hour: absolute_hour(difference).ceil)
34
- mm = modulo.zero? ? "00" : "30"
35
-
36
- Bridgetown.logger.debug "Timezone:", "#{timezone} #{offset}#{hh}:#{mm}"
37
- #
38
- # Note: The 3-letter-word below doesn't have a particular significance.
39
- "WTZ#{sign}#{hh}:#{mm}"
40
- end
41
-
42
- private
43
-
44
- # Private: Convert given seconds to an hour as a rational number.
45
- #
46
- # seconds - supplied as an integer, it is converted to a rational number.
47
- # 3600 - no. of seconds in an hour.
48
- #
49
- # Returns a rational number.
50
- def rational_hour(seconds)
51
- seconds.to_r / 3600
52
- end
53
-
54
- # Private: Convert given seconds to an hour as an absolute number.
55
- #
56
- # seconds - supplied as an integer, it is converted to its absolute.
57
- # 3600 - no. of seconds in an hour.
58
- #
59
- # Returns an integer.
60
- def absolute_hour(seconds)
61
- seconds.abs / 3600
62
- end
63
-
64
- # Private: Perform a modulo operation on a given fraction.
65
- #
66
- # fraction - supplied as a rational number, its numerator is divided
67
- # by its denominator and the remainder returned.
68
- #
69
- # Returns an integer.
70
- def modulo_of(fraction)
71
- fraction.numerator % fraction.denominator
72
- end
73
- end
74
- end
75
- end