bujo 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664e04f1375ac40c4b16d5059c378097dd737d825060a4b372bc92f5cbd00654
4
- data.tar.gz: db563f28615432db6b2533c10a5a473a99ad519b706c59aa35cd335abd7f8e3d
3
+ metadata.gz: 2a25780a5bb46d60c4ab81971f3a50458e78f182b5936a6d4da48e4eb52df9f1
4
+ data.tar.gz: 1896a3b5766b0c5e5b6a1161cc09ec0648b4dd18a615c3290495b8eab96ded1a
5
5
  SHA512:
6
- metadata.gz: 7220cd47f03b84fdb97d1c1d65c82f5665a08351951dfb823195052e1a1eee945837d8b7c63686189a55bada05f0252443bedbbb24b98986cc29ac05a50e2227
7
- data.tar.gz: 0babbad55cdbc19fb8465abd7803c887f4b5b90e035e5c71d316ceae6f6734eac6b06baa0c6d76bb599e7721832acb35de41d7ebdee90038e40c109efb2c308b
6
+ metadata.gz: 5e904702b522a6e56bd28a88606c23acdd5221394ede72a52e1c1707ec8d812e2d4363ae6eb49523496ce2c6b14a4969bd1464fb32b51770024128edd0e5e548
7
+ data.tar.gz: 679f3911b5c95a160218c8bdac1272939c649ec3d74f7eabaed4a0ddcb374e62733832a49f16627fd9047e2272ff0c8ccccd7b8e2b2ef944c692ffdd4e5e00d2
@@ -35,8 +35,8 @@ module Plugins
35
35
  def convert_files
36
36
  puts "Converting to HTML..."
37
37
  Dir.glob(File.join(Configuration::Structure.sources_path, "**/*"))
38
- .select { |file| file =~ /.*\.adoc$/ }
39
- .each { |asciidoctor_file| Utils::Converter.convert_file(asciidoctor_file) }
38
+ .filter { |item| File.file?(item) }
39
+ .each { |file| Utils::Converter.for(file).convert }
40
40
  end
41
41
  end
42
42
  end
@@ -28,7 +28,7 @@ module Plugins
28
28
  @editor.call(relative_path)
29
29
 
30
30
  puts "Converting to HTML..."
31
- Utils::Converter.convert_file(relative_path)
31
+ Utils::Converter.for(relative_path).convert
32
32
  end
33
33
 
34
34
  end
@@ -1,5 +1,6 @@
1
1
  module Utils
2
2
  # Ruby
3
+ require 'fileutils'
3
4
  require 'asciidoctor'
4
5
 
5
6
  # Own
@@ -7,12 +8,35 @@ module Utils
7
8
  require 'bujo/configuration/globals'
8
9
 
9
10
  class Converter
10
- def self.convert_file(source_path)
11
+ def self.for(source_path)
12
+ source_path =~ /.*\.adoc$/ ? AsciidocFileConverter.new(source_path) : RegularFileConverter.new(source_path)
13
+ end
14
+
15
+ private def initialize(source_path)
16
+ @source_path = source_path
17
+ end
18
+
19
+ def convert
20
+ raise NotImplementedError
21
+ end
22
+ end
23
+
24
+ class RegularFileConverter < Converter
25
+ def convert
26
+ source_relative_path = Pathname.new(File.expand_path(@source_path)).relative_path_from(Pathname.new(Configuration::Structure.sources_path))
27
+ target_path = File.join(Configuration::Structure.targets_path, source_relative_path.to_s)
28
+ puts "Converting #{@source_path} to #{target_path}..." if Configuration::Globals.verbose
29
+ FileUtils.copy_file(@source_path, target_path)
30
+ end
31
+ end
32
+
33
+ class AsciidocFileConverter < Converter
34
+ def convert
11
35
  begin
12
- source_relative_path = Pathname.new(File.expand_path(source_path)).relative_path_from(Pathname.new(Configuration::Structure.sources_path))
13
- source_file = File.open(source_path)
36
+ source_relative_path = Pathname.new(File.expand_path(@source_path)).relative_path_from(Pathname.new(Configuration::Structure.sources_path))
37
+ source_file = File.open(@source_path)
14
38
  target_path = File.join(Configuration::Structure.targets_path, source_relative_path.to_s.gsub(/\.adoc/, ".html"))
15
- puts "Converting #{source_path} to #{target_path}..." if Configuration::Globals.verbose
39
+ puts "Converting #{@source_path} to #{target_path}..." if Configuration::Globals.verbose
16
40
  Asciidoctor.convert(
17
41
  source_file,
18
42
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bujo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Dupire