blog-tools 0.2.0 → 0.2.1

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: 7653d790bc62101631922de1c8288efe77d7ec2563c1ed1a0822aca09010f3b0
4
- data.tar.gz: dabe65fa231806eae07ed1e3a20b69a0dfa1c51074a033561c492848c366b024
3
+ metadata.gz: ccf964ed143ccaada2224313faf39eeefd1b06278f4643b83eb91d1200538e7f
4
+ data.tar.gz: 435b1cd63fcc143d02c720ffbeb251291e1a51dd86c8fd7c817171502d156b7c
5
5
  SHA512:
6
- metadata.gz: a8bca7ed225b601cf99e6a46f6169a1b747f30a3487e908524c4bbe98d01c7743f34e99e3433e5fbc55fdaa7e5461e656f6355351ad208c0cd19d1502d7c22a9
7
- data.tar.gz: b4bf5beb81654f40805b3d68ef412abebf8befa235aa55a533e8f834b301ec4e9859abe82efcfaf47c7511617ca34564397d8f0c0a43b8020aa535d3642f4f9c
6
+ metadata.gz: 2b66ac6f4d2ff10d3dac0b49f050b55ef6ee6ad8dfc8f6b7e86d5c82977fce189b0c239e371ea6bd56b6f31172a2a0886f1fbee2f1854b9745570cce31f79641
7
+ data.tar.gz: 22737f73babe47bdbd69c80e6e3d856ab88f455574813d6f5535a01f11b1ed86257fe2cc44b639954c297bc2e1b9d4d450a2b9f2ff6a68e9b2289eeb0a64d061
checksums.yaml.gz.sig CHANGED
Binary file
@@ -8,24 +8,65 @@ require_relative 'commands/config'
8
8
 
9
9
  require_relative 'storage'
10
10
 
11
- # BlogTools is the main namespace for the blog-tools CLI application
12
- # It contains submodules for command logic, file storage, and CLI Interfaces
11
+ # BlogTools is the main namespace for the blog-tools CLI application.
12
+ #
13
+ # It contains submodules for command logic, file storage, and CLI interfaces.
14
+ #
15
+ # @see BlogTools::CLI
13
16
  module BlogTools
14
- # CLI handles all top-level commands for the blog-tools application
15
- # It delegates to subcommands
17
+ # CLI is the entry point for the blog-tools command-line interface.
18
+ #
19
+ # It defines high-level commands like `generate`, `lists`, and `config`,
20
+ # and delegates their functionality to the appropriate subcommands.
21
+ #
22
+ # This class inherits from Thor, a Ruby gem for building command-line interfaces.
23
+ #
24
+ # @example Running the CLI
25
+ # blog-tools generate my-post
26
+ # blog-tools lists show my-list
27
+ # blog-tools config
28
+ #
29
+ # @see Commands::Generate
30
+ # @see Commands::Lists
31
+ # @see Commands::Config
16
32
  class CLI < Thor
33
+ # Creates a new CLI instance and initializes the storage backend.
34
+ #
35
+ # This is called automatically when the CLI is run.
36
+ #
37
+ # @param [Array] args arguments passed to Thor
38
+ # @return [void]
17
39
  def initialize(*args)
18
40
  super
19
41
  Storage.setup!
20
42
  end
21
43
 
44
+ # @!group Commands
45
+
46
+ # Registers the `generate` subcommand.
47
+ #
48
+ # This command allows users to generate a new blog post interactively.
49
+ #
50
+ # @see Commands::Generate
22
51
  desc 'generate', 'Create a new post'
23
52
  subcommand 'generate', Commands::Generate
24
53
 
25
- desc 'lists', 'Lists tools'
54
+ # Registers the `lists` subcommand.
55
+ #
56
+ # This command allows users to manage post lists.
57
+ #
58
+ # @see Commands::Lists
59
+ desc 'lists', 'Manage post lists'
26
60
  subcommand 'lists', Commands::Lists
27
61
 
62
+ # Registers the `config` subcommand.
63
+ #
64
+ # This command allows users to configure blog-tools settings.
65
+ #
66
+ # @see Commands::Config
28
67
  desc 'config', 'Configure blog-tools'
29
68
  subcommand 'config', Commands::Config
