neruda 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b580faa2e64bd6358c78619c309d9568c79a1b66
4
- data.tar.gz: ac61ff055b4c36d9f5afa967929cf53440136065
2
+ SHA256:
3
+ metadata.gz: 7f3224292de6de88d025190d293fd0e9043f2cb54832986410975343887be77d
4
+ data.tar.gz: aaf3bf95cf510fc67cd0dcab3f6c9a65d2153ed676b4300c068dda01bfca6241
5
5
  SHA512:
6
- metadata.gz: e76d4ecfa5b9f1eba99b8b2348cc387bc14909e7815d8871b97c84416027df5450ded9ef0f34605d772fa87928c846b12b30a4d21e3ee4d03425d6ddfc9c8b2e
7
- data.tar.gz: 917fad9923f0d548450c6ae5c7cc42b4cfa5238c787c39077abe9f385f1626d808cb9b74f845cdf59c851cd1e863a4f41192ca04c1c6e0274c4119d56aa1a45e
6
+ metadata.gz: 662711c6423eea8c5c554c53761f23e56260fe8c022685d62ef8b234e6ef89f9bffd85707ff8e39e96c460096817bd52964111ad4f2f86f4b8945856e64be693
7
+ data.tar.gz: 6b95b730be8814ed2d9af07452b34caa6ac07ef58bdfcaef8c653ec901081392e2c2c1e5c85fa392e698a292566b69c25a24297e52beecabe1f8b2211426c141
data/bin/pablo CHANGED
@@ -1,283 +1,142 @@
1
1
  #!/usr/bin/env ruby
2
- # coding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
- require 'yaml'
6
- require 'rainbow'
4
+ require 'rake'
7
5
  require 'optparse'
8
- require 'fileutils'
9
-
10
- # Methods used to play with bundler
11
- module BundlerHelper
12
- def bundler_is_present?
13
- return false unless File.exist?('Gemfile')
14
- ENV['PATH'].split(':').each do |folder|
15
- return true if File.exist? File.join(folder, 'bundle')
16
- end
17
- false
18
- end
19
-
20
- def rake_or_bundle_run(cmd, use_system = false)
21
- cmd.insert(1, '-s') unless @options[:verbose]
22
- cmd = ['bundle', 'exec'] + cmd if bundler_is_present?
23
- joined_cmd = cmd.join(' ')
24
- puts Rainbow(joined_cmd).blue if @options[:verbose]
25
- return system(joined_cmd) if use_system
26
- exec(*cmd)
27
- end
28
-
29
- def capify
30
- unless File.exist? 'Capfile'
31
- STDERR.puts Rainbow('ERROR: Capfile does not exist.').red
32
- exit 1
33
- end
34
-
35
- capfile = File.new('Capfile', 'a')
36
- capfile.write <<~CAPFILE
37
- neruda_spec = Gem::Specification.find_by_name 'neruda'
38
- Dir.glob("\#{neruda_spec.gem_dir}/lib/tasks/*.rake").each { |r| import r }
39
- Dir.glob("\#{neruda_spec.gem_dir}/lib/tasks/capistrano/*.rake").each { |r| import r }
40
- CAPFILE
41
- end
42
- end
43
-
44
- # Methods used with pablo init method
45
- module PabloInit
46
- def init_path
47
- FileUtils.mkdir_p 'config'
48
- FileUtils.mkdir_p 'public'
49
- FileUtils.mkdir_p 'tmp/pids'
50
- FileUtils.mkdir_p 'private/characters'
51
- FileUtils.mkdir_p 'private/sceneries'
52
- FileUtils.mkdir_p 'private/chapters'
53
- FileUtils.mkdir_p 'private/notes'
54
- FileUtils.mkdir_p 'private/epubs'
55
- end
56
-
57
- def init_config
58
- config = {}
59
- print 'Name of your website: '
60
- config['title'] = STDIN.gets.strip
61
- print 'Your author name: '
62
- config['author'] = STDIN.gets.strip
63
- print 'Main language of your website [en_US]: '
64
- lang = STDIN.gets.strip
65
- lang = 'en_US' if lang == ''
66
- config['lang'] = lang
67
-
68
- main_title = config['title'].tr(' ', '_').downcase.gsub(/[^a-z0-9_]/, '')
69
- print "Filename of the main generated epub [#{main_title}]: "
70
- epub = STDIN.gets.strip
71
- if epub == ''
72
- epub = main_title
6
+ require 'r18n-core'
7
+ require 'neruda/utils'
8
+ require 'neruda/version'
9
+
10
+ R18n.set(Neruda::Config.settings['lang'],
11
+ File.expand_path('../locales', __dir__))
12
+
13
+ # Pablo commands
14
+ module PabloCommands
15
+ def pablo_init
16
+ cnf = @options.merge
17
+ cnf.delete(:verbose)
18
+ cnf.delete(:directory)
19
+ cnf.transform_keys!(&:to_s)
20
+ Neruda::Config.save(Neruda::Config.settings.merge(cnf))
21
+ @rake.options.build_all = true
22
+ @rake.invoke_task('org:install')
23
+ o = Neruda::OrgFile.new('src/index.org', @options)
24
+ o.write unless File.exist? 'src/index.org'
25
+ end
26
+ alias_method :pablo_config, :pablo_init
27
+
28
+ def pablo_build(file = ARGV[0])
29
+ @rake.options.build_all = true
30
+ if file.nil?
31
+ @rake.invoke_task('site:build')
73
32
  else
