neruda 0.2.3 → 0.2.4

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: 439ad28e63d071bfd98bd52e99c39ff1bfbfcde9f0e6c4e48bd501143b3a62f1
4
- data.tar.gz: ac080451123c740352e8a6c0259d294ab03a40f375981cb05e68ece0c6c6243a
3
+ metadata.gz: f704b888004971a0ee3c321f41874132283f7f42a3c6b57f267356b7723b2260
4
+ data.tar.gz: 54c3738824f1b80b46b00654aedd805ef0a999a096f1ff320c42001027419147
5
5
  SHA512:
6
- metadata.gz: bb9e592d2a1b61f5b0682023157f8a5b429fd21feb494e328fe0185ddbd27ba182ca5cfd77d82d63c66db208d4713478cec20c5f1d6c9a1bbe7de0e867f8973e
7
- data.tar.gz: 827b583c447d97c43bfb8667b75c9e80b82903b1ce9ecb316e6c95c2dc407e7b601f2f2f3dc02969ca0eeaf487e022765cac070af8d68734462bf09c48b65995
6
+ metadata.gz: ba08196581125aa378a938cb34413d856d7126800cbe692b9237f6e3ffb7bf45743d7dd6fa0ab77c9adb13000dd266085a7ebb4fe556b3d223f620596b237074
7
+ data.tar.gz: efc4308eb4c1d43091f6134fbdee4054feb80535e01fa1cff7f79656f22540bd55011c66c6ac7ca33fb01c0b6c4dbcab6012db44f1726285dc6be85fb8236953
data/bin/pablo CHANGED
@@ -15,26 +15,21 @@ module PabloCommands
15
15
  def pablo_init
16
16
  cnf = @options.merge
17
17
  cnf.delete(:verbose)
18
- cnf.delete(:directory)
19
18
  cnf.transform_keys!(&:to_s)
20
19
  Neruda::Config.save(Neruda::Config.settings.merge(cnf))
21
20
  @rake.options.build_all = true
22
21
  @rake.invoke_task('org:install')
23
22
  return if File.exist? 'src/index.org'
24
23
  Neruda::OrgFile.new('src/index.org', @options).write
24
+ pablo_open 'src/index.org'
25
25
  end
26
26
  alias_method :pablo_config, :pablo_init
27
27
 
28
- def pablo_build(file = ARGV[0])
28
+ def pablo_build
29
29
  @rake.options.build_all = true
30
- # Update org-config.el, if necessary
31
- suffix = ''
32
- if !file.nil?
33
- suffix = ":one[#{file}]"
34
- elsif @options[:force]
35
- suffix = '[true]'
36
- end
37
- @rake.invoke_task("site:build#{suffix}")
30
+ task = 'site:build'
31
+ task = "#{task}[true]" if @options[:force]
32
+ @rake.invoke_task task
38
33
  end
39
34
 
40
35
  def pablo_preview
@@ -55,13 +50,17 @@ module PabloCommands
55
50
  @rake.invoke_task('site:preview')
56
51
  end
57
52
 
58
- def pablo_open
59
- filename = new_file_name(ARGV[0])
60
- FileUtils.mkdir_p File.dirname(filename)
61
- o = Neruda::OrgFile.new(filename, @options)
62
- o.write unless File.exist? filename
53
+ def pablo_open(file_path = ARGV[0])
63
54
  editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
64
- cmd = [editor, '+6', filename]
55
+ cmd = [editor]
56
+ if file_path.nil? || !File.file?(file_path)
57
+ # file_path may be updated with title given in options
58
+ file_path = create_new_file(file_path)
59
+ # Only move to the end of file for new file. Let the editor handle
60
+ # the best position for already existing files
61
+ cmd << '+6'
62
+ end
63
+ cmd << file_path
65
64
  system(*cmd)
66
65
  end
67
66
  alias_method :pablo_edit, :pablo_open
@@ -86,12 +85,27 @@ module PabloCommands
86
85
 
87
86
  private
88
87
 
