neruda 0.0.10 → 0.1.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.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/bin/pablo +105 -246
  3. data/lib/neruda/config.rb +94 -0
  4. data/lib/neruda/config/lisp_config.rb +201 -0
  5. data/lib/neruda/config/org-config.el +17 -0
  6. data/lib/neruda/config/ox-neruda.el +88 -0
  7. data/lib/neruda/index.rb +108 -0
  8. data/lib/neruda/index/atom_generator.rb +86 -0
  9. data/lib/neruda/index/org_generator.rb +92 -0
  10. data/lib/neruda/org_file.rb +266 -0
  11. data/lib/neruda/org_file/class_methods.rb +55 -0
  12. data/lib/neruda/org_file/extracter.rb +61 -0
  13. data/lib/neruda/org_file/htmlizer.rb +78 -0
  14. data/lib/neruda/preview.rb +53 -0
  15. data/lib/neruda/templater.rb +111 -0
  16. data/lib/neruda/utils.rb +130 -0
  17. data/lib/neruda/version.rb +5 -0
  18. data/lib/tasks/org.rake +69 -0
  19. data/lib/tasks/site.rake +84 -0
  20. data/lib/tasks/sync.rake +30 -0
  21. data/locales/en.yml +18 -0
  22. data/locales/fr.yml +18 -0
  23. data/themes/default/css/style.css +216 -0
  24. data/themes/default/fonts/Yanone_Kaffeesatz_400.woff +0 -0
  25. data/themes/default/fonts/Yanone_Kaffeesatz_400.woff2 +0 -0
  26. metadata +145 -39
  27. data/README.md +0 -98
  28. data/docs/Rakefile.example +0 -4
  29. data/docs/config.yml.example +0 -17
  30. data/lib/assets/chapter.slim +0 -14
  31. data/lib/assets/index.slim +0 -13
  32. data/lib/assets/layout.slim +0 -17
  33. data/lib/assets/style.css +0 -199
  34. data/lib/neruda.rb +0 -112
  35. data/lib/neruda/chapter.rb +0 -26
  36. data/lib/neruda/url.rb +0 -14
  37. data/lib/tasks/book.rake +0 -60
  38. data/lib/tasks/capistrano/chapters.rake +0 -60
  39. data/lib/tasks/capistrano/sinatra.rake +0 -18
  40. data/lib/tasks/chapters.rake +0 -132
  41. data/lib/tasks/sinatra.rake +0 -36
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Various method to handle org conversion and metadata access
4
- module Neruda::Chapter
5
- def meta_data(key)
6
- return nil if @content.nil?
7
- value = @content.in_buffer_settings[key.upcase]
8
- return value if value.nil? || !key.casecmp('date').zero?
9
- time_for(value).strftime('%A %d %B %Y')
10
- end
11
-
12
- def title
13
- return Neruda::CONFIG['title'] if @content.nil?
14
- return @title unless @title.nil?
15
- # We use an instance variable to avoid Orgmode::Parser to render
16
- # title with the rest of the file
17
- # Thus we are removing title from the buffer_settings
18
- @title = @content.in_buffer_settings.delete('TITLE')
19
- return @title unless @title.nil?
20
- @title = Neruda::CONFIG['title']
21
- end
22
-
23
- def author
24
- meta_data('author') || Neruda::CONFIG['author']
25
- end
26
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
-
5
- # Various method to ease url handling
6
- module Neruda::Url
7
- def proxy_url(url)
8
- wanted_uri = url(url)
9
- return wanted_uri if Neruda::CONFIG['base_path'].nil?
10
- uri_data = URI.parse(wanted_uri)
11
- uri_data.path = Neruda::CONFIG['base_path'] + uri_data.path
12
- uri_data.to_s
13
- end
14
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'rainbow'
5
-
6
- namespace :book do
7
- desc 'List various book elements'
8
- task :list, :list_type do |_, args|
9
- list_type = args[:list_type]
10
- unless ['chapters', 'characters',
11
- 'notes', 'sceneries'].include?(list_type)
12
- STDERR.puts Rainbow("ERROR: #{list_type} is not a valid list type.").red
13
- STDERR.puts 'Enter one of [chapters, characters, notes, sceneries].'
14
- next
15
- end
16
- Dir.glob("private/#{list_type}/*.org") do |filename|
17
- file_radix = File.basename(filename, '.org')
18
- title = file_radix.split('_').map(&:capitalize).join(' ')
19
- absolute_filename = File.join(Dir.pwd, filename)
20
- puts Rainbow(title).blue + ": #{absolute_filename}"
21
- end
22
- end
23
-
24
- desc 'Create the org file of the complete book'
25
- task prepare: 'chapters:index' do
26
- chapters = YAML.load_file('config/chapters.yml')
27
- next if chapters.nil?
28
-
29
- neruda_config = YAML.load_file('config/config.yml')
30
- final_org = neruda_config['book_filename'] || 'all'
31
- final_org = "tmp/#{final_org}.org"
32
-
33
- Dir.mkdir 'tmp' unless Dir.exist? 'tmp'
34
- File.unlink final_org if File.exist? final_org
35
-
36
- org_file = File.open(final_org, 'a')
37
- org_file.write("#+title: #{neruda_config['title']}\n")
38
- org_file.write("#+author: #{neruda_config['author']}\n")
39
- org_file.write("#+rights: #{neruda_config['license']}\n")
40
- org_file.write("#+language: #{neruda_config['lang']}\n\n")
41
-
42
- chapters.each do |c|
43
- file_radix = c[:slug]
44
- filename = "private/chapters/#{file_radix}.org"
45
- next unless File.exist? filename
46
- file_content = IO.read(filename)
47
- file_content.gsub!(/^#\+date:.*$/i, '')
48
- file_content.gsub!(/^#\+author:.*$/i, '')
49
- file_content.gsub!(/^(\*+)\s+(.*)$/i, '*\1 \2')
50
- file_content.gsub!(/^#\+title:\s?(.*)$/i, '* \1')
51
-
52
- org_file.write(file_content + "\n")
53
- end
54
- org_file.close
55
-
56
- IO.write 'tmp/org_to_convert.yml', [final_org].to_yaml
57
- end
58
-
59
- task make: ['book:prepare', 'chapters:convert_org']
60
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
-
5
- namespace :chapters do
6
- desc 'Upload epub files listed in tmp/epub_to_upload.yml'
7
- task :upload_epubs do
8
- next unless File.exist?('tmp/epub_to_upload.yml')
9
- epub_to_upload = YAML.load_file('tmp/epub_to_upload.yml')
10
- next if epub_to_upload.empty?
11
- on roles(:app) do
12
- epub_to_upload.each do |f|
13
- upload! f, "#{shared_path}/#{f}"
14
- end
15
- end
16
- end
17
-
18
- desc 'Upload the chapters list index'
19
- task upload_index: 'chapters:index' do
20
- on roles(:app) do
21
- upload! 'config/chapters.yml', "#{release_path}/config/chapters.yml"
22
- info 'chatpers.yml has been built and uploaded'
23
- end
24
- end
25
-
26
- desc 'Upload the complete book'
27
- task upload_book: ['book:make', 'chapters:upload_epubs']
28
-
29
- namespace :purge do
30
- desc 'Remove remote orphaned epub files'
31
- task :remote do
32
- neruda_config = YAML.load_file('config/config.yml')
33
- final_org = neruda_config['book_filename'] || 'all'
34
- on roles(:app) do
35
- within release_path do
36
- begin
37
- epub_files = capture :ls, '-1', 'private/epubs/*.epub'
38
- rescue SSHKit::Command::Failed
39
- warn 'No epub files found. Aborting.'
40
- next
41
- end
42
- epub_files.each_line do |filename|
43
- filename.delete!("\n")
44
- file_radix = File.basename(filename, '.epub')
45
- next if file_radix == final_org
46
- org_file = "private/chapters/#{file_radix}.org"
47
- unless test("[ -e '#{release_path}/#{org_file}' ]")
48
- execute :rm, filename
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
-
56
- desc 'Execute in one call the following: :build_epubs,' \
57
- ':upload_epubs, :upload_book, :purge:remote'
58
- task sync: ['chapters:build_epubs', 'chapters:upload_epubs',
59
- 'chapters:upload_book', 'chapters:purge:remote']
60
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :sinatra do
4
- namespace :restart do
5
- desc 'Restart the remote neruda application'
6
- task :remote do
7
- on roles(:app) do
8
- within release_path do
9
- if test("[ -e '#{release_path}/tmp/pids/sinatra.pid' ]")
10
- execute :pkill, '-F', 'tmp/pids/sinatra.pid'
11
- end
12
- execute :bundle, :exec, :rackup, '-E', fetch(:app_env),
13
- '-P', 'tmp/pids/sinatra.pid', '-D'
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
-
5
- namespace :chapters do
6
- desc 'Identify all org files'
7
- task :list_all_orgs do
8
- org_to_convert = []
9
- File.unlink 'tmp/org_to_convert.yml' if File.exist? 'tmp/org_to_convert.yml'
10
- neruda_config = YAML.load_file('config/config.yml')
11
- chapters = neruda_config['chapters']
12
- next unless chapters.any?
13
- chapters.each do |file_radix|
14
- filename = "private/chapters/#{file_radix}.org"
15
- org_to_convert << filename
16
- end
17
- next if org_to_convert.empty?
18
- Dir.mkdir 'tmp' unless Dir.exist? 'tmp'
19
- IO.write 'tmp/org_to_convert.yml', org_to_convert.to_yaml
20
- end
21
-
22
- desc 'Identify orphan (without epubs) org files'
23
- task list_orphaned_orgs: 'chapters:list_all_orgs' do
24
- next unless File.exist? 'tmp/org_to_convert.yml'
25
- org_to_convert = []
26
- chapters = YAML.load_file('tmp/org_to_convert.yml')
27
- next unless chapters.any?
28
- chapters.each do |filename|
29
- file_radix = File.basename(filename, '.org')
30
- epub_file = "private/epubs/#{file_radix}.epub"
31
- org_to_convert << filename unless File.exist? epub_file
32
- end
33
- next if org_to_convert.empty?
34
- IO.write 'tmp/org_to_convert.yml', org_to_convert.to_yaml
35
- end
36
-
37
- desc 'Convert org files from tmp/org_to_convert.yml to epubs'
38
- task :convert_org do
39
- next unless File.exist?('tmp/org_to_convert.yml')
40
- File.unlink 'tmp/epub_to_upload.yml' if File.exist? 'tmp/epub_to_upload.yml'
41
- org_to_convert = YAML.load_file('tmp/org_to_convert.yml')
42
- next if org_to_convert.empty?
43
- epub_to_upload = []
44
- org_to_convert.each do |filename|
45
- file_radix = File.basename(filename, '.org')
46
- epub_file = "private/epubs/#{file_radix}.epub"
47
- epub_to_upload << epub_file
48
- puts "Converting #{filename} to #{epub_file}"
49
- sh 'pandoc', '-S', "--output=#{epub_file}", filename
50
- end
51
- next if epub_to_upload.empty?
52
- IO.write 'tmp/epub_to_upload.yml', epub_to_upload.to_yaml
53
- end
54
-
55
- desc 'Build missing epubs'
56
- task build_epubs: ['chapters:list_orphaned_orgs', 'chapters:convert_org']
57
-
58
- namespace :build_epubs do
59
- desc '(re)Build all epub files for each org files'
60
- task force_all: ['chapters:list_all_orgs', 'chapters:convert_org']
61
- end
62
-
63
- desc 'Remove orphaned (epub without org files) epub files'
64
- task :purge do
65
- neruda_config = YAML.load_file('config/config.yml')
66
- final_org = neruda_config['book_filename'] || 'all'
67
- chapters = neruda_config['chapters']
68
- Dir.glob('private/chapters/*.org') do |filename|
69
- file_radix = File.basename(filename, '.org')
70
- unless chapters.include? file_radix
71
- STDERR.puts "WARNING: #{filename} exists but #{file_radix} " \
72
- 'is no more in the chapters list.'
73
- end
74
- end
75
-
76
- Dir.glob('private/epubs/*.epub') do |filename|
77
- file_radix = File.basename(filename, '.epub')
78
- next if file_radix == final_org
79
- org_file = "private/chapters/#{file_radix}.org"
80
- File.unlink filename unless File.exist? org_file
81
- end
82
- end
83
-
84
- desc 'Create/Update the chapters list index'
85
- task :index do
86
- require 'org-ruby'
87
- neruda_config = YAML.load_file('config/config.yml')
88
- next if neruda_config['chapters'].nil?
89
- chapters = []
90
- neruda_config['chapters'].each do |file_radix|
91
- filename = "private/chapters/#{file_radix}.org"
92
- next unless File.exist? filename
93
- f = Orgmode::Parser.load filename
94
- title = f.in_buffer_settings['TITLE']
95
- chapters << { slug: file_radix, title: title } unless title.nil?
96
- end
97
- IO.write 'config/chapters.yml', chapters.to_yaml
98
- end
99
-
100
- desc 'Open an editor to create a new chapter'
101
- task :create_or_edit, :title do |_, args|
102
- if args[:title] == ''
103
- filename = 'new'
104
- else
105
- filename = args[:title].tr(' ', '_').downcase.gsub(/[^a-z0-9_]/, '')
106
- end
107
-
108
- filename = "private/chapters/#{filename}.org"
109
-
110
- unless File.exist? filename
111
- config = YAML.load_file('config/config.yml')
112
- filecontent = <<~ORG
113
- #+title: #{args[:title]}
114
- #+date: <#{Date.today.strftime('%Y-%m-%d %a.')}>
115
- #+author: #{config['author']}
116
-
117
- ORG
118
- IO.write filename, filecontent
119
- end
120
-
121
- editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
122
-
123
- puts Rainbow(args[:title]).blue
124
- puts "Opening #{filename} with #{editor}"
125
-
126
- if editor.match?(/^emacs/)
127
- sh [editor, '+5', filename].join(' ')
128
- else
129
- sh [editor, filename].join(' ')
130
- end
131
- end
132
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rainbow'
4
-
5
- namespace :sinatra do
6
- desc 'Stop the underlaying sinatra application'
7
- task :stop do
8
- unless File.exist? 'tmp/pids/neruda.pid'
9
- STDERR.puts Rainbow('No pid file found').red
10
- exit 1
11
- end
12
- pid = IO.read('tmp/pids/neruda.pid').strip.to_i
13
- Process.kill('TERM', pid)
14
- File.unlink 'tmp/pids/neruda.pid'
15
- puts Rainbow('Done').green
16
- end
17
-
18
- desc 'Start the underlaying sinatra application'
19
- task :start do
20
- loc_env = ENV['APP_ENV'] || 'development'
21
- cmd = ['rackup', "-E #{loc_env}", '-P', 'tmp/pids/neruda.pid']
22
- cmd << '-D' if loc_env == 'production'
23
- begin
24
- if ENV['APP_ENV'].nil?
25
- system({ 'APP_ENV' => loc_env }, cmd.join(' '))
26
- else
27
- sh(*cmd)
28
- end
29
- rescue Interrupt
30
- puts Rainbow('Kthxbye').blue
31
- end
32
- end
33
-
34
- desc 'Restart local sinatra server'
35
- task restart: ['sinatra:stop', 'sinatra:start']
36
- end