aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-11-07 17:39:29 +0100
committerGravatar √Čtienne Deparis 2020-11-07 18:06:12 +0100
commite7358988d49494a56b6a32befce0e876a0eb267f (patch)
tree66bc3be708cc0b0bb6955c64921f5ec0910139f1
parent9bd534750cbdc99191adba4a30f37b6cf6583198 (diff)
downloadfronde-e7358988d49494a56b6a32befce0e876a0eb267f.tar.gz
fronde-e7358988d49494a56b6a32befce0e876a0eb267f.tar.xz
fronde-e7358988d49494a56b6a32befce0e876a0eb267f.zip
feat: Allow raw boolean values to be used in config file
-rw-r--r--lib/fronde/config/lisp_config.rb12
-rw-r--r--spec/fronde/config_spec.rb28
2 files changed, 37 insertions, 3 deletions
diff --git a/lib/fronde/config/lisp_config.rb b/lib/fronde/config/lisp_config.rb
index b4e4ad7..2acbef0 100644
--- a/lib/fronde/config/lisp_config.rb
+++ b/lib/fronde/config/lisp_config.rb
@@ -202,16 +202,22 @@ module Fronde
head.gsub('__ATOM_FEED__', atomfeed)
end
+ def cast_lisp_value(value)
+ return 't' if value.is_a?(TrueClass)
+ return 'nil' if value.nil? || value.is_a?(FalseClass)
+ value.strip.gsub(/"/, '\"')
+ end
+
def build_project_org_headers(project)
orgtplopts = org_default_html_options(project).merge(
settings['org-html'] || {}, project['org-html'] || {}
)
orgtpl = []
- truthy_val = ['t', 'nil', '1'].freeze
+ lisp_keywords = ['t', 'nil', '1', '-1', '0'].freeze
orgtplopts.each do |k, v|
v = expand_vars_in_html_head(v, project) if k == 'html-head'
- val = v.strip.gsub(/"/, '\"')
- if truthy_val.include? val
+ val = cast_lisp_value(v)
+ if lisp_keywords.include? val
orgtpl << ":#{k} #{val}"
else
orgtpl << ":#{k} \"#{val}\""
diff --git a/spec/fronde/config_spec.rb b/spec/fronde/config_spec.rb
index 18c521c..b698530 100644
--- a/spec/fronde/config_spec.rb
+++ b/spec/fronde/config_spec.rb
@@ -147,6 +147,34 @@ describe Fronde::Config do
expect(headers).to eq(head)
end
+ it 'exposes correct head header with boolean values in conf' do
+ IO.write('config.yml', SAMPLE_CONFIG_3)
+ described_class.send(:load_settings)
+ old_conf = described_class.settings.dup
+ old_conf['sources'][0] = {
+ 'path' => 'src',
+ 'org-html' => {
+ 'html-head-include-default-style' => true,
+ 'html-head-include-scripts' => false
+ }
+ }
+ described_class.load_test(old_conf)
+ projects = described_class.sources
+ headers = described_class.send(:build_project_org_headers, projects[0])
+ head = <<~HEAD.strip
+ :section-numbers nil
+ :with-toc nil
+ :html-postamble "<p><span class=\\\"author\\\">Written by %a</span>
+ with %c, and published with %N</p>
+ <p class=\\\"date\\\">Last modification on %C</p>
+ <p class=\\\"validation\\\">%v</p>"
+ :html-head ""
+ :html-head-include-default-style t
+ :html-head-include-scripts nil
+ HEAD
+ expect(headers).to eq(head)
+ end
+
it 'exposes correct head header with custom domain' do
IO.write('config.yml', SAMPLE_CONFIG_4)
described_class.send(:load_settings)