69
+
70
+ # @!endgroup
30
71
  end
31
72
  end
@@ -2,13 +2,8 @@
2
2
 
3
3
  module BlogTools
4
4
  module Commands
5
- # Config deals with all commands that configure how blog-tools works
5
+ # This command is a work in progress
6
6
  class Config < Thor
7
- desc 'TITLE', 'Configure blog-tools'
8
-
9
- def default(test)
10
- puts test
11
- end
12
7
  end
13
8
  end
14
9
  end
@@ -1,26 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'colorize'
3
4
  require 'erb'
4
5
  require 'date'
5
6
  require_relative '../storage'
6
7
 
7
8
  module BlogTools
8
9
  module Commands
9
- # Generate handles all of the subcommands related to generating posts
10
+ # BlogTools::Commands::Generate handles post generation
11
+ #
12
+ # It is a Thor-based CLI command set for generating blog posts
13
+ # It supports options like specifying a custom template, defining the author,
14
+ # setting tags, and defining the post content.
15
+ #
16
+ # @example Generate a basic post
17
+ # blog-tools generate post "My post Title"
18
+ #
19
+ # @example Generate a post with tags and author
20
+ # blog-tools generate post "My post Title" --tags ruby blog --author username
21
+ #
22
+ # @see BlogTools::CLI
23
+ # @see Storage::CONFIG_FILE
24
+ # @see Storage::TEMPLATES_DIR
10
25
  class Generate < Thor
11
26
  desc 'post TITLE', 'Generate a new blog post'
12
27
  method_option :template, type: :string, desc: 'Specify a template file'
13
28
  method_option :tags, type: :array, desc: 'Specify tags (space separated)'
14
29
  method_option :author, type: :string, desc: 'Specify author'
15
- method_option :output, type: :string, desc: 'Output path or filename (default: title.md)'
30
+ method_option :output, type: :string, desc: 'Output directory'
16
31
  method_option :content, type: :string, desc: 'Path to content of post'
32
+
33
+ # Generates a new blog post from a template
34
+ #
35
+ # This command uses ERB templates to render a new post from a template
36
+ # You can customize the template, author, tags, and content, as well as
37
+ # where to save the file to.
38
+ #
39
+ # @param [String] title The title of the post
40
+ # @option options [String] :template Path to the ERB template
41
+ # @option options [Array<String>] :tags Tags to associate with the post
42
+ # @option options [String] :author Name of the author (overrides default in config file)
43
+ # @option options [String] :output Output directory (default: current)
44
+ # @option options [String] :content Path to file containing the post content
45
+ # @example
46
+ # ❯ blog-tools generate post example
47
+ # [✓] Post generated at example.md
48
+ # @return [Nil]
49
+ # @see ::ERB
50
+ # @see ::Date
51
+ # @see String#Colorize
17
52
  def post(title)
18
53
  config = File.exist?(Storage::CONFIG_FILE) ? YAML.load_file(Storage::CONFIG_FILE) : {}
19
54
 
20
55
  template_file = options[:template] || config['default_template'] || 'post.md'
21
56
  template_path = File.expand_path(File.join(Storage::TEMPLATES_DIR + template_file))
22
57
 
23
- return puts("[!] Template file not found: #{template_path}") unless File.exist?(template_path)
58
+ return puts "[!] Template file not found: #{template_path}".colorize(:red) unless File.exist?(template_path)
24
59
 
25
60
  template = File.read(template_path)
26
61
  renderer = ERB.new(template)
@@ -34,10 +69,15 @@ module BlogTools
34
69
  )
35
70
 
36
71
  dir_path = "#{options[:output]}/"
37
- output_filename = options[:output] ? "#{dir_path}#{title}.md" : "#{title.downcase.strip.gsub(/\s+/, '_')}.md"
72
+ output_filename = if options[:output]
73
+ "#{dir_path}#{title}.md"
74
+ else
75
+ "#{title.downcase.strip.gsub(/\s+/,
76
+ '_')}.md"
77
+ end
38
78
  File.write(output_filename, result)
39
79
 
40
- puts "[✓] Post generated at #{output_filename}"
80
+ puts "[✓] Post generated at #{output_filename}".colorize(:green)
41
81
  end
