fronde 0.3.3 → 0.4.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 +4 -4
- data/bin/fronde +15 -30
- data/lib/ext/nil_time.rb +25 -0
- data/lib/ext/r18n.rb +17 -0
- data/lib/ext/time.rb +49 -0
- data/lib/fronde/cli/commands.rb +92 -103
- data/lib/fronde/cli/data/Rakefile +8 -0
- data/lib/fronde/cli/data/config.yml +13 -0
- data/lib/fronde/cli/data/gitignore +7 -0
- data/lib/fronde/cli/data/zsh_completion +37 -0
- data/lib/fronde/cli/helpers.rb +55 -0
- data/lib/fronde/cli/opt_parse.rb +143 -0
- data/lib/fronde/cli/throbber.rb +99 -0
- data/lib/fronde/cli.rb +41 -42
- data/lib/fronde/config/data/org-config.el +24 -0
- data/lib/fronde/config/{ox-fronde.el → data/ox-fronde.el} +1 -1
- data/lib/fronde/config/helpers.rb +80 -0
- data/lib/fronde/config/lisp.rb +70 -0
- data/lib/fronde/config.rb +135 -99
- data/lib/fronde/emacs.rb +23 -20
- data/lib/fronde/index/atom_generator.rb +55 -66
- data/lib/fronde/index/data/all_tags.org +14 -0
- data/lib/fronde/index/data/template.org +22 -0
- data/lib/fronde/index/data/template.xml +37 -0
- data/lib/fronde/index/org_generator.rb +70 -88
- data/lib/fronde/index.rb +56 -82
- data/lib/fronde/org/file.rb +287 -0
- data/lib/fronde/org/file_extracter.rb +98 -0
- data/lib/fronde/org.rb +103 -0
- data/lib/fronde/preview.rb +43 -39
- data/lib/fronde/slug.rb +27 -0
- data/lib/fronde/source/gemini.rb +39 -0
- data/lib/fronde/source/html.rb +67 -0
- data/lib/fronde/source.rb +204 -0
- data/lib/fronde/templater.rb +94 -71
- data/lib/fronde/version.rb +1 -1
- data/lib/tasks/cli.rake +33 -0
- data/lib/tasks/org.rake +63 -43
- data/lib/tasks/site.rake +68 -30
- data/lib/tasks/sync.rake +41 -21
- data/lib/tasks/tags.rake +11 -7
- data/locales/en.yml +60 -14
- data/locales/fr.yml +68 -14
- metadata +57 -156
- data/lib/fronde/config/lisp_config.rb +0 -340
- data/lib/fronde/config/org-config.el +0 -19
- data/lib/fronde/org_file/class_methods.rb +0 -72
- data/lib/fronde/org_file/extracter.rb +0 -72
- data/lib/fronde/org_file/htmlizer.rb +0 -43
- data/lib/fronde/org_file.rb +0 -298
- data/lib/fronde/utils.rb +0 -229
data/lib/fronde/utils.rb
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
require 'rainbow'
|
5
|
-
require 'net/http'
|
6
|
-
require 'r18n-core'
|
7
|
-
require 'fronde/config'
|
8
|
-
|
9
|
-
module Fronde
|
10
|
-
# Default Error, which may be raised by fronde code
|
11
|
-
class Error < ::StandardError; end
|
12
|
-
|
13
|
-
# Embeds usefull methods, mainly used in rake tasks.
|
14
|
-
module Utils
|
15
|
-
# @return [Hash] the possible throbber themes
|
16
|
-
THROBBER_FRAMES = {
|
17
|
-
'basic' => '-\|/',
|
18
|
-
'basicdots' => '⋯⋱⋮⋰',
|
19
|
-
'moon' => '🌑🌒🌓🌔🌕🌖🌗🌘',
|
20
|
-
'clock' => '🕛🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚',
|
21
|
-
'bricks' => '⣷⣯⣟⡿⢿⣻⣽⣾',
|
22
|
-
'points' => '·⁘∷⁛∷⁘',
|
23
|
-
'quadrant2' => '▙▛▜▟',
|
24
|
-
'default' => ['⠁ ⠂ ⠄ ⡀ ⠄ ⠂ ⠁', '⠂ ⠁ ⠂ ⠄ ⡀ ⠄ ⠂', '⠄ ⠂ ⠁ ⠂ ⠄ ⡀ ⠄',
|
25
|
-
'⡀ ⠄ ⠂ ⠁ ⠂ ⠄ ⡀', '⠄ ⡀ ⠄ ⠂ ⠁ ⠂ ⠄', '⠂ ⠄ ⡀ ⠄ ⠂ ⠁ ⠂']
|
26
|
-
}.freeze
|
27
|
-
|
28
|
-
# @return [Hash] the possible ~fronde~ options and their
|
29
|
-
# configuration
|
30
|
-
FRONDE_OPTIONS = {
|
31
|
-
'-a' => { long: 'author' },
|
32
|
-
'-f' => { long: 'force', boolean: true },
|
33
|
-
'-h' => { long: 'help', boolean: true, meth: :on_tail },
|
34
|
-
'-l' => { long: 'lang', keyword: 'LOCALE' },
|
35
|
-
'-t' => { long: 'title' },
|
36
|
-
'-v' => { long: 'verbose', boolean: true, meth: :on_tail },
|
37
|
-
'-V' => { long: 'version', boolean: true, meth: :on_tail }
|
38
|
-
}.freeze
|
39
|
-
|
40
|
-
# @return [Hash] the possible ~fronde~ subcommands and their
|
41
|
-
# configuration
|
42
|
-
FRONDE_COMMANDS = {
|
43
|
-
'init' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
|
44
|
-
'update' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
|
45
|
-
'config' => { alias: 'update' },
|
46
|
-
'preview' => { opts: ['-h'] },
|
47
|
-
'open' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
|
48
|
-
'edit' => { alias: 'open' },
|
49
|
-
'build' => { opts: ['-f', '-h'] },
|
50
|
-
'publish' => { opts: ['-h'] },
|
51
|
-
'help' => { opts: ['-h'] },
|
52
|
-
'basic' => { opts: ['-h', '-V'], label: '<command>' }
|
53
|
-
}.freeze
|
54
|
-
|
55
|
-
class << self
|
56
|
-
# Animates strings in the user console to alert him that something
|
57
|
-
# is running in the background.
|
58
|
-
#
|
59
|
-
# The animation is chosen among a bunch of themes, with the
|
60
|
-
# configuration option ~throbber~ (retrieved via
|
61
|
-
# {Fronde::Config#settings}).
|
62
|
-
#
|
63
|
-
# @example
|
64
|
-
# long_stuff = Thread.new { very_long_operation }
|
65
|
-
# Fronde::Utils.throbber(long_stuff, 'Computing hard stuff:')
|
66
|
-
#
|
67
|
-
# @param thread [Thread] the long-running operation to decorate
|
68
|
-
# @param message [String] the message to display before the throbber
|
69
|
-
# @return [void]
|
70
|
-
def throbber(thread, message)
|
71
|
-
frames = select_throbber_frames
|
72
|
-
begin
|
73
|
-
run_and_decorate_thread thread, message, frames
|
74
|
-
rescue RuntimeError => e
|
75
|
-
throbber_error message
|
76
|
-
raise e
|
77
|
-
else
|
78
|
-
done = Rainbow('done'.ljust(frames[0].length)).green
|
79
|
-
puts "#{message} #{done}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Returns the short and long options specification for a given
|
84
|
-
# short option.
|
85
|
-
#
|
86
|
-
# This method use the {Fronde::Utils::FRONDE_OPTIONS} Hash to
|
87
|
-
# retrieve corresponding values.
|
88
|
-
#
|
89
|
-
# @example
|
90
|
-
# spec = Fronde::Utils.decorate_option('-a')
|
91
|
-
# => ['-a AUTHOR', '--author AUTHOR']
|
92
|
-
#
|
93
|
-
# @param short [String] the short option to decorate
|
94
|
-
# @return [Array] the short and long specification for an option
|
95
|
-
def decorate_option(short)
|
96
|
-
opt = Fronde::Utils::FRONDE_OPTIONS[short]
|
97
|
-
long = "--#{opt[:long]}"
|
98
|
-
return [short, long] if opt[:boolean]
|
99
|
-
key = opt[:keyword] || opt[:long].upcase
|
100
|
-
[short + key, format('%<long>s %<key>s', long: long, key: key)]
|
101
|
-
end
|
102
|
-
|
103
|
-
# Returns the ~fronde~ help summary for a given command.
|
104
|
-
#
|
105
|
-
# @param command [String] the command for which a summary
|
106
|
-
# should be given
|
107
|
-
# @return [String]
|
108
|
-
def summarize_command(command)
|
109
|
-
Fronde::Utils::FRONDE_COMMANDS[command][:opts].map do |k|
|
110
|
-
short, long = Fronde::Utils.decorate_option(k)
|
111
|
-
opt = Fronde::Utils::FRONDE_OPTIONS[k]
|
112
|
-
label = [short, long].join(', ')
|
113
|
-
line = [format(' %<opt>s', opt: label).ljust(30)]
|
114
|
-
if R18n.t.fronde.bin.options[opt[:long]].translated?
|
115
|
-
line << R18n.t.fronde.bin.options[opt[:long]]
|
116
|
-
end
|
117
|
-
line.join(' ')
|
118
|
-
end.join("\n")
|
119
|
-
end
|
120
|
-
|
121
|
-
# Returns a formatted list of available commands for ~fronde~.
|
122
|
-
#
|
123
|
-
# @return [String]
|
124
|
-
def list_commands
|
125
|
-
lines = []
|
126
|
-
Fronde::Utils::FRONDE_COMMANDS.each do |cmd, opt|
|
127
|
-
next if cmd == 'basic'
|
128
|
-
line = [' ', cmd.ljust(10)]
|
129
|
-
if opt.has_key? :alias
|
130
|
-
line << R18n.t.fronde.bin.commands.alias(opt[:alias])
|
131
|
-
else
|
132
|
-
line << R18n.t.fronde.bin.commands[cmd]
|
133
|
-
end
|
134
|
-
lines << line.join(' ')
|
135
|
-
end
|
136
|
-
lines.join("\n")
|
137
|
-
end
|
138
|
-
|
139
|
-
# Returns the real command name for a given command, which may be
|
140
|
-
# an alias.
|
141
|
-
#
|
142
|
-
# @param command [String] the command to resolve
|
143
|
-
# @return [String]
|
144
|
-
def resolve_possible_alias(command)
|
145
|
-
return 'basic' unless Fronde::Utils::FRONDE_COMMANDS.include?(command)
|
146
|
-
cmd_opt = Fronde::Utils::FRONDE_COMMANDS[command]
|
147
|
-
return cmd_opt[:alias] if cmd_opt.has_key?(:alias)
|
148
|
-
command
|
149
|
-
end
|
150
|
-
|
151
|
-
# Returns the given command options.
|
152
|
-
#
|
153
|
-
# This method will first try to resolve command alias, if any.
|
154
|
-
#
|
155
|
-
# @param command [String] the command, which options should be returned
|
156
|
-
# @return [Hash] the command options
|
157
|
-
def command_options(command)
|
158
|
-
cmd = resolve_possible_alias command
|
159
|
-
FRONDE_COMMANDS[cmd].merge(name: cmd)
|
160
|
-
end
|
161
|
-
|
162
|
-
# Try to discover the current host operating system.
|
163
|
-
#
|
164
|
-
# @return [String] either apple, windows or linux (default)
|
165
|
-
# :nocov:
|
166
|
-
def current_os
|
167
|
-
if ENV['OS'] == 'Windows_NT' || RUBY_PLATFORM.include?('cygwin')
|
168
|
-
return 'windows'
|
169
|
-
end
|
170
|
-
return 'apple' if RUBY_PLATFORM.include?('darwin')
|
171
|
-
'linux'
|
172
|
-
end
|
173
|
-
# :nocov:
|
174
|
-
|
175
|
-
# Download latest org-mode tarball.
|
176
|
-
#
|
177
|
-
# @param destination [String] where to save the org-mode tarball
|
178
|
-
# @return [String] the downloaded org-mode version
|
179
|
-
def download_org(destination = 'var/tmp')
|
180
|
-
# :nocov:
|
181
|
-
return if Fronde::Config.org_last_version.nil?
|
182
|
-
# :nocov:
|
183
|
-
# Remove version number in dest file to allow easy rake file
|
184
|
-
# task naming
|
185
|
-
dest_file = File.expand_path('org.tar.gz', destination)
|
186
|
-
return if File.exist?(dest_file)
|
187
|
-
tarball = "org-mode-release_#{Fronde::Config.org_last_version}.tar.gz"
|
188
|
-
uri = URI("https://git.savannah.gnu.org/cgit/emacs/org-mode.git/snapshot/#{tarball}")
|
189
|
-
# Will crash on purpose if anything goes wrong
|
190
|
-
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
191
|
-
http.request(Net::HTTP::Get.new(uri)) do |response|
|
192
|
-
File.open(dest_file, 'w') do |io|
|
193
|
-
response.read_body { |chunk| io.write chunk }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
def throbber_error(message)
|
202
|
-
warn(
|
203
|
-
format(
|
204
|
-
"%<message>s %<label>s\n%<explanation>s",
|
205
|
-
message: message,
|
206
|
-
label: Rainbow(R18n.t.fronde.error.label).bold.red,
|
207
|
-
explanation: Rainbow(R18n.t.fronde.error.explanation).bold
|
208
|
-
)
|
209
|
-
)
|
210
|
-
end
|
211
|
-
|
212
|
-
def select_throbber_frames
|
213
|
-
model = Fronde::Config.settings['throbber'] || 'default'
|
214
|
-
model = 'default' unless Fronde::Utils::THROBBER_FRAMES.has_key?(model)
|
215
|
-
Fronde::Utils::THROBBER_FRAMES[model]
|
216
|
-
end
|
217
|
-
|
218
|
-
def run_and_decorate_thread(thread, message, frames)
|
219
|
-
thread.abort_on_exception = true
|
220
|
-
current = 0
|
221
|
-
while thread.alive?
|
222
|
-
sleep 0.1
|
223
|
-
print "#{message} #{frames[current % frames.length]}\r"
|
224
|
-
current += 1
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|