neruda 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pablo +37 -17
- data/lib/neruda/config/lisp_config.rb +17 -10
- data/lib/neruda/index.rb +6 -1
- data/lib/neruda/org_file.rb +1 -1
- data/lib/neruda/org_file/htmlizer.rb +2 -2
- data/lib/neruda/utils.rb +60 -12
- data/lib/neruda/version.rb +1 -1
- data/lib/tasks/site.rake +15 -23
- data/lib/tasks/tags.rake +23 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 819cab1f549a9991714bac07e34be41187f667b67200996e2ef78a6a8c555ef5
|
4
|
+
data.tar.gz: 4cc683d19f3bfdf060ce56c720251f1db58ac88df3a44c55ada1298155e76f77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d15fb6bcd865e0493b5f08e6209d7ce6a4e1764b88e2eff9cf9d05b20d832f83d1da81e9d7c9d381c4fd128c1f1ff0ff45524ba2e9412c56c3b17247c89a516
|
7
|
+
data.tar.gz: 05e47deafd1cf2366748100699dcbb8677802be4423191d16ed3f352ba52038665c524aafcf5b205cacbda2b8dad582ad13c161ed3110c5503d18a958aaa2b24
|
data/bin/pablo
CHANGED
@@ -35,38 +35,55 @@ module PabloCommands
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def pablo_preview
|
38
|
+
Thread.new do
|
39
|
+
sleep 1
|
40
|
+
port = Neruda::Config.settings['server_port'] || 5000
|
41
|
+
uri = "http://127.0.0.1:#{port}/"
|
42
|
+
current_os = Neruda::Utils.current_os
|
43
|
+
if current_os == 'windows'
|
44
|
+
system 'start', uri
|
45
|
+
elsif current_os == 'apple'
|
46
|
+
system 'open', uri
|
47
|
+
else
|
48
|
+
system 'gio', 'open', uri
|
49
|
+
end
|
50
|
+
end
|
38
51
|
@rake.invoke_task('site:preview')
|
39
52
|
end
|
40
53
|
|
41
54
|
def pablo_open
|
42
|
-
filename = ARGV[0]
|
55
|
+
filename = new_file_name(ARGV[0])
|
43
56
|
FileUtils.mkdir_p File.dirname(filename)
|
44
57
|
o = Neruda::OrgFile.new(filename, @options)
|
45
58
|
o.write unless File.exist? filename
|
46
|
-
|
47
59
|
editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
|
48
60
|
cmd = [editor, filename]
|
49
61
|
cmd.insert(1, '+6') if editor.match?(/^emacs/)
|
50
62
|
system(*cmd)
|
51
63
|
end
|
64
|
+
alias_method :pablo_edit, :pablo_open
|
65
|
+
|
66
|
+
def pablo_publish
|
67
|
+
@rake.invoke_task('sync:push')
|
68
|
+
end
|
52
69
|
|
53
70
|
def pablo_help(command = 'basic', error = false)
|
54
71
|
warn R18n.t.pablo.error.no_command if error
|
55
|
-
|
56
|
-
cmd_opt = Neruda::Utils::PABLO_COMMANDS[
|
72
|
+
cmd = Neruda::Utils.resolve_possible_alias(command)
|
73
|
+
cmd_opt = Neruda::Utils::PABLO_COMMANDS[cmd]
|
57
74
|
label = cmd_opt[:label] || command
|
58
75
|
warn "Usage: pablo #{label} [options]\n\n"
|
59
76
|
warn cmd_opt[:desc] + "\n\n" if cmd_opt.has_key?(:desc)
|
60
|
-
warn "Options\n#{Neruda::Utils.summarize_command(
|
61
|
-
warn "Commands\n#{Neruda::Utils.list_commands}\n" if
|
77
|
+
warn "Options\n#{Neruda::Utils.summarize_command(cmd)}\n"
|
78
|
+
warn "Commands\n#{Neruda::Utils.list_commands}\n" if cmd == 'basic'
|
62
79
|
exit 1 if error
|
63
80
|
exit
|
64
81
|
end
|
65
82
|
|
66
83
|
private
|
67
84
|
|
68
|
-
def new_file_name
|
69
|
-
title
|
85
|
+
def new_file_name(title)
|
86
|
+
title ||= @options[:title]
|
70
87
|
title = 'new' if title.nil? || title == ''
|
71
88
|
filename = Neruda::OrgFile.slug title
|
72
89
|
return "#{filename}.org" unless @options[:directory]
|
@@ -112,14 +129,14 @@ class Pablo
|
|
112
129
|
end
|
113
130
|
end
|
114
131
|
|
115
|
-
|
116
|
-
optparser =
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
opts.send(opt[:meth] || :on, short, long, opt[:desc])
|
121
|
-
end
|
132
|
+
optparser = OptionParser.new
|
133
|
+
optparser.version = Neruda::VERSION
|
134
|
+
|
135
|
+
Neruda::Utils::PABLO_OPTIONS.each do |k, opt|
|
136
|
+
optparser.send(opt[:meth] || :on, *Neruda::Utils.decorate_option(k))
|
122
137
|
end
|
138
|
+
|
139
|
+
params = {}
|
123
140
|
optparser.parse!(into: params)
|
124
141
|
|
125
142
|
if params[:version]
|
@@ -133,8 +150,11 @@ if ARGV[0] == 'help'
|
|
133
150
|
end
|
134
151
|
pablo = Pablo.new(params)
|
135
152
|
command = "pablo_#{ARGV[0]}".to_sym
|
136
|
-
|
137
|
-
|
153
|
+
cmd_err = !pablo.respond_to?(command)
|
154
|
+
if params[:help] || cmd_err
|
155
|
+
cmd_err = false if params[:help] && !ARGV[0]
|
156
|
+
pablo.pablo_help(ARGV[0], cmd_err)
|
157
|
+
end
|
138
158
|
ARGV.shift
|
139
159
|
|
140
160
|
init_cmds = ['pablo_init', 'pablo_config']
|
@@ -91,13 +91,13 @@ module Neruda
|
|
91
91
|
orgtpl = opts['org_headers']
|
92
92
|
base_directory = File.expand_path(opts['path'])
|
93
93
|
publish_in = [Dir.pwd, settings['public_folder']]
|
94
|
-
publish_in << project_name unless project_name == '
|
94
|
+
publish_in << project_name unless project_name == 'neruda'
|
95
95
|
publish_in = publish_in.join('/')
|
96
96
|
recline = [opts['recursive'] || 't']
|
97
97
|
default_ex_ptrn = settings['exclude_pattern']
|
98
98
|
if opts['exclude']
|
99
99
|
recline << ":exclude \"#{opts['exclude']}\""
|
100
|
-
elsif project_name == '
|
100
|
+
elsif project_name == 'neruda' && default_ex_ptrn
|
101
101
|
recline << ":exclude \"#{default_ex_ptrn}\""
|
102
102
|
end
|
103
103
|
<<~ORGPROJECT
|
@@ -147,17 +147,24 @@ module Neruda
|
|
147
147
|
orgtpl.join("\n ")
|
148
148
|
end
|
149
149
|
|
150
|
+
def org_external_projects_opts(seed, orgtpl)
|
151
|
+
opts = { 'org_headers' => orgtpl }
|
152
|
+
if seed.is_a? String
|
153
|
+
opts['path'] = seed
|
154
|
+
elsif seed.is_a? Hash
|
155
|
+
opts.merge! seed
|
156
|
+
end
|
157
|
+
opts
|
158
|
+
end
|
159
|
+
|
150
160
|
def org_generate_projects
|
151
161
|
orgtpl = org_templates
|
152
|
-
|
153
|
-
|
162
|
+
default_project = org_project(
|
163
|
+
'neruda', 'org_headers' => orgtpl, 'path' => './src'
|
164
|
+
)
|
165
|
+
projects = { 'neruda' => default_project }
|
154
166
|
settings['external_sources']&.each do |s|
|
155
|
-
opts =
|
156
|
-
if s.is_a? String
|
157
|
-
opts['path'] = s
|
158
|
-
elsif s.is_a? Hash
|
159
|
-
opts.merge! s
|
160
|
-
end
|
167
|
+
opts = org_external_projects_opts(s, orgtpl)
|
161
168
|
next unless opts.has_key?('path')
|
162
169
|
pname = File.basename(opts['path']).sub(/^\./, '')
|
163
170
|
projects[pname] = org_project(pname, opts)
|
data/lib/neruda/index.rb
CHANGED
@@ -49,7 +49,12 @@ module Neruda
|
|
49
49
|
|
50
50
|
def sort_by(kind)
|
51
51
|
if [:name, :weight].include?(kind)
|
52
|
-
|
52
|
+
tags_sorted = sort_tags_by_name_and_weight["by_#{kind}".to_sym]
|
53
|
+
# Reverse in order to have most important or A near next prompt
|
54
|
+
# and avoid to scroll to find the beginning of the list.
|
55
|
+
return tags_sorted.map do |k|
|
56
|
+
@tags_names[k] + " (#{@index[k].length})"
|
57
|
+
end.reverse
|
53
58
|
end
|
54
59
|
raise ArgumentError, "#{kind} not in [:name, :weight]"
|
55
60
|
end
|
data/lib/neruda/org_file.rb
CHANGED
@@ -252,7 +252,7 @@ module Neruda
|
|
252
252
|
@notime = false
|
253
253
|
@author = @options[:author] || Neruda::Config.settings['author']
|
254
254
|
@keywords = []
|
255
|
-
@lang = Neruda::Config.settings['lang']
|
255
|
+
@lang = @options[:lang] || Neruda::Config.settings['lang']
|
256
256
|
@excerpt = ''
|
257
257
|
@content = @options[:content] || <<~ORG
|
258
258
|
#+title: #{@title}
|
@@ -70,9 +70,9 @@ module Neruda
|
|
70
70
|
command = emacs_command arguments
|
71
71
|
if @options[:verbose]
|
72
72
|
warn command
|
73
|
-
return system(command)
|
73
|
+
return system(command, exception: true)
|
74
74
|
end
|
75
|
-
system command, out: '/dev/null', err: '/dev/null'
|
75
|
+
system command, out: '/dev/null', err: '/dev/null', exception: true
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
data/lib/neruda/utils.rb
CHANGED
@@ -41,11 +41,16 @@ module Neruda
|
|
41
41
|
'init' => { opts: ['-a', '-l', '-t', '-v', '-h'],
|
42
42
|
desc: 'Initialize your Neruda instance ' \
|
43
43
|
'(you just need to do it once).' },
|
44
|
+
'config' => { alias: 'init' },
|
44
45
|
'preview' => { opts: ['-h'],
|
45
46
|
desc: 'Start a test webserver to preview ' \
|
46
47
|
'your website on http://127.0.0.1:5000' },
|
47
48
|
'open' => { opts: ['-a', '-l', '-t', '-d', '-p', '-v', '-h'],
|
48
49
|
desc: 'Open or create an org file for edition.' },
|
50
|
+
'edit' => { alias: 'open' },
|
51
|
+
'publish' => { opts: ['-h'],
|
52
|
+
desc: 'Push local changes to your public ' \
|
53
|
+
'server online.' },
|
49
54
|
'help' => { opts: ['-h'], desc: 'Alias for the -h switch.' },
|
50
55
|
'basic' => { opts: ['-h', '-V'], label: '<command>' }
|
51
56
|
}.freeze
|
@@ -66,17 +71,19 @@ module Neruda
|
|
66
71
|
# @param message [String] the message to display before the throbber
|
67
72
|
# @return [void]
|
68
73
|
def throbber(thread, message)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
frames = select_throbber_frames
|
75
|
+
begin
|
76
|
+
run_and_decorate_thread thread, message, frames
|
77
|
+
rescue RuntimeError => e
|
78
|
+
done = Rainbow('An error occured.').bold.red + "\n"
|
79
|
+
done += Rainbow('To see it, run again your command with more ' \
|
80
|
+
'verbosity, i.e. pablo build -v').bold
|
81
|
+
warn "#{message} #{done}"
|
82
|
+
raise e
|
83
|
+
else
|
84
|
+
done = Rainbow('done'.ljust(frames[0].length)).green
|
85
|
+
puts "#{message} #{done}"
|
77
86
|
end
|
78
|
-
done = Rainbow('done'.ljust(frames[0].length)).green
|
79
|
-
puts "#{message} #{done}"
|
80
87
|
end
|
81
88
|
|
82
89
|
# Returns the short and long options specification for a given
|
@@ -95,8 +102,8 @@ module Neruda
|
|
95
102
|
opt = Neruda::Utils::PABLO_OPTIONS[short]
|
96
103
|
long = "--#{opt[:long]}"
|
97
104
|
return [short, long] if opt[:boolean]
|
98
|
-
key =
|
99
|
-
[short + key, long + key]
|
105
|
+
key = opt[:keyword] || opt[:long].upcase
|
106
|
+
[short + key, long + ' ' + key]
|
100
107
|
end
|
101
108
|
|
102
109
|
# Returns the ~pablo~ help summary for a given command.
|
@@ -125,6 +132,47 @@ module Neruda
|
|
125
132
|
end
|
126
133
|
lines
|
127
134
|
end
|
135
|
+
|
136
|
+
# Returns the real command name for a given command, which may be
|
137
|
+
# an alias.
|
138
|
+
#
|
139
|
+
# @param command [String] the command to resolve
|
140
|
+
# @return [String]
|
141
|
+
def resolve_possible_alias(command)
|
142
|
+
return 'basic' unless Neruda::Utils::PABLO_COMMANDS.include?(command)
|
143
|
+
cmd_opt = Neruda::Utils::PABLO_COMMANDS[command]
|
144
|
+
return cmd_opt[:alias] if cmd_opt.has_key?(:alias)
|
145
|
+
command
|
146
|
+
end
|
147
|
+
|
148
|
+
# Try to discover the current host operating system.
|
149
|
+
#
|
150
|
+
# @return [String] either apple, windows or linux (default)
|
151
|
+
def current_os
|
152
|
+
if ENV['OS'] == 'Windows_NT' || RUBY_PLATFORM =~ /cygwin/
|
153
|
+
return 'windows'
|
154
|
+
end
|
155
|
+
return 'apple' if RUBY_PLATFORM =~ /darwin/
|
156
|
+
'linux'
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def select_throbber_frames
|
162
|
+
model = Neruda::Config.settings['throbber'] || 'default'
|
163
|
+
model = 'default' unless Neruda::Utils::THROBBER_FRAMES.has_key?(model)
|
164
|
+
Neruda::Utils::THROBBER_FRAMES[model]
|
165
|
+
end
|
166
|
+
|
167
|
+
def run_and_decorate_thread(thread, message, frames)
|
168
|
+
thread.abort_on_exception = true
|
169
|
+
current = 0
|
170
|
+
while thread.alive?
|
171
|
+
sleep 0.1
|
172
|
+
print "#{message} #{frames[current % frames.length]}\r"
|
173
|
+
current += 1
|
174
|
+
end
|
175
|
+
end
|
128
176
|
end
|
129
177
|
end
|
130
178
|
end
|
data/lib/neruda/version.rb
CHANGED
data/lib/tasks/site.rake
CHANGED
@@ -28,7 +28,12 @@ namespace :site do
|
|
28
28
|
build_html = Thread.new do
|
29
29
|
Neruda::OrgFile.new(nil, verbose: Rake::FileUtilsExt.verbose_flag).publish
|
30
30
|
end
|
31
|
-
|
31
|
+
begin
|
32
|
+
Neruda::Utils.throbber(build_html, 'Publishing:')
|
33
|
+
rescue RuntimeError
|
34
|
+
warn 'Aborting'
|
35
|
+
next
|
36
|
+
end
|
32
37
|
customize_html = Thread.new do
|
33
38
|
pubfolder = Neruda::Config.settings['public_folder']
|
34
39
|
Dir["#{pubfolder}/**/*.html"].each do |f|
|
@@ -46,8 +51,15 @@ namespace :site do
|
|
46
51
|
next
|
47
52
|
end
|
48
53
|
verbose = Rake::FileUtilsExt.verbose_flag
|
49
|
-
o =
|
50
|
-
|
54
|
+
o = Thread.new do
|
55
|
+
Neruda::OrgFile.new(args[:source], verbose: verbose).publish
|
56
|
+
end
|
57
|
+
begin
|
58
|
+
Neruda::Utils.throbber(o, 'Publishing:')
|
59
|
+
rescue RuntimeError
|
60
|
+
warn 'Aborting'
|
61
|
+
next
|
62
|
+
end
|
51
63
|
target = Neruda::OrgFile.target_for_source(args[:source])
|
52
64
|
warn "Customizing file #{target}" if verbose
|
53
65
|
Neruda::Templater.customize_output(target, o)
|
@@ -62,23 +74,3 @@ namespace :site do
|
|
62
74
|
end
|
63
75
|
# :nocov:
|
64
76
|
end
|
65
|
-
|
66
|
-
namespace :tags do
|
67
|
-
desc 'List all tags by name'
|
68
|
-
task :name do
|
69
|
-
blog_path = Neruda::Config.settings['blog_path']
|
70
|
-
next if blog_path.nil?
|
71
|
-
next unless Dir.exist?("src/#{blog_path}")
|
72
|
-
index = Neruda::Index.new
|
73
|
-
puts index.sort_by(:name).join("\n")
|
74
|
-
end
|
75
|
-
|
76
|
-
desc 'List all tags by weight'
|
77
|
-
task :weight do
|
78
|
-
blog_path = Neruda::Config.settings['blog_path']
|
79
|
-
next if blog_path.nil?
|
80
|
-
next unless Dir.exist?("src/#{blog_path}")
|
81
|
-
index = Neruda::Index.new
|
82
|
-
puts index.sort_by(:weight).join("\n")
|
83
|
-
end
|
84
|
-
end
|
data/lib/tasks/tags.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'neruda/index'
|
4
|
+
|
5
|
+
namespace :tags do
|
6
|
+
desc 'List all tags by name'
|
7
|
+
task :name do
|
8
|
+
blog_path = Neruda::Config.settings['blog_path']
|
9
|
+
next if blog_path.nil?
|
10
|
+
next unless Dir.exist?("src/#{blog_path}")
|
11
|
+
index = Neruda::Index.new
|
12
|
+
puts index.sort_by(:name).join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'List all tags by weight'
|
16
|
+
task :weight do
|
17
|
+
blog_path = Neruda::Config.settings['blog_path']
|
18
|
+
next if blog_path.nil?
|
19
|
+
next unless Dir.exist?("src/#{blog_path}")
|
20
|
+
index = Neruda::Index.new
|
21
|
+
puts index.sort_by(:weight).join("\n")
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neruda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Étienne Deparis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -208,12 +208,13 @@ files:
|
|
208
208
|
- lib/tasks/org.rake
|
209
209
|
- lib/tasks/site.rake
|
210
210
|
- lib/tasks/sync.rake
|
211
|
+
- lib/tasks/tags.rake
|
211
212
|
- locales/en.yml
|
212
213
|
- locales/fr.yml
|
213
214
|
- themes/default/css/style.css
|
214
215
|
- themes/default/fonts/Yanone_Kaffeesatz_400.woff
|
215
216
|
- themes/default/fonts/Yanone_Kaffeesatz_400.woff2
|
216
|
-
homepage: https://
|
217
|
+
homepage: https://git.deparis.io/neruda/
|
217
218
|
licenses:
|
218
219
|
- WTFPL
|
219
220
|
metadata: {}
|
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
235
|
- !ruby/object:Gem::Version
|
235
236
|
version: '0'
|
236
237
|
requirements: []
|
237
|
-
rubygems_version: 3.
|
238
|
+
rubygems_version: 3.1.2
|
238
239
|
signing_key:
|
239
240
|
specification_version: 4
|
240
241
|
summary: A simplistic way to create an org-mode static website.
|