89
- def new_file_name(title)
90
- title ||= @options[:title]
91
- title = 'new' if title.nil? || title == ''
92
- filename = Neruda::OrgFile.slug title
93
- return "#{filename}.org" unless @options[:directory]
94
- "#{filename}/index.org"
88
+ def new_file_name(file_path)
89
+ file_path = File.expand_path(file_path || '')
90
+ return file_path if file_path[-4..] == '.org'
91
+ # file_path seems to be a dir path. Thus we have to create the new
92
+ # filename from its title
93
+ title = @options[:title]
94
+ # No title, nor a reliable file_path? Better abort
95
+ return nil if title.nil? || title == ''
96
+ filename = "#{Neruda::OrgFile.slug(title)}.org"
97
+ File.join file_path, filename
98
+ end
99
+
100
+ def create_new_file(file_path)
101
+ filename = new_file_name(file_path)
102
+ if filename.nil?
103
+ warn R18n.t.pablo.error.no_file
104
+ exit 1
105
+ end
106
+ FileUtils.mkdir_p File.dirname(filename)
107
+ Neruda::OrgFile.new(filename, @options).write
108
+ filename
95
109
  end
96
110
 
97
111
  def help_command_body(command)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'open-uri'
4
5
  require 'neruda/version'
5
6
 
@@ -16,17 +17,13 @@ module Neruda
16
17
  @org_version = IO.read('tmp/__last_org_version__')
17
18
  return @org_version
18
19
  end
19
- index = URI('https://orgmode.org/index.html').open.read
20
- last_ver = index.match(/https:\/\/orgmode\.org\/org-([0-9.]+)\.tar\.gz/)
21
- # :nocov:
22
- if last_ver.nil?
23
- warn 'Org last version not found'
24
- return nil
25
- end
20
+ versions = JSON.parse(
21
+ URI('https://updates.orgmode.org/data/releases').open.read
22
+ ).sort { |a, b| b['date'] <=> a['date'] }
23
+ @org_version = versions.first['version']
26
24
  FileUtils.mkdir_p 'tmp'
27
- IO.write('tmp/__last_org_version__', last_ver[1])
28
- # :nocov:
29
- @org_version = last_ver[1]
25
+ IO.write('tmp/__last_org_version__', @org_version)
26
+ @org_version
30
27
  end
31
28
 
32
29
  # Generate emacs lisp configuration file for Org and write it.
@@ -145,8 +142,6 @@ module Neruda
145
142
  #{other_lines.join("\n ")}
146
143
  :publishing-directory "#{publish_in}"
147
144
  :publishing-function org-html-publish-to-html
148
- :section-numbers nil
149
- :with-toc nil
150
145
  #{opts['org_headers']})