42
82
  end
43
83
  end
@@ -1,26 +1,83 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'colorize'
4
+
3
5
  require_relative '../storage'
4
6
 
5
7
  module BlogTools
6
8
  module Commands
7
- # List handles all of the subcommands dealing with makes, editing, and
9
+ # BlogTools::Commands::Lists handles post lists
10
+ #
11
+ # List handles all of the subcommands dealing with making, editing, and
8
12
  # creating lists of blog post ideas
9
13
  #
10
- # TODO option to add file path to the post
14
+ # @example Show all posts in a list
15
+ # blog-tools lists show list
16
+ #
17
+ # @example Remove a post from a list
18
+ # blog-tools lists remove list post
19
+ #
20
+ # @see BlogTools::CLI
21
+ # @see BlogTools::Storage
11
22
  class Lists < Thor
23
+ # Initializes the `lists` command with stored list data.
24
+ #
25
+ # This constructor is automatically called by Thor when the `lists` subcommand is invoked.
26
+ # It loads existing lists from storage into the `@lists` instance variable.
27
+ #
28
+ # @param [Array<String>] args Command-line arguments passed to the subcommand from Thor
29
+ # @see BlogTools::Storage::LISTS_FILE
12
30
  def initialize(*args)
13
31
  super
14
32
  @lists = Storage.read_lists || {}
15
33
  end
16
34
 
17
- desc 'list LIST', 'View all posts in a list'
35
+ desc 'show LIST', 'View all posts in a list'
18
36
  method_option :completed, type: :boolean, default: false, desc: 'Show only completed posts'
19
- method_option :in_progress, type: :boolean, default: false, desc: 'show only in-progress posts'
37
+ method_option :in_progress, type: :boolean, default: false, desc: 'Show only in-progress posts'
20
38
  method_option :status, type: :boolean, default: false, desc: 'Show post status as well'
21
- # TODO: all option for all information about the post
22
- def list(list)
23
- return puts('[!] List not found') unless @lists[list]
39
+ # Shows all posts that are in a list
40
+ #
41
+ # This command reads the list from the `@lists` variable, and then shows it
42
+ # You can customize what it shows (completed/uncompleted), and if it shows
43
+ # the status of the post.
44
+ #
45
+ # @param [String] list The name of the list
46
+ # @option options [Boolean] :completed Show only posts that are completed.
47
+ # @option options [Boolean] :in_progress Show only posts that are in progress.
48
+ # @option options [Boolean] :status Show the status of the posts in the list.
49
+ # @example Basic usage
50
+ # ❯ blog-tools lists show example
51
+ # EXAMPLE
52
+ # - example-post-1
53
+ # - example-post-2
54
+ # - example-post-3
55
+ # - example-post-4
56
+ # - example-post-5
57
+ #
58
+ # @example using the `--status` flag
59
+ # ❯ blog-tools lists show example --status
60
+ # EXAMPLE
61
+ # - [✓] example-post-1
62
+ # - [~] example-post-2
63
+ # - [✓] example-post-3
64
+ # - [ ] example-post-4
65
+ # - [ ] example-post-5
66
+ #
67
+ # @example using the `--completed` flag
68
+ # ❯ blog-tools lists show example --completed
69
+ # EXAMPLE
70
+ # - example-post-1
71
+ # - example-post-3
72
+ #
73
+ # @example using the `--in-progress` flag
74
+ # ❯ blog-tools lists show example --in-progress
75
+ # EXAMPLE
76
+ # - example-post-2
77
+ #
78
+ # @return [Nil]
79
+ def show(list)
80
+ return puts '[!] List not found'.colorize(:red) unless @lists[list]
24
81
 
25
82
  puts list.upcase
26
83
  @lists[list][:posts].each do |item, data|
@@ -44,58 +101,112 @@ module BlogTools
44
101
  end
45
102
 
46
103
  desc 'create NAME', 'Create a list'
104
+ # Creates a new list
105
+ #
106
+ # This command takes in a name for a list, and then creates a new list in
107
+ # the lists configuration file.
108
+ #
109
+ # @param [String] list The name of the list
110
+ # @example creating a new list
111
+ # ❯ blog-tools lists create test
112
+ # [✓] Created list: test
113
+ #
114
+ # @return [Nil]
47
115
  def create(name)
48
116
  @lists[name] = { posts: {} }
49
117
  Storage.write_lists(@lists)
50
- puts "[✓] Created list: #{name}"
118
+ puts "[✓] Created list: #{name}".colorize(:green)
51
119
  end
52
120
 
53
121
  desc 'add LIST POST', 'Add a post to a list'
122
+ # Adds a post to a list
123
+ #
124
+ # This command takes the name of a list and the name of a post to be added.
125
+ # Assuming that the list exists, it will add the post to the list, and
126
+ # write the result to the list configuration file
127
+ #
128
+ # @param [String] list The name of the list
129
+ # @param [String] post_name The name of the post
130
+ # @example Adding a post to a list
131
+ # ❯ blog-tools lists add test example
132
+ # [✓] Added example to test list
133
+ # @return [Nil]
54
134
  def add(list, post_name)
55
- return puts('[!] List not found') unless @lists[list]
135
+ return puts '[!] List not found'.colorize(:red) unless @lists[list]
56
136
 
57
137
  @lists[list][:posts][post_name] = { completed: false, in_progress: false }
58
- puts "[✓] Added #{post_name} to #{list} list"
59
138
  Storage.write_lists(@lists)
139
+ puts "[✓] Added #{post_name} to #{list} list".colorize(:green)
60
140
  end
61
141
 
62
142
  desc 'delete LIST', 'Delete a list'
143
+ # Deletes a list
144
+ #
145
+ # This command takes in the name of a list and deletes it from the lists
146
+ # configuration file. It requires user input to confirm the deletion of
147
+ # the list. Once the user gives confirmation, it edits the `@lists`
148
+ # variable and writes it back to the lists configuration file.
149
+ #
150
+ # @param [String] list The name of the list
151
+ # @example Deleting a list
152
+ # ❯ blog-tools lists delete test
153
+ # [?] Are you sure you want to delete the 'test' list?
154
+ # [?] This action cannot be undone. Proceed? (y/N)
155
+ # > y
156
+ # [✓] Deleted 'test' list
157
+ # @return [Nil]
63
158
  def delete(list)
64
- return puts('[!] List not found') unless @lists[list]
159
+ return puts '[!] List not found'.colorize(:red) unless @lists[list]
65
160
 
66
- puts "[?] Are you sure you want to delete the '#{list}' list?"
67
- print "[?] This action cannot be undone. Proceed? (y/N)\n> "
161
+ puts "[?] Are you sure you want to delete the '#{list}' list?".colorize(:yellow)
162
+ print "[?] This action cannot be undone. Proceed? (y/N)\n> ".colorize(:yellow)
68
163
  input = $stdin.gets.chomp.strip
69
164
 
70
165
  case input.downcase
71
166
  when 'y'
72
167
  @lists.delete(list)
73
168
  Storage.write_lists(@lists)
74
- puts "[✓] Deleted '#{list}' list"
169
+ puts "[✓] Deleted '#{list}' list".colorize(:green)
75
170
  when 'n', ''
76
- puts '[i] Cancelled deletion.'
171
+ puts '[i] Cancelled deletion.'.colorize(:blue)
77
172
  else
78
- puts '[!] Invalid input. Not deleting.'
173
+ puts '[!] Invalid input. Not deleting.'.colorize(:red)
79
174
  end
80
175
  end
81
176
 
82
177
  desc 'remove LIST POST', 'Remove a post from a list'
178
+ # Removes a post from a list
179
+ #
180
+ # This command take in both a list name and a post name, and then removes
181
+ # the post from the list. It requires user confirmation in order to make
182
+ # the deletion. Once the user confirms, it edits the `@lists` variable,
183
+ # and writes it to the lists configuration file.
184
+ #
185
+ # @param [String] list The name of the list
186
+ # @param [String] post_name The name of the post
187
+ # @example
188
+ # ❯ blog-tools lists remove example example-post-1
189
+ # [?] Are you sure you want to delete the post 'example-post-1'?
190
+ # [?] This action cannot be undone. Proceed? (y/N)
191
+ # > y
192
+ # [✓] Deleted 'example-post-1' post
193
+ # @return [Nil]
83
194
  def remove(list, post_name)
84
- return puts('[!] List not found') unless @lists[list]
195
+ return puts '[!] List not found'.colorize(:red) unless @lists[list]
85
196
 
86
- puts "[?] Are you sure you want to delete the post '#{post_name}'?"
87
- print "[?] This action cannot be undone. Proceed? (y/N)\n> "
197
+ puts "[?] Are you sure you want to delete the post '#{post_name}'?".colorize(:yellow)
198
+ print "[?] This action cannot be undone. Proceed? (y/N)\n> ".colorize(:yellow)
88
199
  input = $stdin.gets.chomp.strip
89
200
 
90
201
  case input.downcase
91
202
  when 'y'
92
203
  @lists[list][:posts].delete(post_name)
93
204
  Storage.write_lists(@lists)
94
- puts "[✓] Deleted '#{post_name}' post"
205
+ puts "[✓] Deleted '#{post_name}' post".colorize(:green)
95
206
  when 'n', ''
96
- puts '[i] Cancelled deletion.'
207
+ puts '[i] Cancelled deletion.'.colorize(:blue)
97
208
  else
98
- puts '[!] Invalid input. Not deleting.'
209
+ puts '[!] Invalid input. Not deleting.'.colorize(:red)
99
210
  end
100
211
  end
101
212
 
@@ -104,30 +215,56 @@ module BlogTools
104
215
  method_option :in_progress, type: :boolean, default: false, desc: 'Mark as in progress'
105
216
  method_option :path, type: :string, desc: 'Path to the post contents'
106
217
  method_option :tags, type: :array
218
+ # Updates aspects of a post in a list
219
+ #
220
+ # This command takes a list and post, and requires a flag to be set to
221
+ # run. If no flag is set it will return. The set flag and the parameter
222
+ # with the flag are added into the lists configuration file under the
223
+ # post.
224
+ #
225
+ # @param [String] list The name of the list
226
+ # @param [String] post_name The name of the post
227
+ # @option options [Boolean] :completed This marks a post as completed
228
+ # @option options [Boolean] :in_progress This marks a post as in progress
229
+ # @option options [String] :path This specifies the path to the post's contents
230
+ # @option options [Array] :tags This adds tags to the post in the list
231
+ # @example Using the `--completed` flag.
232
+ # ❯ blog-tools lists update example example-post-1 --completed
233
+ # [✓] Marked 'example-post-1' as complete
234
+ # @example Using the `--in-progress` flag.
235
+ # ❯ blog-tools lists update example example-post-2 --in-progress
236
+ # [✓] Marked 'example-post-2' as in progress
237
+ # @example Using the `--path` flag.
238
+ # ❯ blog-tools lists update example example-post-1 --path ~/documents/writeup.md
239
+ # The post content is located at: /home/slavetomints/documents/writeup.md
240
+ # @example Using the `--tags` flag.
241
+ # ❯ blog-tools lists update example example-post-3 --tags 1 2 3
242
+ # Added the following tags to the post: ["1", "2", "3"]
243
+ # @return [Nil]
107
244
  def update(list, post_name)
108
245
  unless options[:completed] || options[:in_progress] || options[:tags] || options[:path]
109
- return puts('[!] Please specify a status. Type "blog-tools lists help update" for more info.')
246
+ return puts '[!] Please specify a status. Type "blog-tools lists help update" for more info.'.colorize(:red)
110
247
  end
111
- return puts('[!] List not found') unless @lists[list]
112
- return puts('[!] Post not found') unless @lists[list][:posts].key?(post_name)
248
+ return puts '[!] List not found'.colorize(:red) unless @lists[list]
249
+ return puts '[!] Post not found'.colorize(:red) unless @lists[list][:posts].key?(post_name)
113
250
 
114
251
  post = @lists[list][:posts][post_name]
115
252
 
116
253
  if options[:completed]
117
254
  if post[:completed]
118
- puts('[!] Post already marked as complete')
255
+ puts '[!] Post already marked as complete'.colorize(:redd)
119
256
  else
120
257
  post[:completed] = true
121
- puts("[✓] Marked '#{post_name}' as complete")
258
+ puts "[✓] Marked '#{post_name}' as complete".colorize(:green)
122
259
  end
123
260
  end
124
261
 
125
262
  if options[:in_progress]
126
263
  if post[:in_progress]
127
- puts('[!] Post already marked as in progress')
264
+ puts '[!] Post already marked as in progress'.colorize(:red)
128
265
  else
129
266
  post[:in_progress] = true
130
- puts("[✓] Marked '#{post_name}' as in progress")
267
+ puts "[✓] Marked '#{post_name}' as in progress".colorize(:green)
131
268
  end
132
269
  end
133
270
  post[:tags] = options[:tags] if options[:tags]
@@ -136,24 +273,7 @@ module BlogTools
136
273
  puts "The post content is located at: #{options[:path]}" if options[:path]
137
274
 
138
275
  Storage.write_lists(@lists)
139
- end
140
-
141
- private
142
-
143
- def show_statuses
144
- if options[:status]
145
- status =
146
- if data[:completed]
147
- '[✓]'
148
- elsif data[:in_progress]
149
- '[~]'
150
- else
151
- '[ ]'
152
- end
153
- puts "- #{status} #{item}"
154
- else
155
- puts "- #{item}"
156
- end
276
+ nil
157
277
  end
158
278
  end
159
279
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'commands/config'
4
+ require_relative 'commands/generate'
5
+ require_relative 'commands/lists'
6
+
7
+ module BlogTools
8
+ # The Commands module groups all the CLI subcommands for blog-tools together.
9
+ #
10
+ # Each subcommand implements a feature of the CLI, such as generating posts,
11
+ # managing lists of future posts, and editing configurations for the tool.
12
+ #
13
+ # These subcommands are registered by the main BlogTools:CLI class.
14
+ #
15
+ # @see BlogTools::Commands::Generate
16
+ # @see BlogTools::Commands::Lists
17
+ # @see BlogTools::Commands::Config
18
+ module Commands
19
+ # This intentionally contains no logic. It exists to namespace the CLI commands
20
+ end
21
+ end
@@ -1,17 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'colorize'
3
4
  require 'fileutils'
4
5
  require 'yaml'
5
6
 
6
7
  module BlogTools
7
- # Handles paths and file initialization for blog-tools
8
+ # BlogTools::Storage handles paths and file initialization for blog-tools
8
9
  # configuration and templates.
10
+ #
11
+ # It is the namespace for all of the locations of files and directories the CLI
12
+ # accesses and writes to, as well as setting up the environment upon first run
13
+ # or if the configuration directory was deleted.
14
+ #
15
+ # @see BlogTools::CLI
9
16
  module Storage
17
+ # The location of the configuration directory. You can set your own with the
18
+ # `BLOG_TOOLS_DIR` environment variable, otherwise it will be located at
19
+ # `~/.config/blog-tools/`
10
20
  CONFIG_DIR = ENV['BLOG_TOOLS_DIR'] || File.join(Dir.home, '.config', 'blog-tools')
21
+
22
+ # The location of the file used for storing lists. It is named `lists.yml`
23
+ # and put inside the configuration directory.
11
24
  LISTS_FILE = File.join(CONFIG_DIR, 'lists.yml')
25
+
26
+ # The locaion of the default configurations file. It is inside the
27
+ # configuration directory
12
28
  CONFIG_FILE = File.join(CONFIG_DIR, 'config.yml')
29
+
30
+ # The directory where `blog-tools` looks to find templates for generating
31
+ # posts. It is in the configuration directory.
13
32
  TEMPLATES_DIR = File.join(CONFIG_DIR, 'templates/')
33
+
34
+ # This is the location of the default template file used.
14
35
  DEFAULT_TEMPLATE_FILE = File.join(TEMPLATES_DIR, 'post.md')
36
+
37
+ # This is the markdown for the default configuration file. It is put into
38
+ # the file when `BlogTools::Storage.create_default_template` is run
39
+ # @see BlogTools::Storage.create_default_template
15
40
  DEFAULT_TEMPLATE = <<~'MARKDOWN'
16
41
  ---
17
42
  title: "<%= title %>"
@@ -26,6 +51,12 @@ module BlogTools
26
51
  MARKDOWN
27
52
 
28
53
  # Ensure required directories and files exist.
