aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Étienne Deparis 2022-09-23 21:47:50 +0200
committerGravatar Étienne Deparis 2022-09-23 21:47:50 +0200
commit26da0fb76407f74fa919e328cec62b753ad2bd15 (patch)
tree4a04c822bd7dce7f5428abe26fef91da08b5a7b3
parent6ce00b587104f987a7e5a43c0e73bde95b9d626d (diff)
parent981af72ded90360598929350f3a35859a79bdecb (diff)
downloadfronde-main.tar.gz
fronde-main.tar.xz
fronde-main.zip
Merge branch 'v0.3.3-dev'HEADv0.3.3main
-rw-r--r--Gemfile.lock92
-rw-r--r--README.org9
-rwxr-xr-xbin/fronde4
-rw-r--r--fronde.gemspec20
-rw-r--r--lib/fronde/cli.rb6
-rw-r--r--lib/fronde/cli/commands.rb26
-rw-r--r--lib/fronde/config.rb63
-rw-r--r--lib/fronde/config/lisp_config.rb82
-rw-r--r--lib/fronde/emacs.rb2
-rw-r--r--lib/fronde/index.rb2
-rw-r--r--lib/fronde/index/atom_generator.rb11
-rw-r--r--lib/fronde/index/org_generator.rb12
-rw-r--r--lib/fronde/org_file.rb14
-rw-r--r--lib/fronde/org_file/class_methods.rb4
-rw-r--r--lib/fronde/org_file/extracter.rb6
-rw-r--r--lib/fronde/org_file/htmlizer.rb2
-rw-r--r--lib/fronde/preview.rb10
-rw-r--r--lib/fronde/templater.rb4
-rw-r--r--lib/fronde/utils.rb17
-rw-r--r--lib/fronde/version.rb2
-rw-r--r--lib/tasks/org.rake25
-rw-r--r--lib/tasks/site.rake5
-rw-r--r--lib/tasks/sync.rake50
-rw-r--r--locales/en.yml1
-rw-r--r--locales/fr.yml1
-rw-r--r--spec/data/index_proof.html30
-rw-r--r--spec/fronde/config_spec.rb85
-rw-r--r--spec/fronde/index_spec.rb44
-rw-r--r--spec/fronde/org_file_spec.rb53
-rw-r--r--spec/fronde/templater_spec.rb63
-rw-r--r--spec/fronde/utils_spec.rb27
-rw-r--r--spec/rake_org_spec.rb34
-rw-r--r--spec/rake_preview_spec.rb24
-rw-r--r--spec/rake_site_spec.rb19
-rw-r--r--spec/requirements.rb21
35 files changed, 493 insertions, 377 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index d8d69f3..b14428c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,10 +1,10 @@
PATH
remote: .
specs:
- fronde (0.3.2)
- nokogiri (~> 1.11)
+ fronde (0.3.3)
+ nokogiri (~> 1.13)
r18n-core (~> 5.0)
- rainbow (~> 3.0)
+ rainbow (~> 3.1)
rake (~> 13.0)
webrick (~> 1.7)
@@ -14,60 +14,61 @@ GEM
ast (2.4.2)
byebug (11.1.3)
coderay (1.1.3)
- diff-lcs (1.4.4)
- docile (1.3.5)
+ diff-lcs (1.5.0)
+ docile (1.4.0)
+ json (2.6.2)
method_source (1.0.0)
- mini_portile2 (2.6.1)
- nokogiri (1.12.4)
- mini_portile2 (~> 2.6.1)
+ mini_portile2 (2.8.0)
+ nokogiri (1.13.8)
+ mini_portile2 (~> 2.8.0)
racc (~> 1.4)
org-ruby (0.9.12)
rubypants (~> 0.2)
- parallel (1.20.1)
- parser (3.0.1.0)
+ parallel (1.22.1)
+ parser (3.1.2.1)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
- pry-doc (1.1.0)
+ pry-doc (1.3.0)
pry (~> 0.11)
yard (~> 0.9.11)
r18n-core (5.0.1)
- racc (1.5.2)
- rainbow (3.0.0)
+ racc (1.6.0)
+ rainbow (3.1.1)
rake (13.0.6)
- regexp_parser (2.1.1)
+ regexp_parser (2.5.0)
rexml (3.2.5)
- rspec (3.10.0)
- rspec-core (~> 3.10.0)
- rspec-expectations (~> 3.10.0)
- rspec-mocks (~> 3.10.0)
- rspec-core (3.10.1)
- rspec-support (~> 3.10.0)
- rspec-expectations (3.10.1)
+ rspec (3.11.0)
+ rspec-core (~> 3.11.0)
+ rspec-expectations (~> 3.11.0)
+ rspec-mocks (~> 3.11.0)
+ rspec-core (3.11.0)
+ rspec-support (~> 3.11.0)
+ rspec-expectations (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.10.0)
- rspec-mocks (3.10.2)
+ rspec-support (~> 3.11.0)
+ rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
- rspec-support (~> 3.10.0)
- rspec-support (3.10.2)
- rubocop (1.12.1)
+ rspec-support (~> 3.11.0)
+ rspec-support (3.11.1)
+ rubocop (1.36.0)
+ json (~> 2.3)
parallel (~> 1.10)
- parser (>= 3.0.0.0)
+ parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
- rexml
- rubocop-ast (>= 1.2.0, < 2.0)
+ rexml (>= 3.2.5, < 4.0)
+ rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
- rubocop-ast (1.4.1)
- parser (>= 2.7.1.5)
- rubocop-performance (1.10.2)
- rubocop (>= 0.90.0, < 2.0)
+ rubocop-ast (1.21.0)
+ parser (>= 3.1.1.0)
+ rubocop-performance (1.15.0)
+ rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
- rubocop-rspec (2.2.0)
- rubocop (~> 1.0)
- rubocop-ast (>= 1.1.0)
+ rubocop-rspec (2.13.1)
+ rubocop (~> 1.33)
ruby-progressbar (1.11.0)
rubypants (0.7.1)
simplecov (0.21.2)
@@ -75,10 +76,11 @@ GEM
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
- simplecov_json_formatter (0.1.2)
- unicode-display_width (2.0.0)
+ simplecov_json_formatter (0.1.4)
+ unicode-display_width (2.3.0)
webrick (1.7.0)
- yard (0.9.26)
+ yard (0.9.28)
+ webrick (~> 1.7.0)
PLATFORMS
ruby
@@ -88,13 +90,13 @@ DEPENDENCIES
fronde!
org-ruby (~> 0.9)
pry (~> 0.14)
- pry-doc (~> 1.1)
- rspec (~> 3.10)
- rubocop (~> 1.12)
- rubocop-performance (~> 1.10)
- rubocop-rspec (~> 2.2)
+ pry-doc (~> 1.3)
+ rspec (~> 3.11)
+ rubocop (~> 1.36)
+ rubocop-performance (~> 1.15)
+ rubocop-rspec (~> 2.13)
simplecov (~> 0.21)
yard (~> 0.9)
BUNDLED WITH
- 2.2.22
+ 2.3.19
diff --git a/README.org b/README.org
index 54ff618..ac276d7 100644
--- a/README.org
+++ b/README.org
@@ -50,6 +50,15 @@ fronde build
fronde preview
#+end_src
+* Support
+
+#+html: <a href="https://liberapay.com/milouse/donate"><img alt="Support using Liberapay" src="https://img.shields.io/badge/Liberapay-Support_me-yellow?logo=liberapay"/></a>
+#+html: <a href="https://paypal.me/milouse"><img alt="Support using Paypal" src="https://img.shields.io/badge/Paypal-Support_me-00457C?logo=paypal&labelColor=lightgray"/></a>
+
+You can help me a lot by giving me some tip, either through [[https://liberapay.com/milouse][Liberapay]] or
+[[https://paypal.me/milouse][Paypal]]. Thank you very much!
+
+
* Going further
Please refer to the [[./DOCUMENTATION.org][documentation]].
diff --git a/bin/fronde b/bin/fronde
index c4a370d..3da72a7 100755
--- a/bin/fronde
+++ b/bin/fronde
@@ -8,7 +8,7 @@ require 'fronde/version'
require 'fronde/cli'
R18n.default_places = File.expand_path('../locales', __dir__)
-R18n.set Fronde::Config.settings['lang']
+R18n.set Fronde::Config.get('lang')
optparser = OptionParser.new
optparser.version = Fronde::VERSION
@@ -38,7 +38,7 @@ if params[:help] || cmd_err
end
ARGV.shift
-init_cmds = [:fronde_init, :fronde_config]
+init_cmds = [:fronde_init, :fronde_config, :fronde_update]
unless File.exist?('config.yml') || init_cmds.include?(command)
fronde.fronde_init
end
diff --git a/fronde.gemspec b/fronde.gemspec
index bf3cd43..69b8d28 100644
--- a/fronde.gemspec
+++ b/fronde.gemspec
@@ -12,6 +12,12 @@ Gem::Specification.new do |s|
DESC
s.authors = ['Étienne Deparis']
s.email = 'etienne@depar.is'
+ s.metadata = {
+ 'rubygems_mfa_required' => 'true',
+ 'source_code_uri' => 'https://git.umaneti.net/fronde',
+ 'homepage_uri' => 'https://etienne.depar.is/fronde/',
+ 'funding_uri' => 'https://liberapay.com/milouse'
+ }
s.files = ['lib/fronde/cli.rb',
'lib/fronde/cli/commands.rb',
'lib/fronde/config.rb',
@@ -45,20 +51,20 @@ Gem::Specification.new do |s|
s.license = 'WTFPL'
s.required_ruby_version = '>= 2.7'
- s.add_runtime_dependency 'nokogiri', '~> 1.11'
+ s.add_runtime_dependency 'nokogiri', '~> 1.13'
s.add_runtime_dependency 'r18n-core', '~> 5.0'
- s.add_runtime_dependency 'rainbow', '~> 3.0'
+ s.add_runtime_dependency 'rainbow', '~> 3.1'
s.add_runtime_dependency 'rake', '~> 13.0'
s.add_runtime_dependency 'webrick', '~> 1.7'
s.add_development_dependency 'byebug', '~> 11.1'
s.add_development_dependency 'org-ruby', '~> 0.9'
s.add_development_dependency 'pry', '~> 0.14'
- s.add_development_dependency 'pry-doc', '~> 1.1'
- s.add_development_dependency 'rspec', '~> 3.10'
- s.add_development_dependency 'rubocop', '~> 1.12'
- s.add_development_dependency 'rubocop-performance', '~> 1.10'
- s.add_development_dependency 'rubocop-rspec', '~> 2.2'
+ s.add_development_dependency 'pry-doc', '~> 1.3'
+ s.add_development_dependency 'rspec', '~> 3.11'
+ s.add_development_dependency 'rubocop', '~> 1.36'
+ s.add_development_dependency 'rubocop-performance', '~> 1.15'
+ s.add_development_dependency 'rubocop-rspec', '~> 2.13'
s.add_development_dependency 'simplecov', '~> 0.21'
s.add_development_dependency 'yard', '~> 0.9'
end
diff --git a/lib/fronde/cli.rb b/lib/fronde/cli.rb
index c9bd87e..93566ea 100644
--- a/lib/fronde/cli.rb
+++ b/lib/fronde/cli.rb
@@ -36,14 +36,14 @@ module Fronde
fronde_spec = Gem::Specification.find_by_name 'fronde'
R18n.default_places = "\#{fronde_spec.gem_dir}/locales"
- R18n.set(Fronde::Config.settings['lang'] || 'en')
+ R18n.set(Fronde::Config.get('lang', 'en'))
R18n::Filters.on(:named_variables)
Dir.glob("\#{fronde_spec.gem_dir}/lib/tasks/*.rake").each { |r| import r }
task default: 'site:build'
RAKE
- IO.write 'Rakefile', rakefile
+ File.write 'Rakefile', rakefile
end
def init_gitignore
@@ -54,7 +54,7 @@ module Fronde
public_html
var
GITIGNORE
- IO.write '.gitignore', gitignore
+ File.write '.gitignore', gitignore
end
end
end
diff --git a/lib/fronde/cli/commands.rb b/lib/fronde/cli/commands.rb
index 321a1d4..2b86f4d 100644
--- a/lib/fronde/cli/commands.rb
+++ b/lib/fronde/cli/commands.rb
@@ -3,18 +3,21 @@
module Fronde
# Fronde commands
module CLICommands
+ def fronde_update
+ update_config
+ @rake.options.build_all = true
+ @rake.invoke_task('org:upgrade')
+ end
+ alias_method :fronde_config, :fronde_update
+
def fronde_init
- cnf = @options.merge
- cnf.delete(:verbose)
- cnf.transform_keys!(&:to_s)
- Fronde::Config.save(Fronde::Config.settings.merge(cnf))
+ update_config
@rake.options.build_all = true
@rake.invoke_task('org:install')
return if File.exist? 'src/index.org'
Fronde::OrgFile.new('src/index.org', @options).write
fronde_open 'src/index.org'
end
- alias_method :fronde_config, :fronde_init
def fronde_build
@rake.options.build_all = true
@@ -26,7 +29,7 @@ module Fronde
def fronde_preview
Thread.new do
sleep 1
- port = Fronde::Config.settings.dig('preview', 'server_port') || 5000
+ port = Fronde::Config.get(['preview', 'server_port'], 5000)
uri = "http://127.0.0.1:#{port}/"
current_os = Fronde::Utils.current_os
case current_os
@@ -62,10 +65,10 @@ module Fronde
def fronde_help(command = 'basic', error: false)
warn R18n.t.fronde.bin.error.no_command if error
- cmd = Fronde::Utils.resolve_possible_alias(command)
- cmd_opt = Fronde::Utils::FRONDE_COMMANDS[cmd]
+ cmd_opt = Fronde::Utils.command_options(command)
label = cmd_opt[:label] || command
warn format("%<label>s\n\n", label: R18n.t.fronde.bin.usage(label))
+ cmd = cmd_opt[:name] || command
if R18n.t.fronde.bin.commands[cmd].translated?
warn format("%<label>s\n\n", label: R18n.t.fronde.bin.commands[cmd])
end
@@ -76,6 +79,13 @@ module Fronde
private
+ def update_config
+ cnf = @options.merge
+ cnf.delete(:verbose)
+ cnf.transform_keys!(&:to_s)
+ Fronde::Config.save(Fronde::Config.settings.merge(cnf))
+ end
+
def new_file_name(file_path)
file_path = File.expand_path(file_path || '')
return file_path if file_path[-4..] == '.org'
diff --git a/lib/fronde/config.rb b/lib/fronde/config.rb
index da2bf18..f8dee65 100644
--- a/lib/fronde/config.rb
+++ b/lib/fronde/config.rb
@@ -24,7 +24,7 @@ module Fronde
# Settings will be available like this:
#
# #+begin_src
- # Fronde::Config.settings['author']
+ # Fronde::Config.get('author')
# => "Alice Doe"
# #+end_src
class Config
@@ -33,15 +33,38 @@ module Fronde
class << self
# Access the current website settings
#
- # If the settings have not been loaded yet, this method is
- # responsible for calling the one, which actually loads them.
+ # If necessary, this method will load settings from a config
+ # file.
#
# @return [Hash] the website settings
def settings
- return load_settings unless @config
+ load_settings
@config
end
+ # Return a named setting.
+ #
+ # ~setting~ may be a ~String~ or an ~Array~.
+ #
+ # If the given ~setting~ name is an Array, this method will
+ # behave as ~Hash::dig~.
+ #
+ # If no value is found for the given setting, ~default~ will be
+ # returned.
+ #
+ # @param setting [String, Array] the setting to get
+ # @param default the default value to use if ~setting~ is absent
+ # @return the setting value or nil
+ def get(setting, default = nil)
+ load_settings
+ if setting.is_a? Array
+ value = @config.dig(*setting)
+ else
+ value = @config[setting]
+ end
+ value || default
+ end
+
# Save the settings given as a parameter to the ~config.yml~ file.
#
# Not only this method overwrite the old settings, but it replace
@@ -58,25 +81,42 @@ module Fronde
# which may be different from a system to another. Thus it may
# be confusing if one use fronde on two different computer and
# these params always change.
+ default_keys = default_settings.keys
new_config.delete_if do |k, v|
- ['domain', 'public_folder', 'templates', 'theme'].include?(k) \
- && v == default_settings[k]
+ default_keys.include?(k) && v == default_settings[k]
end
- IO.write 'config.yml', new_config.to_yaml
+ File.write 'config.yml', new_config.to_yaml
+ @config = @sources = nil
load_settings # Reload config, taking default settings into account
end
+ # Reset settings
+ #
+ # This method is handy for testing purpose. Next call to
+ # {file:Fronde/Config.html#get-class_method get} or
+ # {file:Fronde/Config.html#settings-class_method settings} will
+ # force reload the settings from the config file
+ #
+ # @return nil
+ def reset
+ @sources = @config = nil
+ end
+
# Load the given settings as if they comes from the ~config.yml~ file.
#
- # This method is handy for testing purpose. Later call to
+ # This method is handy for testing purpose. Next call to
+ # {file:Fronde/Config.html#get-class_method get},
+ # {file:Fronde/Config.html#sources-class_method sources} or
# {file:Fronde/Config.html#settings-class_method settings} will
# use these new settings.
#
# @param config [Hash] the settings to artificially load
# @return [Hash] the new settings
def load_test(config)
- @sources = nil # Reset sources
+ reset
@config = default_settings.merge config
+ sources
+ @config
end
# Return the qualified projects sources list.
@@ -84,8 +124,9 @@ module Fronde
# @return [Array] the fully qualified projects sources list
def sources
return @sources if @sources
+ load_settings
default_sources = [{ 'path' => 'src', 'target' => '.' }]
- @sources = (settings['sources'] || default_sources).map do |s|
+ @sources = get('sources', default_sources).map do |s|
build_source(s)
end.compact
end
@@ -93,7 +134,7 @@ module Fronde
private
def load_settings
- @sources = nil
+ return @config if @config
conf_file = 'config.yml'
if File.exist? conf_file
@config = default_settings.merge(YAML.load_file(conf_file)).freeze
diff --git a/lib/fronde/config/lisp_config.rb b/lib/fronde/config/lisp_config.rb
index 0633f54..3862d7f 100644
--- a/lib/fronde/config/lisp_config.rb
+++ b/lib/fronde/config/lisp_config.rb
@@ -4,6 +4,20 @@ require 'json'
require 'open-uri'
require 'fronde/version'
+def fetch_org_version
+ # Retrieve last org version from git repository tags page.
+ tag_rx = Regexp.new(
+ '<a href=\'/cgit/emacs/org-mode.git/tag/\?h=' \
+ '(?<tag>release_(?<number>[^\']+))\'>\k<tag></a>'
+ )
+ versions = URI(
+ 'https://git.savannah.gnu.org/cgit/emacs/org-mode.git/refs/'
+ ).open.readlines.map do |line|
+ line.match(tag_rx) { |matchdata| matchdata[:number] }
+ end
+ versions.compact.first
+end
+
module Fronde
# This module contains utilitary methods to ease ~org-config.el~
# file generation
@@ -14,15 +28,12 @@ module Fronde
def org_last_version
return @org_version if @org_version
if File.exist?('var/tmp/last_org_version')
- @org_version = IO.read('var/tmp/last_org_version')
+ @org_version = File.read('var/tmp/last_org_version')
return @org_version
end
- versions = JSON.parse(
- URI('https://updates.orgmode.org/data/releases').open.read
- ).sort { |a, b| b['date'] <=> a['date'] }
- @org_version = versions.first['version']
+ @org_version = fetch_org_version
FileUtils.mkdir_p 'var/tmp'
- IO.write('var/tmp/last_org_version', @org_version)
+ File.write('var/tmp/last_org_version', @org_version)
@org_version
end
@@ -33,24 +44,29 @@ module Fronde
# existed already.
#
# @return [Integer] the length written (as returned by the
- # underlying ~IO.write~ method call)
+ # underlying ~File.write~ method call)
+ # rubocop:disable Metrics/MethodLength
def write_org_lisp_config(with_tags: false)
projects = org_generate_projects(with_tags: with_tags)
workdir = Dir.pwd
- content = IO.read(File.expand_path('./org-config.el', __dir__))
- .gsub('__VERSION__', Fronde::VERSION)
- .gsub('__WORK_DIR__', workdir)
- .gsub('__FRONDE_DIR__', __dir__)
- .gsub('__ORG_VER__', org_last_version)
- .gsub('__ALL_PROJECTS__', projects.values.join("\n "))
- .gsub('__THEME_CONFIG__', org_default_theme_config)
- .gsub('__ALL_PROJECTS_NAMES__', project_names(projects))
- .gsub('__LONG_DATE_FMT__', r18n_full_datetime_format)
- .gsub('__AUTHOR_EMAIL__', settings['author_email'] || '')
- .gsub('__AUTHOR_NAME__', settings['author'])
+ content = File.read(File.expand_path('./org-config.el', __dir__))
+ .gsub('__VERSION__', Fronde::VERSION)
+ .gsub('__WORK_DIR__', workdir)
+ .gsub('__FRONDE_DIR__', __dir__)
+ .gsub('__ORG_VER__', org_last_version)
+ .gsub(
+ '__ALL_PROJECTS__',
+ projects.values.join("\n ")
+ )
+ .gsub('__THEME_CONFIG__', org_default_theme_config)
+ .gsub('__ALL_PROJECTS_NAMES__', project_names(projects))
+ .gsub('__LONG_DATE_FMT__', r18n_full_datetime_format)
+ .gsub('__AUTHOR_EMAIL__', get('author_email', ''))
+ .gsub('__AUTHOR_NAME__', get('author'))
FileUtils.mkdir_p "#{workdir}/var/lib"
- IO.write("#{workdir}/var/lib/org-config.el", content)
+ File.write("#{workdir}/var/lib/org-config.el", content)
end
+ # rubocop:enable Metrics/MethodLength
# Generate emacs directory variables file.
#
@@ -59,11 +75,11 @@ module Fronde
# of this fronde instance.
#
# @return [Integer] the length written (as returned by the
- # underlying ~IO.write~ method call)
+ # underlying ~File.write~ method call)
def write_dir_locals
workdir = Dir.pwd
# rubocop:disable Layout/LineLength
- IO.write(
+ File.write(
"#{workdir}/.dir-locals.el",
"((org-mode . ((eval . (load-file \"#{workdir}/var/lib/org-config.el\")))))"
)
@@ -93,12 +109,10 @@ module Fronde
names = projects.keys.map do |p|
["\"#{p}\"", "\"#{p}-assets\""]
end.flatten
- unless settings['theme'] == 'default'
- names << "\"theme-#{settings['theme']}\""
- end
+ names << "\"theme-#{get('theme')}\"" unless get('theme') == 'default'
sources.each do |s|
# Default theme defined in settings is already included
- next unless s['theme'] && s['theme'] != settings['theme']
+ next unless s['theme'] && s['theme'] != get('theme')
# Never include theme named 'default' as it does not rely on any
# file to export.
next if s['theme'] == 'default'
@@ -118,9 +132,9 @@ module Fronde
def publication_path(project)
publish_in = [Dir.pwd]
if project['type'] == 'gemini'
- publish_in << (settings['gemini_public_folder'] || 'public_gmi')
+ publish_in << get('gemini_public_folder', 'public_gmi')
else
- publish_in << settings['public_folder']
+ publish_in << get('public_folder')
end
publish_in << project['target'] unless project['target'] == '.'
publish_in.join('/')
@@ -187,7 +201,7 @@ module Fronde
'html-head-include-default-style' => 't',
'html-head-include-scripts' => 't'
}
- curtheme = project['theme'] || settings['theme']
+ curtheme = project['theme'] || get('theme')
return defaults if curtheme.nil? || curtheme == 'default'
defaults['html-head'] = org_default_html_head
defaults['html-head-include-default-style'] = 'nil'
@@ -205,7 +219,7 @@ module Fronde
else
defaults.merge!(
org_default_html_options(project),
- settings['org-html'] || {},
+ get('org-html', {}),
project['org-html'] || {}
)
end
@@ -213,14 +227,14 @@ module Fronde
end
def expand_vars_in_html_head(head, project)
- curtheme = project['theme'] || settings['theme']
+ curtheme = project['theme'] || get('theme')
# Head may be frozen when coming from settings
head = head.gsub('__THEME__', curtheme)
- .gsub('__DOMAIN__', settings['domain'])
+ .gsub('__DOMAIN__', get('domain'))
return head.gsub('__ATOM_FEED__', '') unless project['is_blog']
atomfeed = <<~ATOMFEED
<link rel="alternate" type="application/atom+xml" title="Atom 1.0"
- href="#{settings['domain']}/feeds/index.xml" />
+ href="#{get('domain')}/feeds/index.xml" />
ATOMFEED
head.gsub('__ATOM_FEED__', atomfeed)
end
@@ -261,7 +275,7 @@ module Fronde
end
def org_default_theme_config
- theme_config = org_theme_config(settings['theme'])
+ theme_config = org_theme_config(get('theme'))
return theme_config if theme_config == ''
format("\n %<conf>s", conf: theme_config)
end
@@ -278,7 +292,7 @@ module Fronde
# rubocop:enable Layout/LineLength
' :recursive t',
format(' :publishing-directory "%<wd>s/%<pub>s/assets/%<theme>s"',
- wd: workdir, pub: settings['public_folder'], theme: theme),
+ wd: workdir, pub: get('public_folder'), theme: theme),
' :publishing-function org-publish-attachment)'
].join("\n ").strip
end
diff --git a/lib/fronde/emacs.rb b/lib/fronde/emacs.rb
index 9522a5c..9295a07 100644
--- a/lib/fronde/emacs.rb
+++ b/lib/fronde/emacs.rb
@@ -24,7 +24,7 @@ module Fronde
private
def emacs_command(*arguments)
- default_emacs = Fronde::Config.settings['emacs']
+ default_emacs = Fronde::Config.get('emacs')
emacs_cmd = [
default_emacs || 'emacs -Q --batch -nw',
'--eval \'(setq enable-dir-local-variables nil)\''
diff --git a/lib/fronde/index.rb b/lib/fronde/index.rb
index e7a349d..06fa9cc 100644
--- a/lib/fronde/index.rb
+++ b/lib/fronde/index.rb
@@ -17,7 +17,7 @@ module Fronde
include Fronde::IndexOrgGenerator
def initialize
- @pubdir = Fronde::Config.settings['public_folder']
+ @pubdir = Fronde::Config.get('public_folder')
@index = { 'index' => [] }
@projects = {}
@tags_names = {}
diff --git a/lib/fronde/index/atom_generator.rb b/lib/fronde/index/atom_generator.rb
index 2a47028..028189b 100644
--- a/lib/fronde/index/atom_generator.rb
+++ b/lib/fronde/index/atom_generator.rb
@@ -19,7 +19,7 @@ module Fronde
slug = Fronde::OrgFile.slug index_name
FileUtils.mkdir_p "#{@pubdir}/feeds"
atomdest = "#{@pubdir}/feeds/#{slug}.xml"
- IO.write(atomdest, to_atom(index_name))
+ File.write(atomdest, to_atom(index_name))
end
private
@@ -29,13 +29,12 @@ module Fronde
# @param title [String] the title of the current atom feed
# @return [String] the Atom header as a String
def atom_header(title)
- domain = Fronde::Config.settings['domain']
+ domain = Fronde::Config.get('domain')
upddate = @date.rfc3339
if title == 'index'
slug = 'index'
tagurl = domain
- title = Fronde::Config.settings['title'] || \
- R18n.t.fronde.index.all_tags
+ title = Fronde::Config.get('title', R18n.t.fronde.index.all_tags)
else
slug = Fronde::OrgFile.slug(title)
tagurl = "#{domain}/tags/#{slug}.html"
@@ -47,13 +46,13 @@ module Fronde
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
- xml:lang="#{Fronde::Config.settings['lang']}">
+ xml:lang="#{Fronde::Config.get('lang')}">
<title>#{title}</title>
<link href="#{domain}/feeds/#{slug}.xml" rel="self" type="application/atom+xml"/>
<link href="#{tagurl}" rel="alternate" type="text/html" title="#{title}"/>
<updated>#{upddate}</updated>
- <author><name>#{Fronde::Config.settings['author'] || ''}</name></author>
+ <author><name>#{Fronde::Config.get('author', '')}</name></author>
<id>urn:md5:#{Digest::MD5.hexdigest(domain)}</id>
<generator uri="https://git.umaneti.net/fronde/about/">Fronde</generator>
ENDATOM
diff --git a/lib/fronde/index/org_generator.rb b/lib/fronde/index/org_generator.rb
index 6818dd8..1d27a02 100644
--- a/lib/fronde/index/org_generator.rb
+++ b/lib/fronde/index/org_generator.rb
@@ -18,7 +18,7 @@ module Fronde
FileUtils.mkdir 'tags' unless Dir.exist? 'tags'
content = to_org index_name
orgdest = "tags/#{slug}.org"
- IO.write(orgdest, content)
+ File.write(orgdest, content)
end
private
@@ -37,7 +37,7 @@ module Fronde
next unless Dir.exist?(project['path'])
warn "Generated blog home for #{project['name']}" if verbose
orgdest = format('%<root>s/index.org', root: project['path'])
- IO.write(orgdest, to_org(project['name'], is_project: true))
+ File.write(orgdest, to_org(project['name'], is_project: true))
end
end
@@ -57,7 +57,7 @@ module Fronde
end
def tag_published_url(tag_name)
- domain = Fronde::Config.settings['domain']
+ domain = Fronde::Config.get('domain')
title = @tags_names[tag_name]
tag_link = "#{domain}/tags/#{tag_name}.html"
"[[#{tag_link}][#{title}]]"
@@ -67,12 +67,12 @@ module Fronde
if is_tag
title = @tags_names[title]
elsif title.nil? || title == 'index'
- title = Fronde::Config.settings['title']
+ title = Fronde::Config.get('title')
end
<<~HEADER.strip
#+title: #{title}
- #+author: #{Fronde::Config.settings['author']}
- #+language: #{Fronde::Config.settings['lang']}
+ #+author: #{Fronde::Config.get('author')}
+ #+language: #{Fronde::Config.get('lang')}
HEADER
end
diff --git a/lib/fronde/org_file.rb b/lib/fronde/org_file.rb
index f03e052..23a7d46 100644
--- a/lib/fronde/org_file.rb
+++ b/lib/fronde/org_file.rb
@@ -15,7 +15,7 @@ module Fronde
# This class is responsible for reading or writing existing or new org
# files, and formating their content to be used on the generated
# website.
- class OrgFile
+ class OrgFile # rubocop:disable Metrics/ClassLength
# @return [String] the title of the current org document, taken from
# the ~#+title:~ header.
attr_reader :title
@@ -240,7 +240,7 @@ module Fronde
.gsub('%k', @keywords.join(', '))
.gsub('%K', keywords_to_html)
.gsub('%l', @lang)
- .gsub('%L', (Fronde::Config.settings['license'] || '').gsub(/\s+/, ' ').strip)
+ .gsub('%L', Fronde::Config.get('license', '').gsub(/\s+/, ' ').strip)
.gsub('%n', "Fronde #{Fronde::VERSION}")
.gsub('%N', "<a href=\"https://git.umaneti.net/fronde/about/\">Fronde</a> #{Fronde::VERSION}")
.gsub('%s', @subtitle)
@@ -257,12 +257,12 @@ module Fronde
# The intermediate parent folders are created if necessary.
#
# @return [Integer] the length written (as returned by the
- # underlying ~IO.write~ method call)
+ # underlying ~File.write~ method call)
def write
raise TypeError, 'no conversion from nil file name to path.' if @file.nil?
file_dir = File.dirname @file
FileUtils.mkdir_p file_dir unless Dir.exist? file_dir
- IO.write @file, @content
+ File.write @file, @content
end
private
@@ -272,7 +272,7 @@ module Fronde
@html_file = Fronde::OrgFile.target_for_source(
@file, @project, with_public_folder: false
)
- @url = "#{Fronde::Config.settings['domain']}/#{@html_file}"
+ @url = "#{Fronde::Config.get('domain')}/#{@html_file}"
end
def init_empty_file
@@ -280,9 +280,9 @@ module Fronde
@subtitle = ''
@date = DateTime.now
@notime = false
- @author = @options[:author] || Fronde::Config.settings['author']
+ @author = @options[:author] || Fronde::Config.get('author')
@keywords = []
- @lang = @options[:lang] || Fronde::Config.settings['lang']
+ @lang = @options[:lang] || Fronde::Config.get('lang')
@excerpt = ''
body = @options[:content] || ''
@content = @options[:raw_content] || <<~ORG
diff --git a/lib/fronde/org_file/class_methods.rb b/lib/fronde/org_file/class_methods.rb
index a4e3f43..f62b734 100644
--- a/lib/fronde/org_file/class_methods.rb
+++ b/lib/fronde/org_file/class_methods.rb
@@ -6,7 +6,7 @@ module Fronde
def source_for_target(file_name)
# file_name may be frozen...
src = file_name.sub(/\.html\z/, '.org')
- pubfolder = Fronde::Config.settings['public_folder']
+ pubfolder = Fronde::Config.get('public_folder')
src.sub!(/^#{pubfolder}\//, '')
# Look for match in each possible sources. The first found wins.
Fronde::Config.sources.each do |project|
@@ -36,7 +36,7 @@ module Fronde
target = "#{project['target']}/#{target}" if project['target'] != '.'
end
return target unless with_public_folder
- pubfolder = Fronde::Config.settings['public_folder']
+ pubfolder = Fronde::Config.get('public_folder')
"#{pubfolder}/#{target}"
end
diff --git a/lib/fronde/org_file/extracter.rb b/lib/fronde/org_file/extracter.rb
index 05f211d..7f7b595 100644
--- a/lib/fronde/org_file/extracter.rb
+++ b/lib/fronde/org_file/extracter.rb
@@ -8,7 +8,7 @@ module Fronde
# Main method, which will call the other to initialize an
# {Fronde::OrgFile} instance.
def extract_data
- @content = IO.read @file
+ @content = File.read @file
@title = extract_title
@subtitle = extract_subtitle
@date = extract_date
@@ -49,7 +49,7 @@ module Fronde
def extract_author
m = /^#\+author:(.+)$/i.match(@content)
- return Fronde::Config.settings['author'] if m.nil?
+ return Fronde::Config.get('author') if m.nil?
m[1].strip
end
@@ -61,7 +61,7 @@ module Fronde
def extract_lang
m = /^#\+language:(.+)$/i.match(@content)
- return Fronde::Config.settings['lang'] if m.nil?
+ return Fronde::Config.get('lang') if m.nil?
m[1].strip
end
diff --git a/lib/fronde/org_file/htmlizer.rb b/lib/fronde/org_file/htmlizer.rb
index 953f120..296699e 100644
--- a/lib/fronde/org_file/htmlizer.rb
+++ b/lib/fronde/org_file/htmlizer.rb
@@ -13,7 +13,7 @@ module Fronde
#
# @return [String] the HTML keywords list
def keywords_to_html
- domain = Fronde::Config.settings['domain']
+ domain = Fronde::Config.get('domain')
klist = @keywords.map do |k|
<<~KEYWORDLINK
<li class="keyword">
diff --git a/lib/fronde/preview.rb b/lib/fronde/preview.rb
index 62a0110..4a1595d 100644
--- a/lib/fronde/preview.rb
+++ b/lib/fronde/preview.rb
@@ -19,9 +19,9 @@ module Fronde # rubocop:disable Style/Documentation
private
def local_path(requested_path)
- routes = Fronde::Config.settings.dig('preview', 'routes') || {}
+ routes = Fronde::Config.get(['preview', 'routes'], {})
return routes[requested_path] if routes.has_key? requested_path
- local_path = Fronde::Config.settings['public_folder'] + requested_path
+ local_path = Fronde::Config.get('public_folder') + requested_path
if File.directory? local_path
local_path = format(
'%<path>s/index.html', path: local_path.delete_suffix('/')
@@ -32,9 +32,9 @@ module Fronde # rubocop:disable Style/Documentation
end
def parse_body(local_path, local_host)
- body = IO.read local_path
+ body = File.read local_path
return body unless local_path.match?(/\.(?:ht|x)ml\z/)
- domain = Fronde::Config.settings['domain']
+ domain = Fronde::Config.get('domain')
return body if domain == ''
body.gsub(/"file:\/\//, format('"%<host>s', host: local_host))
.gsub(/"#{domain}/, format('"%<host>s', host: local_host))
@@ -45,7 +45,7 @@ module Fronde # rubocop:disable Style/Documentation
def start_preview
# Inspired by ruby un.rb library, which allows normally to start a
# webrick server in one line: ruby -run -e httpd public_html -p 5000
- port = Fronde::Config.settings.dig('preview', 'server_port') || 5000
+ port = Fronde::Config.get(['preview', 'server_port'], 5000)
s = WEBrick::HTTPServer.new(Port: port)
s.mount '/', Fronde::PreviewServlet
['TERM', 'QUIT', 'INT'].each { |sig| trap(sig, proc { s.shutdown }) }
diff --git a/lib/fronde/templater.rb b/lib/fronde/templater.rb
index 54da13b..17a7aea 100644
--- a/lib/fronde/templater.rb
+++ b/lib/fronde/templater.rb
@@ -52,7 +52,7 @@ module Fronde
private
def filter_templates(file_name)
- templates = Fronde::Config.settings['templates']
+ templates = Fronde::Config.get('templates')
return [] if templates.nil? || templates.empty?
templates.filter { |t| check_required_keys(t, file_name) }
end
@@ -71,7 +71,7 @@ module Fronde
end
def check_path(file_name, pathes)
- pub_folder = Fronde::Config.settings['public_folder']
+ pub_folder = Fronde::Config.get('public_folder')
if pathes.is_a?(Array)
pathes.each do |tp|
return true if File.fnmatch?("#{pub_folder}#{tp}",
diff --git a/lib/fronde/utils.rb b/lib/fronde/utils.rb
index d7ae6af..d630a42 100644
--- a/lib/fronde/utils.rb
+++ b/lib/fronde/utils.rb
@@ -7,6 +7,9 @@ require 'r18n-core'
require 'fronde/config'
module Fronde
+ # Default Error, which may be raised by fronde code
+ class Error < ::StandardError; end
+
# Embeds usefull methods, mainly used in rake tasks.
module Utils
# @return [Hash] the possible throbber themes
@@ -38,7 +41,8 @@ module Fronde
# configuration
FRONDE_COMMANDS = {
'init' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
- 'config' => { alias: 'init' },
+ 'update' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
+ 'config' => { alias: 'update' },
'preview' => { opts: ['-h'] },
'open' => { opts: ['-a', '-h', '-l', '-t', '-v'] },
'edit' => { alias: 'open' },
@@ -144,6 +148,17 @@ module Fronde
command
end
+ # Returns the given command options.
+ #
+ # This method will first try to resolve command alias, if any.
+ #
+ # @param command [String] the command, which options should be returned
+ # @return [Hash] the command options
+ def command_options(command)
+ cmd = resolve_possible_alias command
+ FRONDE_COMMANDS[cmd].merge(name: cmd)
+ end
+
# Try to discover the current host operating system.
#
# @return [String] either apple, windows or linux (default)
diff --git a/lib/fronde/version.rb b/lib/fronde/version.rb
index 36355dd..134cbe3 100644
--- a/lib/fronde/version.rb
+++ b/lib/fronde/version.rb
@@ -2,5 +2,5 @@
module Fronde
# @return [String] the version number of the current Fronde release.
- VERSION = '0.3.2'
+ VERSION = '0.3.3'
end
diff --git a/lib/tasks/org.rake b/lib/tasks/org.rake
index 56547d6..07827a4 100644
--- a/lib/tasks/org.rake
+++ b/lib/tasks/org.rake
@@ -12,12 +12,19 @@ CLOBBER.push(
'var/lib/org-config.el', '.dir-locals.el', 'lib/htmlize.el'
)
+def make_org_cmd(org_dir, target)
+ make = ['make', '-C', org_dir, target]
+ return make.join(' ') if verbose
+ make.insert(3, '-s')
+ make << 'EMACSQ="emacs -Q --eval \'(setq inhibit-message t)\'"'
+ make.join(' ')
+end
+
namespace :org do
directory 'var/tmp'
desc 'Download last version of Org'
file 'var/tmp/org.tar.gz' => 'var/tmp' do
- verbose = Rake::FileUtilsExt.verbose_flag
download = Thread.new do
Thread.current[:org_version] = Fronde::Config.org_last_version
Fronde::Utils.download_org
@@ -32,20 +39,14 @@ namespace :org do
desc 'Compile Org'
task compile: 'var/tmp/org.tar.gz' do |task|
- verbose = Rake::FileUtilsExt.verbose_flag
org_version = Fronde::Config.org_last_version
org_dir = "lib/org-#{org_version}"
next if Dir.exist?("#{org_dir}/lisp")
- make = ['make', '-C', org_dir]
- unless verbose
- make << '-s'
- make << 'EMACSQ="emacs -Q --eval \'(setq inhibit-message t)\'"'
- end
build = Thread.new do
sh "tar -C lib -xzf #{task.prerequisites[0]}"
mv "lib/org-mode-release_#{org_version}", org_dir
- sh((make + ['compile']).join(' '))
- sh((make + ['autoloads']).join(' '))
+ sh make_org_cmd(org_dir, 'compile')
+ sh make_org_cmd(org_dir, 'autoloads')
Dir.glob('lib/org-[0-9.]*').each do |ov|
next if ov == org_dir
rm_r ov
@@ -65,14 +66,14 @@ namespace :org do
htmlize = URI(
'https://raw.githubusercontent.com/hniksic/emacs-htmlize/master/htmlize.el'
).open.read
- IO.write 'lib/htmlize.el', htmlize
+ File.write 'lib/htmlize.el', htmlize
end
file 'lib/ox-gmi.el' => 'lib' do
ox_gmi = URI(
'https://git.umaneti.net/ox-gmi.el/plain/ox-gmi.el'
).open.read
- IO.write 'lib/ox-gmi.el', ox_gmi
+ File.write 'lib/ox-gmi.el', ox_gmi
end
file 'var/lib/org-config.el' => ['lib/htmlize.el', 'lib/ox-gmi.el'] do
@@ -85,7 +86,7 @@ namespace :org do
desc 'Install Org'
multitask install: ['org:compile', '.dir-locals.el'] do
- mkdir_p "#{Fronde::Config.settings['public_folder']}/assets"
+ mkdir_p "#{Fronde::Config.get('public_folder')}/assets"
Fronde::Config.sources.each do |s|
mkdir_p s['path'] unless Dir.exist? s['path']
end
diff --git a/lib/tasks/site.rake b/lib/tasks/site.rake
index 6027ef8..6c30b39 100644
--- a/lib/tasks/site.rake
+++ b/lib/tasks/site.rake
@@ -10,7 +10,6 @@ namespace :site do
desc 'Generates all index files'
task :index do
index = Fronde::Index.new
- verbose = Rake::FileUtilsExt.verbose_flag
if verbose
index.write_all
next
@@ -28,7 +27,7 @@ namespace :site do
args.with_defaults(:force? => false)
build_html = Thread.new do
rm_r 'var/tmp/timestamps', force: true if args[:force?]
- Fronde::Emacs.new(verbose: Rake::FileUtilsExt.verbose_flag).publish
+ Fronde::Emacs.new(verbose: verbose).publish
end
begin
Fronde::Utils.throbber(build_html, 'Building:')
@@ -39,7 +38,7 @@ namespace :site do
end
# :nocov:
customize_html = Thread.new do
- pubfolder = Fronde::Config.settings['public_folder']
+ pubfolder = Fronde::Config.get('public_folder')
Dir["#{pubfolder}/**/*.html"].each do |f|
Fronde::Templater.customize_output(f)
end
diff --git a/lib/tasks/sync.rake b/lib/tasks/sync.rake
index d3de6ab..74c3ce7 100644
--- a/lib/tasks/sync.rake
+++ b/lib/tasks/sync.rake
@@ -3,8 +3,12 @@
require 'fronde/config'
require 'fronde/utils'
-def rsync_command(verbose, test = nil)
- rsync_command = Fronde::Config.settings['rsync']
+module Fronde
+ class SyncError < Error; end
+end
+
+def rsync_command(test = nil)
+ rsync_command = Fronde::Config.get('rsync')
return rsync_command unless rsync_command.nil?
optstring = []
optstring << 'n' if test
@@ -16,19 +20,37 @@ def rsync_command(verbose, test = nil)
"rsync -#{optstring.join}rlt --delete"
end
+def pull_or_push(direction, label, test)
+ unless [:pull, :push].include? direction
+ raise Fronde::SyncError, 'Not a valid direction'
+ end
+ remote_path = Fronde::Config.get('remote')
+ raise Fronde::SyncError, 'No remote path set' if remote_path.nil?
+ public_folder = Fronde::Config.get('public_folder')
+ # Default is to push
+ cmd = ["#{public_folder}/", remote_path]
+ cmd.reverse! if direction == :pull
+ rsync = rsync_command(test)
+ publish_thread = Thread.new do
+ sh "#{rsync} #{cmd.join(' ')}"
+ end
+ Fronde::Utils.throbber(publish_thread, label)
+end
+
namespace :sync do
- desc 'Push change to server'
+ desc 'Push changes to server'
task :push, :test? do |_, args|
- remote_path = Fronde::Config.settings['remote']
- if remote_path.nil?
- warn 'No remote path set'
- next
- end
- public_folder = Fronde::Config.settings['public_folder']
- publish_thread = Thread.new do
- sh [rsync_command(Rake::FileUtilsExt.verbose_flag, args[:test?]),
- "#{public_folder}/", remote_path].join(' ')
- end
- Fronde::Utils.throbber(publish_thread, 'Publishing:')
+ pull_or_push(:push, 'Publishing:', args[:test?])
+ rescue Fronde::SyncError => e
+ warn e
+ next
+ end
+
+ desc 'Pull changes from server'
+ task :pull, :test? do |_, args|
+ pull_or_push(:pull, 'Pulling:', args[:test?])
+ rescue Fronde::SyncError => e
+ warn e
+ next
end
end
diff --git a/locales/en.yml b/locales/en.yml
index 39d33ca..6cb3310 100644
--- a/locales/en.yml
+++ b/locales/en.yml
@@ -6,6 +6,7 @@ fronde:
cmd_title: Commands
alias: Alias for %1.
init: Initialize your Fronde instance (you just need to do it once).
+ update: Update Fronde dependency (to be run once in a while).
preview: 'Start a test web server to preview your website on http://127.0.0.1:5000'
open: Open or create an org file.
build: Compile your org files to HTML.
diff --git a/locales/fr.yml b/locales/fr.yml
index 7c4047d..db6cd56 100644
--- a/locales/fr.yml
+++ b/locales/fr.yml
@@ -6,6 +6,7 @@ fronde:
cmd_title: Commandes
alias: Alias pour %1.
init: Initialise votre instance de Fronde (vous ne devriez faire cela qu'une fois).
+ update: Met à jour les dépendances de Fronde (à lancer une fois de temps à autre).
preview: "Démarre un serveur web de test pour prévisualiser votre site à l'adresse http://127.0.0.1:5000"
open: Ouvre ou crée un fichier org.
build: Compile vos fichiers org en HTML.
diff --git a/spec/data/index_proof.html b/spec/data/index_proof.html
index 84f0a38..af0afb1 100644
--- a/spec/data/index_proof.html
+++ b/spec/data/index_proof.html
@@ -9,10 +9,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="fronde-test" content="test">
<title>My website</title>
-<meta name="generator" content="Org mode">
<meta name="author" content="Tata">
-<style type="text/css">
- <!--/*--><![CDATA[/*><!--*/
+<meta name="generator" content="Org Mode">
+<style>
+ #content { max-width: 60em; margin: auto; }
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
@@ -33,8 +33,9 @@
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
- border: 1px solid #ccc;
- box-shadow: 3px 3px 3px #eee;
+ border: 1px solid #e6e6e6;
+ border-radius: 3px;
+ background-color: #f2f2f2;
padding: 8pt;
font-family: monospace;
overflow: auto;
@@ -43,21 +44,21 @@
pre.src {
position: relative;
overflow: auto;
- padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
- background-color: white;
- top: -10px;
- right: 10px;
+ top: -8px;
+ right: 12px;
padding: 3px;
- border: 1px solid black;
+ color: #555;
+ background-color: #f2f2f299;
}
pre.src:hover:before { display: inline; margin-top: 14px;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
+ pre.src-authinfo::before { content: 'Authinfo'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
@@ -192,12 +193,10 @@
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
- .org-svg { width: 90%; }
- /*]]>*/-->
+ .org-svg { }
</style>
-<script type="text/javascript">
+<script>
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&amp;dn=gpl-3.0.txt GPL-v3-or-Later
-<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
@@ -214,12 +213,11 @@
target.classList.remove("code-highlighted");
}
}
- /*]]>*///-->
// @license-end
</script>
</head>
<body>
-<div id="content">
+<div id="content" class="content">
<header>
<h1 class="title">My website</h1>
</header><p>
diff --git a/spec/fronde/config_spec.rb b/spec/fronde/config_spec.rb
index 41d76d3..98f4676 100644
--- a/spec/fronde/config_spec.rb
+++ b/spec/fronde/config_spec.rb
@@ -54,15 +54,13 @@ describe Fronde::Config do
context 'with a config file' do
before do
FileUtils.mkdir_p 'tmp/config'
- IO.write('tmp/config/config.yml', SAMPLE_CONFIG)
+ File.write('tmp/config/config.yml', SAMPLE_CONFIG)
Dir.chdir 'tmp/config'
- described_class.send(:load_settings)
+ described_class.reset
end
after do
- described_class.load_test({})
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/config'
+ tear_down 'tmp/config'
end
it 'parses it successfully' do
@@ -79,7 +77,7 @@ describe Fronde::Config do
it 'saves it successfully' do
described_class.save('author' => 'Titi', 'title' => 'Nevermind',
'domain' => 'https://tutu.com')
- expect(IO.read('config.yml')).to eq(SAMPLE_CONFIG_2)
+ expect(File.read('config.yml')).to eq(SAMPLE_CONFIG_2)
conf = described_class.settings
expect(conf['author']).to eq('Titi')
expect(conf['title']).to eq('Nevermind')
@@ -93,44 +91,43 @@ describe Fronde::Config do
before do
FileUtils.mkdir_p 'tmp/config'
Dir.chdir 'tmp/config'
- described_class.load_test({})
+ described_class.reset
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/config'
+ tear_down 'tmp/config'
end
it 'lists sources' do
- IO.write('config.yml', SAMPLE_CONFIG_3)
- described_class.send(:load_settings)
- expect(described_class.sources.length).to eq(2)
- expect(described_class.sources[0]['name']).to eq('src')
- expect(described_class.sources[0]['path']).to(
+ File.write('config.yml', SAMPLE_CONFIG_3)
+ projects = described_class.sources
+ expect(projects.length).to eq(2)
+ expect(projects[0]['name']).to eq('src')
+ expect(projects[0]['path']).to(
eq(File.expand_path('src'))
)
- expect(described_class.sources[0]['target']).to eq('src')
- expect(described_class.sources[0]['is_blog']).to be(false)
- expect(described_class.sources[0]['recursive']).to be(true)
- expect(described_class.sources[1]['name']).to eq('news')
- expect(described_class.sources[1]['path']).to(
+ expect(projects[0]['target']).to eq('src')
+ expect(projects[0]['is_blog']).to be(false)
+ expect(projects[0]['recursive']).to be(true)
+ expect(projects[1]['name']).to eq('news')
+ expect(projects[1]['path']).to(
eq(File.expand_path('src/news'))
)
- expect(described_class.sources[1]['target']).to eq('news')
- expect(described_class.sources[1]['is_blog']).to be(true)
- expect(described_class.sources[1]['recursive']).to be(true)
+ expect(projects[1]['target']).to eq('news')
+ expect(projects[1]['is_blog']).to be(true)
+ expect(projects[1]['recursive']).to be(true)
end
it 'generates projects hash' do
- IO.write('config.yml', SAMPLE_CONFIG_3)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_3)
+ described_class.reset
projects = described_class.send(:org_generate_projects)
expect(projects).to have_key('news')
end
it 'exposes correct head header' do
- IO.write('config.yml', SAMPLE_CONFIG_3)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_3)
+ described_class.reset
projects = described_class.sources
headers = described_class.send(:build_project_org_headers, projects[0])
head = <<~HEAD.strip
@@ -148,8 +145,8 @@ describe Fronde::Config do
end
it 'exposes correct head header with boolean values in conf' do
- IO.write('config.yml', SAMPLE_CONFIG_3)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_3)
+ described_class.reset
old_conf = described_class.settings.dup
old_conf['sources'][0] = {
'path' => 'src',
@@ -176,8 +173,8 @@ describe Fronde::Config do
end
it 'exposes correct head header with custom domain' do
- IO.write('config.yml', SAMPLE_CONFIG_4)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_4)
+ described_class.reset
projects = described_class.sources
headers = described_class.send(:build_project_org_headers, projects[0])
head = <<~HEAD.strip
@@ -213,8 +210,8 @@ describe Fronde::Config do
end
it 'exposes correct head header for gemini projects' do
- IO.write('config.yml', SAMPLE_CONFIG_3)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_3)
+ described_class.reset
old_conf = described_class.settings.dup
old_conf['sources'][0] = { 'path' => 'src', 'type' => 'gemini' }
described_class.load_test(old_conf)
@@ -230,8 +227,8 @@ describe Fronde::Config do
end
it 'generates projects' do
- IO.write('config.yml', SAMPLE_CONFIG_4)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_4)
+ described_class.reset
projects = described_class.send(:org_generate_projects)
srcconf = <<~SRCCONF.strip
("src"
@@ -298,8 +295,8 @@ describe Fronde::Config do
end
it 'generates gemini projects' do
- IO.write('config.yml', SAMPLE_CONFIG_4)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_4)
+ described_class.reset
old_conf = described_class.settings.dup
old_conf['sources'][0] = { 'path' => 'src', 'type' => 'gemini' }
described_class.load_test(old_conf)
@@ -327,8 +324,8 @@ describe Fronde::Config do
end
it 'generates projects names list' do
- IO.write('config.yml', SAMPLE_CONFIG_4)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_4)
+ described_class.reset
projects = described_class.send(:org_generate_projects)
expect(described_class.send(:project_names, projects)).to(
eq('"src" "src-assets" "news" "news-assets" "other" "other-assets" "theme-my-theme"')
@@ -336,8 +333,8 @@ describe Fronde::Config do
end
it 'generates projects names list without default' do
- IO.write('config.yml', SAMPLE_CONFIG_5)
- described_class.send(:load_settings)
+ File.write('config.yml', SAMPLE_CONFIG_5)
+ described_class.reset
projects = described_class.send(:org_generate_projects)
expect(described_class.send(:project_names, projects)).to(
eq('"src" "src-assets" "news" "news-assets" "theme-my-theme"')
@@ -349,13 +346,11 @@ describe Fronde::Config do
before do
FileUtils.mkdir_p 'tmp/config2'
Dir.chdir 'tmp/config2'
- described_class.send(:load_settings)
+ described_class.reset
end
after do
- described_class.load_test({})
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/config2'
+ tear_down 'tmp/config2'
end
it 'uses default config' do
@@ -381,7 +376,7 @@ describe Fronde::Config do
it 'gives current org version' do
described_class.class_eval '@org_version = nil', __FILE__, __LINE__
- IO.write('var/tmp/last_org_version', 'test')
+ File.write('var/tmp/last_org_version', 'test')
expect(described_class.org_last_version).to eq('test')
end
end
diff --git a/spec/fronde/index_spec.rb b/spec/fronde/index_spec.rb
index 89d19c9..9d2547e 100644
--- a/spec/fronde/index_spec.rb
+++ b/spec/fronde/index_spec.rb
@@ -149,18 +149,16 @@ describe Fronde::Index do
FileUtils.mkdir_p 'tmp/blog/writings/other'
FileUtils.mkdir_p 'tmp/blog/output'
FileUtils.cp(
- ['spec/data/test1.org',
- 'spec/data/test2.org'],
+ ['data/test1.org',
+ 'data/test2.org'],
'tmp/blog/writings'
)
- FileUtils.cp 'spec/data/test3.org', 'tmp/blog/writings/other'
+ FileUtils.cp 'data/test3.org', 'tmp/blog/writings/other'
Dir.chdir 'tmp/blog'
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/blog', force: true
- Fronde::Config.load_test({})
+ tear_down 'tmp/blog'
end
context 'with recursive config' do
@@ -248,26 +246,26 @@ describe Fronde::Index do
it 'correctly saves one index', core: true do
described_class.new.write_org('index')
expect(File.exist?('tags/index.org')).to be(true)
- expect(IO.read('tags/index.org')).to eq(SAMPLE_ALL_INDEX)
+ expect(File.read('tags/index.org')).to eq(SAMPLE_ALL_INDEX)
end
it 'correctly saves one blog index', core: true do
described_class.new.send(:write_all_blog_home, false)
expect(File.exist?('writings/index.org')).to be(true)
- expect(IO.read('writings/index.org')).to eq(SAMPLE_PROJECT_INDEX)
+ expect(File.read('writings/index.org')).to eq(SAMPLE_PROJECT_INDEX)
end
it 'correctly saves one blog index, even verbosely', core: true do
described_class.new.send(:write_all_blog_home, true)
expect(File.exist?('writings/index.org')).to be(true)
- expect(IO.read('writings/index.org')).to eq(SAMPLE_PROJECT_INDEX)
+ expect(File.read('writings/index.org')).to eq(SAMPLE_PROJECT_INDEX)
end
it 'correctly saves one atom feed', core: true do
index = described_class.new
index.write_atom('index')
expect(File.exist?('output/feeds/index.xml')).to be(true)
- expect(IO.read('output/feeds/index.xml')).to(
+ expect(File.read('output/feeds/index.xml')).to(
eq(format(SAMPLE_ATOM, date: index.date.rfc3339))
)
end
@@ -346,9 +344,7 @@ describe Fronde::Index do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/blog', force: true
- Fronde::Config.load_test({})
+ tear_down 'tmp/blog'
end
it 'has generated no index', core: true do
@@ -435,7 +431,7 @@ describe Fronde::Index do
:UNNUMBERED: notoc
:END:
INDEX
- expect(IO.read('tags/index.org')).to eq(empty_index)
+ expect(File.read('tags/index.org')).to eq(empty_index)
end
it 'correctly saves one blog index', core: true do
@@ -446,7 +442,7 @@ describe Fronde::Index do
#+author: Test
#+language: en
INDEX
- expect(IO.read('writings/index.org')).to eq(empty_project_index)
+ expect(File.read('writings/index.org')).to eq(empty_project_index)
end
it 'correctly saves one atom feed', core: true do
@@ -469,7 +465,7 @@ describe Fronde::Index do
<generator uri="https://git.umaneti.net/fronde/about/">Fronde</generator>
</feed>
ATOM
- expect(IO.read('output/feeds/index.xml')).to(
+ expect(File.read('output/feeds/index.xml')).to(
eq(format(empty_atom, date: index.date.rfc3339))
)
end
@@ -488,9 +484,9 @@ describe Fronde::Index do
FileUtils.mkdir_p 'tmp/txt/writings'
FileUtils.mkdir_p 'tmp/txt/output'
FileUtils.cp(
- ['spec/data/test1.org',
- 'spec/data/test2.org',
- 'spec/data/test3.org'],
+ ['data/test1.org',
+ 'data/test2.org',
+ 'data/test3.org'],
'tmp/txt/writings'
)
Dir.chdir 'tmp/txt'
@@ -504,9 +500,7 @@ describe Fronde::Index do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/txt', force: true
- Fronde::Config.load_test({})
+ tear_down 'tmp/txt'
end
it 'does not have generated any indexes', core: true do
@@ -589,7 +583,7 @@ describe Fronde::Index do
before do
FileUtils.mkdir_p 'tmp/txt/writings'
FileUtils.mkdir_p 'tmp/txt/output'
- FileUtils.cp 'spec/data/test1.org', 'tmp/txt/writings'
+ FileUtils.cp 'data/test1.org', 'tmp/txt/writings'
Dir.chdir 'tmp/txt'
Fronde::Config.load_test(
'public_folder' => 'output',
@@ -599,9 +593,7 @@ describe Fronde::Index do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/txt', force: true
- Fronde::Config.load_test({})
+ tear_down 'tmp/txt'
end
it 'does not have generated any indexes', core: true do
diff --git a/spec/fronde/org_file_spec.rb b/spec/fronde/org_file_spec.rb
index 9741129..1a2f0be 100644
--- a/spec/fronde/org_file_spec.rb
+++ b/spec/fronde/org_file_spec.rb
@@ -3,7 +3,7 @@
describe Fronde::OrgFile do
context 'with working org files' do
it 'parses without date', core: true do
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.title).to eq('My sweet article')
expect(o.date).to be_nil
expect(o.timekey).to eq('00000000000000')
@@ -11,7 +11,7 @@ describe Fronde::OrgFile do
end
it 'parses with a partial date', core: true do
- o = described_class.new('spec/data/test2.org')
+ o = described_class.new('data/test2.org')
expect(o.title).to eq('My second article')
expect(o.date).to eq(DateTime.strptime('2019-06-11 00:00:00', '%Y-%m-%d %H:%M:%S'))
expect(o.timekey).to eq('20190611000000')
@@ -21,7 +21,7 @@ describe Fronde::OrgFile do
end
it 'parses with a complete date', core: true do
- o = described_class.new('spec/data/test3.org')
+ o = described_class.new('data/test3.org')
expect(o.title).to eq('My third article')
expect(o.date).to eq(DateTime.strptime('2019-06-11 23:42:10', '%Y-%m-%d %H:%M:%S'))
expect(o.timekey).to eq('20190611234210')
@@ -30,7 +30,7 @@ describe Fronde::OrgFile do
end
it 'parses with a complete date, but partial time', core: true do
- o = described_class.new('spec/data/test4.org')
+ o = described_class.new('data/test4.org')
expect(o.title).to eq('Fourth test')
expect(o.date).to eq(DateTime.strptime('2019-07-25 20:45:00', '%Y-%m-%d %H:%M:%S'))
expect(o.timekey).to eq('20190725204500')
@@ -39,7 +39,7 @@ describe Fronde::OrgFile do
end
it 'finds a subtitle', core: true do
- o = described_class.new('spec/data/content.org')
+ o = described_class.new('data/content.org')
expect(o.title).to eq('My first blog post?')
expect(o.subtitle).to eq('What to do with that')
end
@@ -62,8 +62,7 @@ describe Fronde::OrgFile do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/org_test', force: true
+ tear_down 'tmp/org_test'
end
it 'raises if file_name is nil and try to write', core: true do
@@ -90,7 +89,7 @@ describe Fronde::OrgFile do
CONTENT
expect(File.exist?('__test__.org')).to be(true)
- expect(IO.read('__test__.org')).to eq(empty_content)
+ expect(File.read('__test__.org')).to eq(empty_content)
end
it 'creates new Org file, even in a new folder', core: true do
@@ -109,33 +108,32 @@ describe Fronde::OrgFile do
Lorem ipsum
CONTENT
- expect(IO.read('not/existing/test.org')).to eq(content)
+ expect(File.read('not/existing/test.org')).to eq(content)
end
end
context 'with configuration' do
- after do
- # Reset config
- Fronde::Config.load_test({})
+ before do
+ Fronde::Config.reset
end
it 'respects author name', core: true do
Fronde::Config.load_test('author' => 'Test')
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.author).to eq('Test')
- o = described_class.new('spec/data/test2.org')
+ o = described_class.new('data/test2.org')
expect(o.author).to eq('Titi')
- o = described_class.new('spec/data/test3.org')
+ o = described_class.new('data/test3.org')
expect(o.author).to eq('Test')
end
it 'computes the right html_file path for existing sources', core: true do
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.html_file).to eq('data/test1.html')
Fronde::Config.load_test('domain' => 'http://perdu.com')
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.html_file).to eq('data/test1.html')
- o = described_class.new('spec/data/content.org')
+ o = described_class.new('data/content.org')
expect(o.html_file).to eq('data/content.html')
# The following are weird tests. We begin to test theoric stuff here
Fronde::Config.load_test(
@@ -144,19 +142,19 @@ describe Fronde::OrgFile do
{ 'path' => 'data' }
]
)
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.html_file).to eq('data/test1.html')
- o = described_class.new('spec/data/content.org')
+ o = described_class.new('data/content.org')
expect(o.html_file).to eq('data/content.html')
end
it 'computes the right url for existing sources', core: true do
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.url).to eq('/data/test1.html')
Fronde::Config.load_test('domain' => 'http://perdu.com')
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.url).to eq('http://perdu.com/data/test1.html')
- o = described_class.new('spec/data/content.org')
+ o = described_class.new('data/content.org')
expect(o.url).to eq('http://perdu.com/data/content.html')
# The following are weird tests. We begin to test theoric stuff here
Fronde::Config.load_test(
@@ -165,9 +163,9 @@ describe Fronde::OrgFile do
{ 'path' => 'data' }
]
)
- o = described_class.new('spec/data/test1.org')
+ o = described_class.new('data/test1.org')
expect(o.url).to eq('http://perdu.com/data/test1.html')
- o = described_class.new('spec/data/content.org')
+ o = described_class.new('data/content.org')
expect(o.url).to eq('http://perdu.com/data/content.html')
end
@@ -217,7 +215,7 @@ describe Fronde::OrgFile do
FileUtils.mkdir_p 'tmp/test_target/src/blog/toto'
FileUtils.mkdir_p 'tmp/test_target/writings'
Dir.chdir 'tmp/test_target'
- IO.write 'src/test.org', 'Lorem ipsum.'
+ File.write 'src/test.org', 'Lorem ipsum.'
FileUtils.touch(
['src/blog/test.org', 'src/blog/toto/tata.org',
'src/blog/toto/content.org', 'writings/notes.org']
@@ -228,8 +226,7 @@ describe Fronde::OrgFile do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/test_target', force: true
+ tear_down 'tmp/test_target'
end
it 'uses file name as title when title is empty' do
diff --git a/spec/fronde/templater_spec.rb b/spec/fronde/templater_spec.rb
index 5580f5b..d3166c8 100644
--- a/spec/fronde/templater_spec.rb
+++ b/spec/fronde/templater_spec.rb
@@ -42,19 +42,18 @@ describe Fronde::Templater do
end
after do
- Dir.chdir File.expand_path('../..', __dir__)
- FileUtils.rm_r 'tmp/website_testing', force: true
+ tear_down 'tmp/website_testing'
end
context 'with a simple customization process' do
before do
FileUtils.mkdir 'public_html'
- IO.write('public_html/customize_test.html', html_base)
+ File.write('public_html/customize_test.html', html_base)
end
after do
FileUtils.rm_r ['public_html', 'src'], force: true
- Fronde::Config.load_test({})
+ Fronde::Config.reset
end
it 'customizes a given html file with simple template' do
@@ -79,7 +78,7 @@ describe Fronde::Templater do
</body>
</html>
RESULT
- expect(IO.read('public_html/customize_test.html')).to eq(local_result)
+ expect(File.read('public_html/customize_test.html')).to eq(local_result)
end
it 'customizes a given html file with a given org object' do
@@ -95,7 +94,7 @@ describe Fronde::Templater do
My website
ORG
FileUtils.mkdir 'src'
- IO.write('src/index.org', org_content)
+ File.write('src/index.org', org_content)
o = Fronde::OrgFile.new('src/index.org')
described_class.customize_output('public_html/customize_test.html', o)
local_result = <<~RESULT
@@ -112,7 +111,7 @@ describe Fronde::Templater do
</body>
</html>
RESULT
- expect(IO.read('public_html/customize_test.html')).to eq(local_result)
+ expect(File.read('public_html/customize_test.html')).to eq(local_result)
end
it 'customizes a given html file with before' do
@@ -124,7 +123,7 @@ describe Fronde::Templater do
]
)
described_class.customize_output('public_html/customize_test.html')
- expect(IO.read('public_html/customize_test.html')).to eq(result)
+ expect(File.read('public_html/customize_test.html')).to eq(result)
end
it 'customizes a given html file with after' do
@@ -150,7 +149,7 @@ describe Fronde::Templater do
</body>
</html>
RESULT
- expect(IO.read('public_html/customize_test.html')).to eq(local_result)
+ expect(File.read('public_html/customize_test.html')).to eq(local_result)
end
it 'customizes a given html file with replace content' do
@@ -175,7 +174,7 @@ describe Fronde::Templater do
</body>
</html>
RESULT
- expect(IO.read('public_html/customize_test.html')).to eq(local_result)
+ expect(File.read('public_html/customize_test.html')).to eq(local_result)
end
it 'customizes a given html file with previous comments in head' do
@@ -198,7 +197,7 @@ describe Fronde::Templater do
</body>
</html>
HTML
- IO.write('public_html/customize_test2.html', local_html_base)
+ File.write('public_html/customize_test2.html', local_html_base)
described_class.customize_output('public_html/customize_test2.html')
local_result = <<~RESULT
<!DOCTYPE html>
@@ -214,11 +213,11 @@ describe Fronde::Templater do
</body>
</html>
RESULT
- expect(IO.read('public_html/customize_test2.html')).to eq(local_result)
+ expect(File.read('public_html/customize_test2.html')).to eq(local_result)
end
it 'does not customize a given html file with wrong templates' do
- result = IO.read('public_html/customize_test.html')
+ result = File.read('public_html/customize_test.html')
Fronde::Config.load_test(
'templates' => [
{ 'type' => 'replace',
@@ -228,14 +227,14 @@ describe Fronde::Templater do
]
)
described_class.customize_output('public_html/customize_test.html')
- expect(IO.read('public_html/customize_test.html')).to eq(result)
+ expect(File.read('public_html/customize_test.html')).to eq(result)
end
it 'does not customize a given html file with no templates' do
- result = IO.read('public_html/customize_test.html')
+ result = File.read('public_html/customize_test.html')
Fronde::Config.load_test({})
described_class.customize_output('public_html/customize_test.html')
- expect(IO.read('public_html/customize_test.html')).to eq(result)
+ expect(File.read('public_html/customize_test.html')).to eq(result)
end
it 'moves elements around' do
@@ -253,7 +252,7 @@ describe Fronde::Templater do
</body>
</html>
HTML
- IO.write('public_html/customize_test.html', other_html_base)
+ File.write('public_html/customize_test.html', other_html_base)
Fronde::Config.load_test(
'templates' => [
{ 'type' => 'before',
@@ -278,15 +277,15 @@ describe Fronde::Templater do
</body>
</html>
HTML
- expect(IO.read('public_html/customize_test.html')).to eq(result)
+ expect(File.read('public_html/customize_test.html')).to eq(result)
end
end
context 'with multiple customize call' do
before do
FileUtils.mkdir_p 'public_html/customize'
- IO.write('public_html/customize_test.html', html_base)
- IO.write('public_html/customize/test.html', html_base)
+ File.write('public_html/customize_test.html', html_base)
+ File.write('public_html/customize/test.html', html_base)
Fronde::Config.load_test(
'templates' => [
{ 'selector' => 'title',
@@ -299,30 +298,30 @@ describe Fronde::Templater do
after do
FileUtils.rm_r 'public_html', force: true
- Fronde::Config.load_test({})
+ Fronde::Config.reset
end
it 'customizes a file on a specific path' do
described_class.customize_output('public_html/customize_test.html')
- expect(IO.read('public_html/customize_test.html')).to eq(html_base)
+ expect(File.read('public_html/customize_test.html')).to eq(html_base)
described_class.customize_output('public_html/customize/test.html')
- expect(IO.read('public_html/customize/test.html')).to eq(result)
+ expect(File.read('public_html/customize/test.html')).to eq(result)
end
it 'does not customize twice a file' do
described_class.customize_output('public_html/customize/test.html')
- expect(IO.read('public_html/customize/test.html')).to eq(result)
+ expect(File.read('public_html/customize/test.html')).to eq(result)
described_class.customize_output('public_html/customize/test.html')
- expect(IO.read('public_html/customize/test.html')).to eq(result)
+ expect(File.read('public_html/customize/test.html')).to eq(result)
end
end
context 'with multiple path to customize' do
before do
FileUtils.mkdir_p ['public_html/customize', 'public_html/other']
- IO.write('public_html/customize_test.html', html_base)
- IO.write('public_html/customize/test.html', html_base)
- IO.write('public_html/other/file.html', html_base)
+ File.write('public_html/customize_test.html', html_base)
+ File.write('public_html/customize/test.html', html_base)
+ File.write('public_html/other/file.html', html_base)
Fronde::Config.load_test(
'templates' => [
{ 'selector' => 'title',
@@ -337,16 +336,16 @@ describe Fronde::Templater do
after do
FileUtils.rm_r 'public_html', force: true
- Fronde::Config.load_test({})
+ Fronde::Config.reset
end
it 'customizes a file on a specific path' do
described_class.customize_output('public_html/customize_test.html')
- expect(IO.read('public_html/customize_test.html')).to eq(html_base)
+ expect(File.read('public_html/customize_test.html')).to eq(html_base)
described_class.customize_output('public_html/customize/test.html')
- expect(IO.read('public_html/customize/test.html')).to eq(result)
+ expect(File.read('public_html/customize/test.html')).to eq(result)
described_class.customize_output('public_html/other/file.html')
- expect(IO.read('public_html/other/file.html')).to eq(result)
+ expect(File.read('public_html/other/file.html')).to eq(result)
end
end
end
diff --git a/spec/fronde/utils_spec.rb b/spec/fronde/utils_spec.rb
index c7a6def..993d841 100644
--- a/spec/fronde/utils_spec.rb
+++ b/spec/fronde/utils_spec.rb
@@ -38,7 +38,8 @@ describe Fronde::Utils do
it 'lists possible commands' do
basic_cmd = [
" init Initialize your Fronde instance (you just need to do it once).\n",
- " config Alias for init.\n",
+ " update Update Fronde dependency (to be run once in a while).\n",
+ " config Alias for update.\n",
" preview Start a test web server to preview your website on http://127.0.0.1:5000\n",
" open Open or create an org file.\n",
" edit Alias for open.\n",
@@ -51,19 +52,35 @@ describe Fronde::Utils do
it 'resolves alias' do
expect(described_class.resolve_possible_alias('init')).to eq('init')
- expect(described_class.resolve_possible_alias('config')).to eq('init')
+ expect(described_class.resolve_possible_alias('update')).to eq('update')
+ expect(described_class.resolve_possible_alias('config')).to eq('update')
expect(described_class.resolve_possible_alias('build')).to eq('build')
expect(described_class.resolve_possible_alias('edit')).to eq('open')
expect(described_class.resolve_possible_alias('wrong')).to eq('basic')
end
+ it 'returns possible options for a command' do
+ init_opts = described_class.command_options('init')
+ expect(init_opts).to have_key(:name)
+ expect(init_opts[:name]).to eq('init')
+ expect(init_opts).to have_key(:opts)
+ expect(init_opts[:opts]).to contain_exactly('-a', '-h', '-l', '-t', '-v')
+ expect(init_opts).not_to have_key(:alias)
+
+ config_opts = described_class.command_options('config')
+ expect(config_opts).to have_key(:name)
+ expect(config_opts[:name]).to eq('update')
+ expect(config_opts).to have_key(:opts)
+ expect(config_opts[:opts]).to contain_exactly('-a', '-h', '-l', '-t', '-v')
+ expect(config_opts).not_to have_key(:alias)
+ end
+
context 'with config' do
- after do
- Fronde::Config.load_test({})
+ before do
+ Fronde::Config.reset
end
it 'selects the right throbber' do
- Fronde::Config.load_test({})
frames = described_class.send(:select_throbber_frames)
expect(frames).to(
eq(['⠁ ⠂ ⠄ ⡀ ⠄ ⠂ ⠁', '⠂ ⠁ ⠂ ⠄ ⡀ ⠄ ⠂', '⠄ ⠂ ⠁ ⠂ ⠄ ⡀ ⠄',
diff --git a/spec/rake_org_spec.rb b/spec/rake_org_spec.rb
index cbf78e7..3c682ef 100644
--- a/spec/rake_org_spec.rb
+++ b/spec/rake_org_spec.rb
@@ -6,16 +6,14 @@ context 'with working org files' do
let(:org_dir) { "lib/org-#{Fronde::Config.org_last_version}" }
before do
+ Fronde::Config.reset
init_testing_website
- Fronde::Config.send(:load_settings)
end
after do
Dir.glob('lib/org-[0-9.]*').each { |ov| FileUtils.rm_r(ov, force: true) }
FileUtils.rm ['.dir-locals.el', 'var/lib/org-config.el'], force: true
- Fronde::Config.load_test({})
- Dir.chdir File.expand_path('..', __dir__)
- FileUtils.rm_r 'tmp/website_testing', force: true
+ tear_down 'tmp/website_testing'
end
it 'compiles org-config.el', rake: true do
@@ -23,12 +21,12 @@ context 'with working org files' do
expect(File.exist?('var/lib/org-config.el')).to be(true)
proof = File.expand_path('data/org-config-proof.el', __dir__)
base_dir = File.expand_path('../', __dir__)
- proof_content = IO.read(proof)
- .gsub(/__TEST_DIR__/, Dir.pwd)
- .gsub(/__BASE_DIR__/, base_dir)
- .gsub(/__VERSION__/, Fronde::VERSION)
- .gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
- expect(IO.read('var/lib/org-config.el')).to eq(proof_content)
+ proof_content = File.read(proof)
+ .gsub(/__TEST_DIR__/, Dir.pwd)
+ .gsub(/__BASE_DIR__/, base_dir)
+ .gsub(/__VERSION__/, Fronde::VERSION)
+ .gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
+ expect(File.read('var/lib/org-config.el')).to eq(proof_content)
end
it 'compiles org-config.el for blog', rake: true do
@@ -39,19 +37,19 @@ context 'with working org files' do
expect(File.exist?('var/lib/org-config.el')).to be(true)
proof = File.expand_path('data/org-config-blog-proof.el', __dir__)
base_dir = File.expand_path('../', __dir__)
- proof_content = IO.read(proof)
- .gsub(/__TEST_DIR__/, Dir.pwd)
- .gsub(/__BASE_DIR__/, base_dir)
- .gsub(/__VERSION__/, Fronde::VERSION)
- .gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
- expect(IO.read('var/lib/org-config.el')).to eq(proof_content)
+ proof_content = File.read(proof)
+ .gsub(/__TEST_DIR__/, Dir.pwd)
+ .gsub(/__BASE_DIR__/, base_dir)
+ .gsub(/__VERSION__/, Fronde::VERSION)
+ .gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
+ expect(File.read('var/lib/org-config.el')).to eq(proof_content)
end
it 'creates .dir-locals.el', rake: true do
rake.invoke_task('.dir-locals.el')
expect(File.exist?('.dir-locals.el')).to be(true)
proof = File.expand_path('var/lib/org-config.el', Dir.pwd)
- expect(IO.read('.dir-locals.el')).to(
+ expect(File.read('.dir-locals.el')).to(
eq("((org-mode . ((eval . (load-file \"#{proof}\")))))")
)
end
@@ -65,8 +63,6 @@ context 'with working org files' do
end
it 'installs Org in verbose mode', rake: true do
- # This one is mainly for coverage
- FileUtils.rm_r org_dir, force: true
copy_org_tarball_to_fake_tmp
rake(verbose: true).invoke_task('org:install')
expect(File.exist?('var/lib/org-config.el')).to be(true)
diff --git a/spec/rake_preview_spec.rb b/spec/rake_preview_spec.rb
index e2bcadd..8756646 100644
--- a/spec/rake_preview_spec.rb
+++ b/spec/rake_preview_spec.rb
@@ -6,7 +6,7 @@ require 'net/http'
def init_preview
copy_org_tarball_to_fake_tmp
- Fronde::Config.send(:load_settings)
+ Fronde::Config.reset
rake.invoke_task('org:install')
FileUtils.cp(
File.expand_path('../tigre.png', __dir__),
@@ -26,6 +26,10 @@ end
context 'when trying preview mode' do
let(:now_str) { DateTime.now.strftime('%A %-d of %B, %Y at %R') }
+ after do
+ tear_down 'tmp/website_testing'
+ end
+
context 'without a domain name' do
around do |test|
init_testing_website
@@ -42,15 +46,10 @@ context 'when trying preview mode' do
webrick_app.join # Be patient before quitting example
end
- after do
- Dir.chdir File.expand_path('..', __dir__)
- FileUtils.rm_r 'tmp/website_testing', force: true
- end
-
it 'is viewable with preview', rake: true do
home_page = URI('http://localhost:5000/index.html').open.read
proof = File.expand_path('data/index_proof.html', __dir__)
- proof_content = IO.read(proof).gsub(/__PUB_DATE__/, now_str)
+ proof_content = File.read(proof).gsub(/__PUB_DATE__/, now_str)
expect(home_page).to eq(proof_content)
tigre = URI('http://localhost:5000/tigre.png')
res = Net::HTTP.get_response(tigre)
@@ -62,14 +61,14 @@ context 'when trying preview mode' do
it 'serves index', rake: true do
home_page = URI('http://localhost:5000/').open.read
proof = File.expand_path('data/index_proof.html', __dir__)
- proof_content = IO.read(proof).gsub(/__PUB_DATE__/, now_str)
+ proof_content = File.read(proof).gsub(/__PUB_DATE__/, now_str)
expect(home_page).to eq(proof_content)
end
it 'is viewable with routes testing', rake: true do
home_page = URI('http://localhost:5000/test').open.read
proof = File.expand_path('data/index_proof.html', __dir__)
- proof_content = IO.read(proof).gsub(/__PUB_DATE__/, now_str)
+ proof_content = File.read(proof).gsub(/__PUB_DATE__/, now_str)
expect(home_page).to eq(proof_content)
end
@@ -97,15 +96,10 @@ context 'when trying preview mode' do
webrick_app.join
end
- after do
- Dir.chdir File.expand_path('..', __dir__)
- FileUtils.rm_r 'tmp/website_testing', force: true
- end
-
it 'replaces domain occurence by localhost URIs', rake: true do
home_page = URI('http://localhost:5000/index.html').open.read
proof = File.expand_path('data/index_proof.html', __dir__)
- proof_content = IO.read(proof).gsub(/__PUB_DATE__/, now_str)
+ proof_content = File.read(proof).gsub(/__PUB_DATE__/, now_str)
proof_content.gsub!(/mydomain\.local/, 'localhost:5000')
expect(home_page).to eq(proof_content)
end
diff --git a/spec/rake_site_spec.rb b/spec/rake_site_spec.rb
index 15dfaad..2b15251 100644
--- a/spec/rake_site_spec.rb
+++ b/spec/rake_site_spec.rb
@@ -9,34 +9,33 @@ def write_base_files
My website
ORG
- IO.write('src/index.org', org_content)
+ File.write('src/index.org', org_content)
file1 = <<~ORG
#+title: Index file
#+keywords: toto, titi
My website
ORG
- IO.write('src/news/test1.org', file1)
+ File.write('src/news/test1.org', file1)
file2 = <<~ORG
#+title: Index file
#+keywords: toto
My website
ORG
- IO.write('src/news/test2.org', file2)
+ File.write('src/news/test2.org', file2)
end
context 'with a testing website' do
before do
+ Fronde::Config.reset
init_testing_website
copy_org_tarball_to_fake_tmp
- Fronde::Config.send(:load_settings)
rake.invoke_task('org:install')
end
after do
- Dir.chdir File.expand_path('..', __dir__)
- FileUtils.rm_r 'tmp/website_testing', force: true
+ tear_down 'tmp/website_testing'
end
context 'when building org files' do
@@ -59,22 +58,22 @@ context 'with a testing website' do
it 'does not build again with successive call', rake: true do
rake(verbose: false).invoke_task('site:build')
- old_content = IO.read('public_html/index.html')
+ old_content = File.read('public_html/index.html')
old_conf = Fronde::Config.settings.dup
old_conf['org-html']['html-postamble'] = '<footer>Modified!</footer>'
Fronde::Config.load_test(old_conf)
rake(verbose: false).invoke_task('site:build')
- expect(IO.read('public_html/index.html')).to eql(old_content)
+ expect(File.read('public_html/index.html')).to eql(old_content)
end
it 'builds again when call with force option', rake: true do
rake(verbose: false).invoke_task('site:build')
- old_content = IO.read('public_html/index.html')
+ old_content = File.read('public_html/index.html')
old_conf = Fronde::Config.settings.dup
old_conf['org-html']['html-postamble'] = '<footer>Modified!</footer>'
Fronde::Config.load_test(old_conf)
rake(verbose: false).invoke_task('site:build[true]')
- expect(IO.read('public_html/index.html')).not_to eql(old_content)
+ expect(File.read('public_html/index.html')).not_to eql(old_content)
end
it 'fails gracefully when something goes wrong', rake: true do
diff --git a/spec/requirements.rb b/spec/requirements.rb
index 112074e..46ef06a 100644
--- a/spec/requirements.rb
+++ b/spec/requirements.rb
@@ -31,21 +31,23 @@ ENV['USER'] = 'alice'
def init_testing_website
FileUtils.mkdir_p 'tmp/website_testing'
Dir.chdir 'tmp/website_testing'
+ # Full path is now spec/tmp/website_testing
+ # Thus we have to rewind 3 level to find fronde src directory
rakefile = <<~RAKE
# frozen_string_literal: true
require 'r18n-core'
- R18n.default_places = '../../locales'
+ R18n.default_places = '../../../locales'
R18n.set 'en'
R18n::Filters.on(:named_variables)
- $LOAD_PATH.unshift('../../lib')
+ $LOAD_PATH.unshift('../../../lib')
- Dir.glob('../../lib/tasks/*.rake').each { |r| import r }
+ Dir.glob('../../../lib/tasks/*.rake').each { |r| import r }
task default: 'site:build'
RAKE
- IO.write('Rakefile', rakefile)
+ File.write('Rakefile', rakefile)
config = <<~CONF
---
author: Tata
@@ -73,12 +75,12 @@ def init_testing_website
routes:
/test: public_html/index.html
CONF
- IO.write('config.yml', config)
+ File.write('config.yml', config)
end
# rubocop:enable Metrics/MethodLength
def copy_org_tarball_to_fake_tmp
- tarball = File.expand_path('../tmp/org.tar.gz', __dir__)
+ tarball = File.expand_path('tmp/org.tar.gz', __dir__)
FileUtils.mkdir_p 'var/tmp'
FileUtils.cp tarball, 'var/tmp'
end
@@ -92,13 +94,20 @@ def rake(verbose: false)
rake
end
+def tear_down(path)
+ Dir.chdir __dir__
+ FileUtils.rm_r path, force: true
+end
+
RSpec.configure do |config|
config.before(:suite) do
+ Dir.chdir __dir__
FileUtils.mkdir 'tmp'
Fronde::Utils.download_org('tmp')
end
config.after(:suite) do
+ Dir.chdir __dir__
FileUtils.rm_r ['tmp', 'var'], force: true
end
end