151
146
  ("#{project_name}-assets"
152
147
  :base-directory "#{opts['path']}"
@@ -178,17 +173,20 @@ module Neruda
178
173
  end
179
174
 
180
175
  def org_default_html_options(project)
181
- curtheme = project['theme'] || settings['theme']
182
- if curtheme.nil? || curtheme == 'default'
183
- return { 'html-head' => '__ATOM_FEED__',
184
- 'html-postamble' => org_default_postamble,
185
- 'html-head-include-default-style' => 't',
186
- 'html-head-include-scripts' => 't' }
187
- end
188
- { 'html-head' => org_default_html_head,
176
+ defaults = {
177
+ 'section-numbers' => 'nil',
178
+ 'with-toc' => 'nil',
189
179
  'html-postamble' => org_default_postamble,
190
- 'html-head-include-default-style' => 'nil',
191
- 'html-head-include-scripts' => 'nil' }
180
+ 'html-head' => '__ATOM_FEED__',
181
+ 'html-head-include-default-style' => 't',
182
+ 'html-head-include-scripts' => 't'
183
+ }
184
+ curtheme = project['theme'] || settings['theme']
185
+ return defaults if curtheme.nil? || curtheme == 'default'
186
+ defaults['html-head'] = org_default_html_head
187
+ defaults['html-head-include-default-style'] = 'nil'
188
+ defaults['html-head-include-scripts'] = 'nil'
189
+ defaults
192
190
  end
193
191
 
194
192
  def expand_vars_in_html_head(head, project)
@@ -11,34 +11,27 @@ module Neruda
11
11
  end
12
12
 
13
13
  def publish
14
- if @file.nil?
15
- emacs_args = ['--eval \'(org-publish "website")\'']
16
- else
17
- emacs_args = ['-f org-publish-current-file']
14
+ command = emacs_command(
15
+ '-l ./org-config.el', '--eval \'(org-publish "website")\''
16
+ )
17
+ if @verbose
18
+ warn command
19
+ return system(command, exception: true)
18
20
  end
19
- call_emacs emacs_args
21
+ system command, out: '/dev/null', err: '/dev/null', exception: true
20
22
  end
21
23
 
22
24
  private
23
25
 
24
- def emacs_command(arguments = [])
26
+ def emacs_command(*arguments)
25
27
  default_emacs = Neruda::Config.settings['emacs']
26
- emacs_cmd = [default_emacs || 'emacs -Q --batch -nw']
27
- emacs_cmd << '--eval \'(setq enable-dir-local-variables nil)\''
28
+ emacs_cmd = [
29
+ default_emacs || 'emacs -Q --batch -nw',
30
+ '--eval \'(setq enable-dir-local-variables nil)\''
31
+ ]
28
32
  emacs_cmd << '--eval \'(setq inhibit-message t)\'' unless @verbose
29
- emacs_cmd << '-l ./org-config.el'
30
- emacs_cmd << "--eval '(find-file \"#{@file}\")'" unless @file.nil?
31
33
  emacs_cmd.concat(arguments)
32
34
  emacs_cmd.join(' ')
33
35
  end
34
-
35
- def call_emacs(arguments = [])
36
- command = emacs_command arguments
37
- if @verbose
38
- warn command
39
- return system(command, exception: true)
40
- end
41
- system command, out: '/dev/null', err: '/dev/null', exception: true
42
- end
43
36
  end
44
37
  end
@@ -7,15 +7,6 @@ module Neruda
7
7
  # This module holds HTML formatter methods for the {Neruda::OrgFile}
8
8
  # class.
9
9
  module OrgFileHtmlizer
10
- # Publish the current file
11
- #
12
- # @return [Boolean, nil] the underlying ~system~ method return value
13
- def publish
14
- Neruda::Emacs.new(
15
- file_path: @file, verbose: @options[:verbose]
16
- ).publish
17
- end
18
-
19
10
  private
20
11
 
21
12
  # Format {Neruda::OrgFile#keywords} list in an HTML listing.
@@ -11,7 +11,7 @@ module Neruda
11
11
  @dom = dom
12
12
  @org_file = source
13
13
  @position = opts['type'] || 'after'
14
- @content = opts['content']
14
+ @content = extract_content opts
15
15
  @element = @dom.css(opts['selector'])
16
16
  digest = Digest::MD5.hexdigest(@content)
17
17
  @check_line = " Neruda Template: #{digest} "
@@ -54,15 +54,7 @@ module Neruda
54
54
  def filter_templates(file_name)
55
55
  templates = Neruda::Config.settings['templates']
56
56
  return [] if templates.nil? || templates.empty?
57
- templates.filter do |t|
58
- if !t.has_key?('selector') || !t.has_key?('content')
59
- false
60
- elsif t.has_key?('path') && !check_path(file_name, t['path'])
61
- false
62
- else
63
- true
64
- end
65
- end
57
+ templates.filter { |t| check_required_keys(t, file_name) }
66
58
  end
67
59
 
68
60
  def open_dom(file_name)
@@ -90,6 +82,13 @@ module Neruda
90
82
  File.fnmatch?("#{pub_folder}#{pathes}",
91
83
  file_name, File::FNM_DOTMATCH)
92
84
  end
85
+
86
+ def check_required_keys(opts, file_name)
87
+ return false unless opts.has_key?('selector')
88
+ return false unless opts.has_key?('content') || opts.has_key?('source')
89
+ return check_path(file_name, opts['path']) if opts.has_key?('path')
90
+ true
91
+ end
93
92
  end
94
93
 
95
94
  private
@@ -108,5 +107,12 @@ module Neruda
108
107
  elem.add_next_sibling content
109
108
  end
110
109
  end
110
+
111
+ def extract_content(opts)
112
+ return opts['content'] if opts['content']
113
+ # If we don't have a content option, then we must have a source
114
+ # one.
115
+ @dom.css(opts['source']).unlink.to_s
116
+ end
111
117
  end
112
118
  end
@@ -26,7 +26,6 @@ module Neruda
26
26
  # configuration
27
27
  PABLO_OPTIONS = {
28
28
  '-a' => { long: 'author' },
29
- '-d' => { long: 'directory', boolean: true },
30
29
  '-f' => { long: 'force', boolean: true },
31
30
  '-h' => { long: 'help', boolean: true, meth: :on_tail },
32
31
  '-l' => { long: 'lang', keyword: 'LOCALE' },
@@ -42,7 +41,7 @@ module Neruda
42
41
  'init' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
43
42
  'config' => { alias: 'init' },
44
43
  'preview' => { opts: ['-h'] },
45
- 'open' => { opts: ['-a', '-d', '-h', '-l', '-p', '-t', '-v'] },
44
+ 'open' => { opts: ['-a', '-h', '-l', '-p', '-t', '-v'] },
46
45
  'edit' => { alias: 'open' },
47
46
  'build' => { opts: ['-f', '-h'] },
48
47
  'publish' => { opts: ['-h'] },
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Neruda
4
4
  # @return [String] the version number of the current Neruda release.
5
- VERSION = '0.2.3'
5
+ VERSION = '0.2.4'
6
6
  end
@@ -23,7 +23,7 @@ namespace :site do
23
23
  Neruda::Config.write_org_lisp_config(with_tags: true)
24
24
  end
25
25
 
26
- desc 'Convert all org files'
26
+ desc 'Convert and customize all org files'
27
27
  task :build, [:force?] => ['org-config.el', :index] do |_, args|
28
28
  args.with_defaults(:force? => false)
29
29
  build_html = Thread.new do
@@ -47,38 +47,6 @@ namespace :site do
47
47
  Neruda::Utils.throbber(customize_html, 'Customizing:')
48
48
  end
49
49
 
50
- namespace :build do
51
- desc 'Convert one org file'
52
- task :one, [:source] => ['org-config.el'] do |_, args|
53
- if args[:source].nil?
54
- warn 'No source file given'
55
- next
56
- end
57
- verbose = Rake::FileUtilsExt.verbose_flag
58
- project = Neruda::OrgFile.project_for_source(args[:source])
59
- if project.nil?
60
- warn "No project found for #{args['source']}"
61
- next
62
- end
63
- build_html = Thread.new do
64
- o = Neruda::OrgFile.new(
65
- args[:source], project: project, verbose: verbose
66
- )
67
- Thread.current[:org_file] = o
68
- o.publish
69
- end
70
- begin
71
- Neruda::Utils.throbber(build_html, 'Building:')
72
- rescue RuntimeError
73
- warn 'Aborting'
74
- next
75
- end
76
- target = Neruda::OrgFile.target_for_source(args[:source], project)
77
- warn "Customizing file #{target}" if verbose
78
- Neruda::Templater.customize_output(target, build_html[:org_file])
79
- end
80
- end
81
-
82
50
  desc 'Start a test server'
83
51
  task :preview do
84
52
  require 'neruda/preview'
@@ -2,6 +2,7 @@
2
2
  pablo:
3
3
  error:
4
4
  no_command: 'ERROR: no command or unknown command given.'
5
+ no_file: 'ERROR: no file to open or edit.'
5
6
  usage: 'Usage: pablo %1 [options]'
6
7
  commands:
7
8
  cmd_title: Commands
@@ -1,7 +1,8 @@
1
1
  ---
2
2
  pablo:
3
3
  error:
4
- no_command: 'ERREUR: Aucune commande ou commande inconnue donnée.'
4
+ no_command: 'ERREUR: Aucune commande ou commande inconnue donnée.'
5
+ no_file: 'ERREUR : Aucun fichier à ouvrir ou éditer.'
5
6
  usage: 'Usage : pablo %1 [options]'
6
7
  commands:
7
8
  cmd_title: Commandes
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Étienne Deparis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-23 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri