immosquare-cleaner 0.1.10 → 0.1.11

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
  SHA256:
3
- metadata.gz: 50795a36ff8dc13390b41e0b9dd90bfc022369bee4e16f42d143e913340fbbb1
4
- data.tar.gz: 995716de9e442829586399ad171d12090fe78a343f6c4085318074c321665a36
3
+ metadata.gz: ab3996336fc3c838878d792d3a32f07f39bb28c403851d5e6e14997ee210df90
4
+ data.tar.gz: cbe3806e171f5aa52f2dac90ab0959e297dcb81b0e78699eee61f4dd49a5e8f1
5
5
  SHA512:
6
- metadata.gz: d80eac3c3314a34b279a1fe3c2ede81ec840b919cbc22ffc7fa3266f234a860b46d0651a16f59b03a148841c623dde689a1d87e272934a0d96ad3c3401c5e486
7
- data.tar.gz: 1ce219e30239ad611e26c3dff48860bdfcbb7fd3024501fcde44733733d1835de09b8943425cf94ff896b7c54f32a3138c45cb27254026f27ea6132a24aa462d
6
+ metadata.gz: b3de83f33a8c826458e50c7b9801687d5a6c14dca1c52126bc63d38bfb7a8f900086506b3304e5cc17df582ebf8c335a7da4c816bb2a6df89fd8742734bd18ea
7
+ data.tar.gz: '039ec5621025a918e3c2a75ff7e0a7466c322548e8c92574ee735a4e4b4671b42f4e57c4c01290a992de2186b3e61fb47f1c5d4c681b051c6e25e7a39b7ea0dd'
@@ -0,0 +1,102 @@
1
+ module ImmosquareCleaner
2
+ module Markdown
3
+ class << self
4
+
5
+
6
+ ##============================================================##
7
+ ## we want to clean the markdown files to have a uniform style
8
+ ## for the tables.
9
+ ##============================================================##
10
+ def clean(file_path)
11
+ results = []
12
+ array_to_parse = []
13
+ prev_line_special = false
14
+
15
+ ##============================================================##
16
+ ## We parse each line of the file
17
+ ##============================================================##
18
+ File.foreach(file_path) do |line|
19
+ if line.lstrip.start_with?("|")
20
+ array_to_parse << line
21
+ else
22
+ if !array_to_parse.empty?
23
+ results << cleaned_array(array_to_parse)
24
+ array_to_parse = []
25
+ end
26
+ new_line, prev_line_special = cleaned_line(line, prev_line_special)
27
+ results << new_line
28
+ end
29
+ end
30
+
31
+ ##============================================================##
32
+ ## Handle the case where the file ends with a table
33
+ ##============================================================##
34
+ results << cleaned_array(array_to_parse) if !array_to_parse.empty?
35
+
36
+ results.join
37
+ end
38
+
39
+
40
+ private
41
+
42
+ def cleaned_array(array_to_clean)
43
+ ##============================================================##
44
+ ## We split each line of the array and remove the empty cells
45
+ ## we also save the max lenght of each position in x.
46
+ ##============================================================##
47
+ elements_size = []
48
+ rows = array_to_clean.map do |line|
49
+ cells = line.split("|").map(&:strip).reject(&:empty?)
50
+
51
+ ##============================================================##
52
+ ## We increase the size of the array if needed
53
+ ##============================================================##
54
+ elements_size += Array.new(cells.length - elements_size.size, 0) if cells.length > elements_size.length
55
+
56
+ ##============================================================##
57
+ ## We update the max length of each position in x
58
+ ##============================================================##
59
+ cells.map(&:length).zip(elements_size).each_with_index do |(cell_length, max_length), index|
60
+ elements_size[index] = [cell_length, max_length].max
61
+ end
62
+
63
+ cells
64
+ end
65
+
66
+ ##============================================================##
67
+ ## We fill the empty cells with nil to have uniform rows
68
+ ##============================================================##
69
+ rows.each {|row| row.fill(nil, row.length...elements_size.size) }
70
+
71
+
72
+ formatted_rows = rows.map do |row|
73
+ line = row.each_with_index.map do |cell, index|
74
+ max_length = elements_size[index]
75
+ cell =
76
+ if cell&.match(/^-*$/)
77
+ "-" * max_length
78
+ else
79
+ cell.to_s.ljust(max_length)
80
+ end
81
+ end.join(" | ")
82
+ "| #{line} |"
83
+ end
84
+
85
+ "#{formatted_rows.join("\n")}\n"
86
+ end
87
+
88
+ ##============================================================##
89
+ ## We simply add a newline at the end of the line if needed
90
+ ##============================================================##
91
+ def cleaned_line(line, prev_line_special)
92
+ cleaned = line.rstrip
93
+ blank_line = line.gsub("\n", "").empty?
94
+ special = cleaned.lstrip.start_with?("*", "-", "+")
95
+ new_line = "#{"\n" if prev_line_special && !blank_line}#{cleaned}\n"
96
+ prev_line_special = special
97
+ [new_line, prev_line_special]
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.10".freeze
2
+ VERSION = "0.1.11".freeze
3
3
  end
@@ -2,6 +2,7 @@ require "English"
2
2
  require "immosquare-yaml"
3
3
  require "immosquare-extensions"
4
4
  require_relative "immosquare-cleaner/configuration"
5
+ require_relative "immosquare-cleaner/markdown"
5
6
  require_relative "immosquare-cleaner/railtie" if defined?(Rails)
6
7
 
7
8
  ##===========================================================================##
@@ -91,6 +92,17 @@ module ImmosquareCleaner
91
92
  return
92
93
  end
93
94
 
95
+ ##============================================================##
96
+ ## Markdown files
97
+ ##============================================================##
98
+ if file_path.end_with?(".md", ".md.erb")
99
+ formatted_md = ImmosquareCleaner::Markdown.clean(file_path)
100
+ File.write(file_path, formatted_md)
101
+ normalize_last_line(file_path)
102
+ return
103
+ end
104
+
105
+
94
106
  ##============================================================##
95
107
  ## Autres formats
96
108
  ##============================================================##
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rubocop
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: erb_lint
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +78,20 @@ dependencies:
92
78
  - - ">="
93
79
  - !ruby/object:Gem::Version
94
80
  version: 0.1.16
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1'
95
95
  description: Immosquare-cleaner streamlines Rails applications by running tools like
96
96
  RuboCop, ERBLint, Stylelint and more. It ensures code quality, readability, and
97
97
  consistency across the application.
@@ -105,6 +105,7 @@ files:
105
105
  - bin/immosquare-cleaner
106
106
  - lib/immosquare-cleaner.rb
107
107
  - lib/immosquare-cleaner/configuration.rb
108
+ - lib/immosquare-cleaner/markdown.rb
108
109
  - lib/immosquare-cleaner/railtie.rb
109
110
  - lib/immosquare-cleaner/version.rb
110
111
  - lib/tasks/immosquare_cleaner.rake