74
- epub = File.basename(epub, '.epub')
33
+ @rake.invoke_task("site:build:one[#{file}]")
75
34
  end
76
- config['book_filename'] = epub
77
- config['chapters'] = []
78
-
79
- IO.write 'config/config.yml', config.to_yaml
80
35
  end
81
36
 
82
- def init_assets
83
- unless Dir.exist? 'views'
84
- FileUtils.cp_r File.join(__dir__, '../lib/assets'), 'views'
85
- end
86
-
87
- return if File.exist? 'public/style.css'
88
- FileUtils.mv 'views/style.css', 'public/style.css'
37
+ def pablo_preview
38
+ @rake.invoke_task('site:preview')
89
39
  end
90
40
 
91
- def init_rackup
92
- unless File.exist? 'Rakefile'
93
- FileUtils.copy File.join(__dir__, '../docs/Rakefile.example'), 'Rakefile'
94
- end
95
-
96
- return if File.exist? 'config.ru'
97
- IO.write 'config.ru', <<~CONFIG
98
- # frozen_string_literal: true
41
+ def pablo_open
42
+ filename = ARGV[0] || new_file_name
43
+ FileUtils.mkdir_p File.dirname(filename)
44
+ o = Neruda::OrgFile.new(filename, @options)
45
+ o.write unless File.exist? filename
99
46
 
100
- require 'neruda'
101
- run Neruda::App
102
- CONFIG
47
+ editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
48
+ cmd = [editor, filename]
49
+ cmd.insert(1, '+6') if editor.match?(/^emacs/)
50
+ system(*cmd)
103
51
  end
104
52
 
105
- def init_bundler
106
- return if File.exist? 'Gemfile'
107
- puts ''
108
- puts 'Bundler has been detected in your path.'
109
- # puts ''
110
- # print 'Do you want to use [o]rg files, [m]arkdown files or [b]oth' \
111
- # ' (default is org): '
112
- # markup = STDIN.gets.strip.downcase
113
- # if markup == 'm'
114
- # markup_gem = 'gem \'kramdown\''
115
- # elsif markup == 'b'
116
- # markup_gem = "gem 'kramdown'\ngem 'org-ruby'"
117
- # else
118
- # markup_gem = 'gem \'org-ruby\''
119
- # end
120
- markup_gem = 'gem \'org-ruby\''
121
-
122
- IO.write 'Gemfile', <<~GEMFILE
123
- # frozen_string_literal: true
124
-
125
- source 'https://rubygems.org'
126
-
127
- gem 'neruda'
128
- #{markup_gem}
129
-
130
- group :development do
131
- gem 'capistrano'
132
- gem 'capistrano-bundler'
133
- gem 'capistrano-rvm'
134
- gem 'rubocop'
135
- end
136
- GEMFILE
137
- puts ''
138
- puts 'To complete this installation, you must now run: ' +
139
- Rainbow('bundle install').yellow
53
+ def pablo_help(command = 'basic', error = false)
54
+ warn R18n.t.pablo.error.no_command if error
55
+ command = 'basic' unless Neruda::Utils::PABLO_COMMANDS.include?(command)
56
+ cmd_opt = Neruda::Utils::PABLO_COMMANDS[command]
57
+ label = cmd_opt[:label] || command
58
+ warn "Usage: pablo #{label} [options]\n\n"
59
+ warn cmd_opt[:desc] + "\n\n" if cmd_opt.has_key?(:desc)
60
+ warn "Options\n#{Neruda::Utils.summarize_command(command)}\n"
61
+ warn "Commands\n#{Neruda::Utils.list_commands}\n" if command == 'basic'
62
+ exit 1 if error
63
+ exit
140
64
  end
141
65
 