54
+ #
55
+ # This method is used to completely setup the configuration environment
56
+ # It creates the `~/.config/blog-tools` directory, and the files
57
+ # and templates that are needed for the tool to run.
58
+ #
59
+ # @return [Nil]
29
60
  def self.setup!
30
61
  create_directories
31
62
  create_lists_file
@@ -33,40 +64,61 @@ module BlogTools
33
64
  create_default_template
34
65
  end
35
66
 
36
- # Path to the config file
37
- def self.config_path
38
- CONFIG_FILE
39
- end
40
-
67
+ # This method creates the configuration and templates directories.
68
+ #
69
+ # The directories are located at `~/.config/blog-tools`, and at
70
+ # `~/.config/blog-tools/templates`
71
+ #
72
+ # @return [Array] An array of the directories created
41
73
  def self.create_directories
42
74
  FileUtils.mkdir_p(CONFIG_DIR)
43
75
  FileUtils.mkdir_p(TEMPLATES_DIR)
44
76
  end
45
77
 
78
+ # Creates an empty lists file if it doesn't exist.
79
+ #
80
+ # @return [Array<String>, nil] The path to the file if created, otherwise nil.
46
81
  def self.create_lists_file
47
82
  FileUtils.touch(LISTS_FILE) unless File.exist?(LISTS_FILE)
48
83
  end
49
84
 
85
+ # Writes the given data to the lists file in YAML format.
86
+ #
87
+ # @param data [Hash] The data to write.
88
+ # @return [Integer] The number of bytes written to the file.
50
89
  def self.write_lists(data)
51
90
  File.write(LISTS_FILE, data.to_yaml)
52
91
  end
53
92
 
93
+ # Reads and parses the lists file, returning its contents as a hash.
94
+ #
95
+ # If the file doesn't exist or contains invalid YAML, returns an empty hash.
96
+ #
97
+ # @return [Hash] Parsed YAML data from the lists file.
54
98
  def self.read_lists
55
99
  return {} unless File.exist?(LISTS_FILE)
56
100
 
57
101
  data = YAML.safe_load_file(LISTS_FILE, permitted_classes: [Symbol, Date, Time], aliases: true)
58
102
  data.is_a?(Hash) ? data : {}
59
103
  rescue Psych::SyntaxError => e
60
- warn "[!] Failed to parse lists.yml: #{e.message}"
104
+ warn "[!] Failed to parse lists.yml: #{e.message}".colorize(:red)
61
105
  {}
62
106
  end
63
107
 
108
+ # Creates a default configuration file if one does not already exist.
109
+ #
110
+ # If the config file is missing, this method will:
111
+ # - Print a warning message.
112
+ # - Create the config directory if needed.
113
+ # - Write a default config YAML file.
114
+ #
115
+ # @return [nil] Always returns nil.
64
116
  def self.create_config_file
65
117
  return if File.exist?(CONFIG_FILE)
66
118
 
67
119
  FileUtils.mkdir_p(File.dirname(CONFIG_FILE))
68
120
 
69
- puts '[!] No configuration file found, generating now...'
121
+ puts '[!] No configuration file found, generating now...'.colorize(:red)
70
122
 
71
123
  default_config = {
72
124
  'author' => ENV['USER'] || 'changeme',
@@ -77,6 +129,11 @@ module BlogTools
77
129
  File.write(CONFIG_FILE, default_config.to_yaml)
78
130
  end
79
131
 
132
+ # Creates the default template file if the templates directory is empty.
133
+ #
134
+ # Writes the default post template to `post.md` and prints a success message.
135
+ #
136
+ # @return [nil] Always returns nil.
80
137
  def self.create_default_template
81
138
  return unless Dir.empty?(TEMPLATES_DIR)
82
139
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlogTools
4
- VERSION = '0.2.0'
4
+ # Current tool version
5
+ VERSION = '0.2.1'
5
6
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blog-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slavetomints
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - bin/blog-tools
62
62
  - lib/blog-tools/cli.rb
63
+ - lib/blog-tools/commands.rb
63
64
  - lib/blog-tools/commands/config.rb
64
65
  - lib/blog-tools/commands/generate.rb
65
66
  - lib/blog-tools/commands/lists.rb
metadata.gz.sig CHANGED
Binary file