aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-11-07 21:21:02 +0100
committerGravatar √Čtienne Deparis 2020-11-07 22:30:25 +0100
commitedcdd89acf37f14e7ac97ef206ad9e37b98541c7 (patch)
treefb227ff81b2d2d84e429e83f1b6ed28e93282cb9
parent71e31841e8afe85b54d5bbad2f6cd80003767904 (diff)
downloadfronde-edcdd89acf37f14e7ac97ef206ad9e37b98541c7.tar.gz
fronde-edcdd89acf37f14e7ac97ef206ad9e37b98541c7.tar.xz
fronde-edcdd89acf37f14e7ac97ef206ad9e37b98541c7.zip
refactor: Try to mimick the FHS to store required deps and gen. files
-rw-r--r--lib/fronde/config/lisp_config.rb15
-rw-r--r--lib/fronde/config/org-config.el4
-rw-r--r--lib/fronde/config/ox-fronde.el2
-rw-r--r--lib/fronde/emacs.rb2
-rw-r--r--lib/fronde/utils.rb5
-rw-r--r--lib/tasks/org.rake35
-rw-r--r--lib/tasks/site.rake4
-rw-r--r--spec/data/org-config-blog-proof.el4
-rw-r--r--spec/data/org-config-proof.el4
-rw-r--r--spec/fronde/config_spec.rb4
-rw-r--r--spec/rake_org_spec.rb30
-rw-r--r--spec/requirements.rb9
12 files changed, 64 insertions, 54 deletions
diff --git a/lib/fronde/config/lisp_config.rb b/lib/fronde/config/lisp_config.rb
index 2acbef0..b2855ed 100644
--- a/lib/fronde/config/lisp_config.rb
+++ b/lib/fronde/config/lisp_config.rb
@@ -13,16 +13,16 @@ module Fronde
# @return [String] the new x.x.x version string of Org
def org_last_version
return @org_version if @org_version
- if File.exist?('tmp/__last_org_version__')
- @org_version = IO.read('tmp/__last_org_version__')
+ if File.exist?('var/tmp/last_org_version')
+ @org_version = IO.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']
- FileUtils.mkdir_p 'tmp'
- IO.write('tmp/__last_org_version__', @org_version)
+ FileUtils.mkdir_p 'var/tmp'
+ IO.write('var/tmp/last_org_version', @org_version)
@org_version
end
@@ -48,7 +48,8 @@ module Fronde
.gsub('__LONG_DATE_FMT__', r18n_full_datetime_format)
.gsub('__AUTHOR_EMAIL__', settings['author_email'] || '')
.gsub('__AUTHOR_NAME__', settings['author'])
- IO.write("#{workdir}/org-config.el", content)
+ FileUtils.mkdir_p "#{workdir}/var/lib"
+ IO.write("#{workdir}/var/lib/org-config.el", content)
end
# Generate emacs directory variables file.
@@ -61,10 +62,12 @@ module Fronde
# underlying ~IO.write~ method call)
def write_dir_locals
workdir = Dir.pwd
+ # rubocop:disable Layout/LineLength
IO.write(
"#{workdir}/.dir-locals.el",
- "((org-mode . ((eval . (load-file \"#{workdir}/org-config.el\")))))"
+ "((org-mode . ((eval . (load-file \"#{workdir}/var/lib/org-config.el\")))))"
)
+ # rubocop:enable Layout/LineLength
end
private
diff --git a/lib/fronde/config/org-config.el b/lib/fronde/config/org-config.el
index 345f2cd..a4e20d0 100644
--- a/lib/fronde/config/org-config.el
+++ b/lib/fronde/config/org-config.el
@@ -1,7 +1,7 @@
;; Add org-mode to load path
-(add-to-list 'load-path (expand-file-name "org-__ORG_VER__/lisp" "__WORK_DIR__"))
+(add-to-list 'load-path (expand-file-name "org-__ORG_VER__/lisp" "__WORK_DIR__/lib"))
;; Load last version of htmlize.el
-(load-file (expand-file-name "htmlize.el" "__WORK_DIR__"))
+(load-file (expand-file-name "htmlize.el" "__WORK_DIR__/lib"))
;; Current project options
(setq fronde/version "__VERSION__"
diff --git a/lib/fronde/config/ox-fronde.el b/lib/fronde/config/ox-fronde.el
index 03dac14..0a2842a 100644
--- a/lib/fronde/config/ox-fronde.el
+++ b/lib/fronde/config/ox-fronde.el
@@ -91,7 +91,7 @@ INFO is a plist used as a communication channel."
;;; Set configuration options
-(setq fronde/org-temp-dir (expand-file-name "tmp" fronde/current-work-dir)
+(setq fronde/org-temp-dir (expand-file-name "var/tmp" fronde/current-work-dir)
org-publish-timestamp-directory (expand-file-name "timestamps/" fronde/org-temp-dir)
org-id-locations-file (expand-file-name "id-locations.el" fronde/org-temp-dir)
make-backup-files nil
diff --git a/lib/fronde/emacs.rb b/lib/fronde/emacs.rb
index 63848e9..9522a5c 100644
--- a/lib/fronde/emacs.rb
+++ b/lib/fronde/emacs.rb
@@ -12,7 +12,7 @@ module Fronde
def publish
command = emacs_command(
- '-l ./org-config.el', '--eval \'(org-publish "website")\''
+ '-l ./var/lib/org-config.el', '--eval \'(org-publish "website")\''
)
if @verbose
warn command
diff --git a/lib/fronde/utils.rb b/lib/fronde/utils.rb
index c9a5bc5..aa73ec2 100644
--- a/lib/fronde/utils.rb
+++ b/lib/fronde/utils.rb
@@ -160,15 +160,16 @@ module Fronde
# Download latest org-mode tarball.
#
+ # @param destination [String] where to save the org-mode tarball
# @return [String] the downloaded org-mode version
- def download_org
+ def download_org(destination = 'var/tmp')
# :nocov:
return if Fronde::Config.org_last_version.nil?
# :nocov:
tarball = "org-#{Fronde::Config.org_last_version}.tar.gz"
# Remove version number in dest file to allow easy rake file
# task naming
- dest_file = 'tmp/org.tar.gz'
+ dest_file = File.expand_path('org.tar.gz', destination)
return if File.exist?(dest_file)
uri = URI("https://orgmode.org/#{tarball}")
# Will crash on purpose if anything goes wrong
diff --git a/lib/tasks/org.rake b/lib/tasks/org.rake
index a3adf5a..fa1db36 100644
--- a/lib/tasks/org.rake
+++ b/lib/tasks/org.rake
@@ -8,13 +8,15 @@ require 'fronde/utils'
require 'rake/clean'
CLOBBER.push(
- 'tmp/org.tar.gz', 'tmp/__last_org_version__',
- 'org-config.el', '.dir-locals.el', 'htmlize.el'
+ 'var/tmp/org.tar.gz', 'var/tmp/last_org_version',
+ 'var/lib/org-config.el', '.dir-locals.el', 'lib/htmlize.el'
)
namespace :org do
+ directory 'var/tmp'
+
desc 'Download last version of Org'
- file 'tmp/org.tar.gz' do
+ 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
@@ -29,21 +31,22 @@ namespace :org do
end
desc 'Compile Org'
- task compile: 'tmp/org.tar.gz' do |task|
+ task compile: 'var/tmp/org.tar.gz' do |task|
verbose = Rake::FileUtilsExt.verbose_flag
- org_version = "org-#{Fronde::Config.org_last_version}"
- next if Dir.exist?("#{org_version}/lisp")
- make = ['make', '-C', org_version]
+ 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 xzf #{task.prerequisites[0]}"
+ sh "tar -C lib -xzf #{task.prerequisites[0]}"
sh((make + ['compile']).join(' '))
sh((make + ['autoloads']).join(' '))
- Dir.glob('org-[0-9.]*').each do |ov|
- next if ov == org_version
+ Dir.glob('lib/org-[0-9.]*').each do |ov|
+ next if ov == org_dir
rm_r ov
end
end
@@ -55,23 +58,25 @@ namespace :org do
end
end
- file 'htmlize.el' do
+ directory 'lib'
+
+ file 'lib/htmlize.el' => 'lib' do
htmlize = URI(
'https://raw.githubusercontent.com/hniksic/emacs-htmlize/master/htmlize.el'
).open.read
- IO.write 'htmlize.el', htmlize
+ IO.write 'lib/htmlize.el', htmlize
end
- file 'org-config.el' => 'htmlize.el' do
+ file 'var/lib/org-config.el' => 'lib/htmlize.el' do
Fronde::Config.write_org_lisp_config
end
- file '.dir-locals.el' do
+ file '.dir-locals.el' => 'var/lib/org-config.el' do
Fronde::Config.write_dir_locals
end
desc 'Install Org'
- multitask install: ['org:compile', 'org-config.el', '.dir-locals.el'] do
+ multitask install: ['org:compile', '.dir-locals.el'] do
mkdir_p "#{Fronde::Config.settings['public_folder']}/assets"
Fronde::Config.sources.each do |s|
mkdir_p s['path'] unless Dir.exist? s['path']
diff --git a/lib/tasks/site.rake b/lib/tasks/site.rake
index 1ff7132..6027ef8 100644
--- a/lib/tasks/site.rake
+++ b/lib/tasks/site.rake
@@ -24,10 +24,10 @@ namespace :site do
end
desc 'Convert and customize all org files'
- task :build, [:force?] => ['org-config.el', :index] do |_, args|
+ task :build, [:force?] => ['var/lib/org-config.el', :index] do |_, args|
args.with_defaults(:force? => false)
build_html = Thread.new do
- rm_r 'tmp/timestamps', force: true if args[:force?]
+ rm_r 'var/tmp/timestamps', force: true if args[:force?]
Fronde::Emacs.new(verbose: Rake::FileUtilsExt.verbose_flag).publish
end
begin
diff --git a/spec/data/org-config-blog-proof.el b/spec/data/org-config-blog-proof.el
index 758e9bd..09e38d8 100644
--- a/spec/data/org-config-blog-proof.el
+++ b/spec/data/org-config-blog-proof.el
@@ -1,7 +1,7 @@
;; Add org-mode to load path
-(add-to-list 'load-path (expand-file-name "org-__ORG_VERSION__/lisp" "__TEST_DIR__"))
+(add-to-list 'load-path (expand-file-name "org-__ORG_VERSION__/lisp" "__TEST_DIR__/lib"))
;; Load last version of htmlize.el
-(load-file (expand-file-name "htmlize.el" "__TEST_DIR__"))
+(load-file (expand-file-name "htmlize.el" "__TEST_DIR__/lib"))
;; Current project options
(setq fronde/version "__VERSION__"
diff --git a/spec/data/org-config-proof.el b/spec/data/org-config-proof.el
index 8ea8025..5a680e1 100644
--- a/spec/data/org-config-proof.el
+++ b/spec/data/org-config-proof.el
@@ -1,7 +1,7 @@
;; Add org-mode to load path
-(add-to-list 'load-path (expand-file-name "org-__ORG_VERSION__/lisp" "__TEST_DIR__"))
+(add-to-list 'load-path (expand-file-name "org-__ORG_VERSION__/lisp" "__TEST_DIR__/lib"))
;; Load last version of htmlize.el
-(load-file (expand-file-name "htmlize.el" "__TEST_DIR__"))
+(load-file (expand-file-name "htmlize.el" "__TEST_DIR__/lib"))
;; Current project options
(setq fronde/version "__VERSION__"
diff --git a/spec/fronde/config_spec.rb b/spec/fronde/config_spec.rb
index b698530..27b7a1c 100644
--- a/spec/fronde/config_spec.rb
+++ b/spec/fronde/config_spec.rb
@@ -330,13 +330,13 @@ describe Fronde::Config do
context 'with config utils method' do
after do
- FileUtils.rm 'tmp/__last_org_version__', force: true
+ FileUtils.rm 'var/tmp/last_org_version', force: true
described_class.class_eval '@org_version = nil', __FILE__, __LINE__
end
it 'gives current org version' do
described_class.class_eval '@org_version = nil', __FILE__, __LINE__
- IO.write('tmp/__last_org_version__', 'test')
+ IO.write('var/tmp/last_org_version', 'test')
expect(described_class.org_last_version).to eq('test')
end
end
diff --git a/spec/rake_org_spec.rb b/spec/rake_org_spec.rb
index 7a3978b..cbf78e7 100644
--- a/spec/rake_org_spec.rb
+++ b/spec/rake_org_spec.rb
@@ -3,7 +3,7 @@
require 'rake'
context 'with working org files' do
- let(:org_dir) { "org-#{Fronde::Config.org_last_version}" }
+ let(:org_dir) { "lib/org-#{Fronde::Config.org_last_version}" }
before do
init_testing_website
@@ -11,16 +11,16 @@ context 'with working org files' do
end
after do
- Dir.glob('org-[0-9.]*').each { |ov| FileUtils.rm_r(ov, force: true) }
- FileUtils.rm ['.dir-locals.el', 'org-config.el'], force: true
+ 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
end
it 'compiles org-config.el', rake: true do
- rake.invoke_task('org-config.el')
- expect(File.exist?('org-config.el')).to be(true)
+ rake.invoke_task('var/lib/org-config.el')
+ 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)
@@ -28,15 +28,15 @@ context 'with working org files' do
.gsub(/__BASE_DIR__/, base_dir)
.gsub(/__VERSION__/, Fronde::VERSION)
.gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
- expect(IO.read('org-config.el')).to eq(proof_content)
+ expect(IO.read('var/lib/org-config.el')).to eq(proof_content)
end
it 'compiles org-config.el for blog', rake: true do
old_conf = Fronde::Config.settings.dup
old_conf['theme'] = 'toto'
Fronde::Config.load_test(old_conf)
- rake.invoke_task('org-config.el')
- expect(File.exist?('org-config.el')).to be(true)
+ rake.invoke_task('var/lib/org-config.el')
+ 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)
@@ -44,13 +44,13 @@ context 'with working org files' do
.gsub(/__BASE_DIR__/, base_dir)
.gsub(/__VERSION__/, Fronde::VERSION)
.gsub(/__ORG_VERSION__/, Fronde::Config.org_last_version)
- expect(IO.read('org-config.el')).to eq(proof_content)
+ expect(IO.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('org-config.el', Dir.pwd)
+ proof = File.expand_path('var/lib/org-config.el', Dir.pwd)
expect(IO.read('.dir-locals.el')).to(
eq("((org-mode . ((eval . (load-file \"#{proof}\")))))")
)
@@ -59,7 +59,7 @@ context 'with working org files' do
it 'installs Org', rake: true do
copy_org_tarball_to_fake_tmp
rake(verbose: false).invoke_task('org:install')
- expect(File.exist?('org-config.el')).to be(true)
+ expect(File.exist?('var/lib/org-config.el')).to be(true)
expect(File.exist?('.dir-locals.el')).to be(true)
expect(File.exist?("#{org_dir}/lisp/org-loaddefs.el")).to be(true)
end
@@ -69,17 +69,17 @@ context 'with working org files' do
FileUtils.rm_r org_dir, force: true
copy_org_tarball_to_fake_tmp
rake(verbose: true).invoke_task('org:install')
- expect(File.exist?('org-config.el')).to be(true)
+ expect(File.exist?('var/lib/org-config.el')).to be(true)
expect(File.exist?('.dir-locals.el')).to be(true)
expect(File.exist?("#{org_dir}/lisp/org-loaddefs.el")).to be(true)
end
it 'removes old Org version while installing', rake: true do
- FileUtils.mkdir 'org-2.3'
- expect(Dir.exist?('org-2.3')).to be(true)
+ FileUtils.mkdir_p 'lib/org-2.3'
+ expect(Dir.exist?('lib/org-2.3')).to be(true)
copy_org_tarball_to_fake_tmp
rake(verbose: true).invoke_task('org:install')
rake(verbose: false).invoke_task('org:install') # To check coverage
- expect(Dir.exist?('org-2.3')).to be(false)
+ expect(Dir.exist?('lib/org-2.3')).to be(false)
end
end
diff --git a/spec/requirements.rb b/spec/requirements.rb
index e995ec2..112074e 100644
--- a/spec/requirements.rb
+++ b/spec/requirements.rb
@@ -79,8 +79,8 @@ end
def copy_org_tarball_to_fake_tmp
tarball = File.expand_path('../tmp/org.tar.gz', __dir__)
- FileUtils.mkdir 'tmp'
- FileUtils.cp tarball, 'tmp'
+ FileUtils.mkdir_p 'var/tmp'
+ FileUtils.cp tarball, 'var/tmp'
end
def rake(verbose: false)
@@ -94,10 +94,11 @@ end
RSpec.configure do |config|
config.before(:suite) do
- Fronde::Utils.download_org
+ FileUtils.mkdir 'tmp'
+ Fronde::Utils.download_org('tmp')
end
config.after(:suite) do
- FileUtils.rm_r 'tmp', force: true
+ FileUtils.rm_r ['tmp', 'var'], force: true
end
end