142
- def setup
143
- puts Rainbow('Creating main folders…').blue
144
- init_path
145
- puts Rainbow('Populating config file…').blue
146
- init_config
147
- puts Rainbow('Copying template files…').blue
148
- init_assets
149
- puts Rainbow('Installing rake files…').blue
150
- init_rackup
151
- puts ''
152
- puts Rainbow('Neruda has been successfully installed.').green
153
- init_bundler if bundler_is_present?
66
+ private
67
+
68
+ def new_file_name
69
+ title = @options[:title]
70
+ title = 'new' if title.nil? || title == ''
71
+ filename = Neruda::OrgFile.slug title
72
+ return "#{filename}.org" unless @options[:directory]
73
+ "#{filename}/index.org"
154
74
  end
155
75
  end
156
76
 
157
77
  # Main pablo class
158
78
  class Pablo
159
- def initialize
160
- @options = {
161
- verbose: false
162
- }
163
- @available_commands = ['capify', 'list', 'start', 'edit',
164
- 'setup', 'stop', 'compile']
165
-
166
- parse_options
167
- # Be sure required directories are always there
168
- init_path unless @arg == 'setup'
169
- route_command
79
+ def initialize(opts = {})
80
+ @options = { verbose: false }.merge(opts)
81
+ init_rake
170
82
  end
171
83
 
172
- def route_command
173
- if @arg == 'stop'
174
- rake_or_bundle_run ['rake', 'sinatra:stop']
175
- return
176
- end
177
-
178
- ARGV.shift
179
- send @arg
180
- end
84
+ include PabloCommands
181
85
 
182
86
  private
183
87
 
184
- def handle_aliases
185
- @arg = ARGV[0]
186
- if @arg == 'new'
187
- @arg = 'edit'
188
- elsif @arg == 'run'
189
- @arg = 'start'
190
- elsif @arg == 'init'
191
- @arg = 'setup'
192
- end
88
+ def init_rake
89
+ init_rakefile unless File.exist?('Rakefile')
90
+ @rake = Rake.application
91
+ Rake.verbose(false) unless @options[:verbose]
92
+ @rake.raw_load_rakefile
193
93
  end
194
94
 
195
- def parse_options
196
- optparse = OptionParser.new do |opts|
197
- opts.banner = <<~HELP
198
- Usage:
199
- pablo -h
200
- pablo [ -v ] command
201
-
202
- HELP
203
- opts.on('-v', '--verbose', 'Output more information') do
204
- @options[:verbose] = true
205
- end
206
- opts.on('-h', '--help', 'Display this screen') do
207
- STDERR.puts opts
208
- STDERR.puts
209
- pablo_help
210
- end
211
- end
212
-
213
- optparse.parse!
214
-
215
- handle_aliases
216
-
217
- if !File.exist?('config/config.yml') && @arg != 'setup'
218
- STDERR.puts Rainbow('ERROR: please run pablo setup before all').red
219
- exit 1
220
- end
221
- return if @available_commands.include?(@arg)
222
- STDERR.puts Rainbow('ERROR: no or unknown command given.').red
223
- STDERR.puts Rainbow('Run pablo -h for options and available ' \
224
- 'commands').red
225
- exit 1
226
- end
227
-
228
- include BundlerHelper
229
- include PabloInit
230
-
231
- def pablo_help
232
- STDERR.puts <<~HELP
233
- Book Commands:
234
- new [title] Begin to write a new chapter
235
- edit [title] Continue the writing of a chapter
236
- compile Generate the epubs files
237
- list [elements] List various book elements
238
- (chapters, characters, notes, sceneries)
95
+ def init_rakefile
96
+ rakefile = <<~RAKE
97
+ # frozen_string_literal: true
239
98
 
240
- System Commands
241
- setup Initialize your Neruda instance
242
- (you just need to do it once).
243
- start Start a test web server
244
- stop Stop the web server
245
- HELP
246
- exit
247
- end
99
+ require 'neruda/config'
100
+ require 'r18n-core'
248
101
 
249
- def compile
250
- rake_or_bundle_run ['rake', 'chapters:build_epubs'], true
251
- rake_or_bundle_run ['rake', 'book:make'], true
252
- end
102
+ neruda_spec = Gem::Specification.find_by_name 'neruda'
103
+ R18n.set(Neruda::Config.settings['lang'] || 'en',
104
+ "\#{neruda_spec.gem_dir}/locales")
105
+ R18n::Filters.on(:named_variables)
253
106
 
254
- def start
255
- compile
107
+ Dir.glob("\#{neruda_spec.gem_dir}/lib/tasks/*.rake").each { |r| import r }
256
108
 
257
- loc_env = ENV['APP_ENV'] || 'development'
258
- if loc_env != 'production'
259
- puts Rainbow("Neruda is run in #{loc_env} environment").green
260
- else
261
- puts Rainbow('>> Neruda is run in production environment <<').yellow
262
- end
263
- puts ''
264
- rake_or_bundle_run ['rake', 'sinatra:start']
109
+ task default: 'site:build'
110
+ RAKE
111
+ IO.write 'Rakefile', rakefile
265
112
  end
113
+ end
266
114
 
267
- def edit
268
- if ARGV[0].nil?
269
- print 'Title: '
270
- title = STDIN.gets.strip
271
- else
272
- title = ARGV.join(' ')
273
- end
274
- rake_or_bundle_run ['rake', "chapters:create_or_edit[#{title}]"]
115
+ params = {}
116
+ optparser = OptionParser.new do |opts|
117
+ opts.version = Neruda::VERSION
118
+ Neruda::Utils::PABLO_OPTIONS.each do |k, opt|
119
+ short, long = Neruda::Utils.decorate_option(k)
120
+ opts.send(opt[:meth] || :on, short, long, opt[:desc])
275
121
  end
122
+ end
123
+ optparser.parse!(into: params)
276
124
 
277
- def list
278
- list_type = ARGV[0] || 'chapters'
279
- rake_or_bundle_run ['rake', "book:list[#{list_type}]"]
280
- end
125
+ if params[:version]
126
+ warn optparser.ver
127
+ exit
281
128
  end
282
129
 
283
- Pablo.new
130
+ if ARGV[0] == 'help'
131
+ params[:help] = true
132
+ ARGV.shift
133
+ end
134
+ pablo = Pablo.new(params)
135
+ command = "pablo_#{ARGV[0]}".to_sym
136
+ err = command.nil? || !pablo.respond_to?(command)
137
+ pablo.pablo_help(ARGV[0], err) if err || params[:help]
138
+ ARGV.shift
139
+
140
+ init_cmds = ['pablo_init', 'pablo_config']
141
+ pablo.pablo_init unless File.exist?('config.yml') || init_cmds.include?(command)
142
+ pablo.send command
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'neruda/config/lisp_config'
5
+
6
+ module Neruda
7
+ # Wrapper for configuration
8
+ #
9
+ # This class is a singleton interface, which share the static website
10
+ # being build settings among different steps or tasks.
11
+ #
12
+ # It expects the website author to holds their custom settings in a
13
+ # YAML file named ~config.yml~ available at the root of their
14
+ # project.
15
+ #
16
+ # For example, with the given config file:
17
+ #
18
+ # #+begin_src
19
+ # ---
20
+ # title: My website
21
+ # author: Alice Doe
22
+ # #+end_src
23
+ #
24
+ # Settings will be available like this:
25
+ #
26
+ # #+begin_src
27
+ # Neruda::Config.settings['author']
28
+ # => "Alice Doe"
29
+ # #+end_src
30
+ class Config
31
+ extend Neruda::LispConfig
32
+
33
+ class << self
34
+ # Access the current website settings
35
+ #
36
+ # If the settings have not been loaded yet, this method is
37
+ # responsible for calling the one, which actually loads them.
38
+ #
39
+ # @return [Hash] the website settings
40
+ def settings
41
+ return load_settings unless @config
42
+ @config
43
+ end
44
+
45
+ # Save the settings given as a parameter to the ~config.yml~ file.
46
+ #
47
+ # Not only this method overwrite the old settings, but it replace
48
+ # the current shared settings with the ones given in
49
+ # parameter. Later call to
50
+ # {file:Neruda/Config.html#settings-class_method settings}
51
+ # will, obviously, use these new settings.
52
+ #
53
+ # @param new_config [Hash] the settings to save
54
+ # @return [Hash] the new settings after save
55
+ def save(new_config)
56
+ IO.write 'config.yml', new_config.to_yaml
57
+ @config = new_config.freeze
58
+ end
59
+
60
+ # Load the given settings as if they comes from the ~config.yml~ file.
61
+ #
62
+ # This method is handy for testing purpose. Later call to
63
+ # {file:Neruda/Config.html#settings-class_method settings} will
64
+ # use these new settings.
65
+ #
66
+ # @param config [Hash] the settings to artificially load
67
+ # @return [Hash] the new settings
68
+ def load_test(config)
69
+ @config = config
70
+ add_default_settings
71
+ end
72
+
73
+ private
74
+
75
+ def load_settings
76
+ @config = {}
77
+ conf = 'config.yml'
78
+ @config = YAML.load_file(conf) if File.exist? conf
79
+ add_default_settings
80
+ @config.freeze
81
+ end
82
+
83
+ def add_default_settings
84
+ @config['lang'] ||= 'en'
85
+ @config['author'] ||= (ENV['USER'] || '')
86
+ @config['domain'] ||= ''
87
+ @config['public_folder'] ||= 'public_html'
88
+ @config['templates'] ||= []
89
+ return if @config['blog_path'].nil?
90
+ @config['blog_pattern'] ||= '**/*.org'
91
+ end
92
+ end
93
+ end
94
+ end