Module: Fronde::Org
- Defined in:
- lib/fronde/org.rb,
lib/fronde/org/file.rb,
lib/fronde/org/file_extracter.rb
Overview
Everything related to Org mode
The module itself wraps code necessary to download the last version of the Emacs package. It also serves as a namespace for the class responsible for handling Org files: File.
Defined Under Namespace
Modules: FileExtracter Classes: File
Constant Summary collapse
- CGIT_BASE_URL =
'https://cgit.git.savannah.gnu.org/cgit/emacs/org-mode.git/'
Class Method Summary collapse
-
.compile(source, version, target, verbose: false) ⇒ Object
Compile downloaded Org package.
- .current_version ⇒ Object
-
.download(destination = 'var/tmp') ⇒ String
Download latest org-mode tarball.
- .fetch_org_tarball(http, request, destination) ⇒ Object
- .fetch_version_number ⇒ Object
- .http_get_client(uri) ⇒ Object
-
.last_version(force: false, cookie_dir: 'var/tmp') ⇒ String
Fetch and return the last published version of Org.
- .make_org_cmd(org_dir, target, verbose: false) ⇒ Object
Class Method Details
.compile(source, version, target, verbose: false) ⇒ Object
Compile downloaded Org package
107 108 109 110 111 112 113 114 115 |
# File 'lib/fronde/org.rb', line 107 def compile(source, version, target, verbose: false) untar_cmd = ['tar', '-xzf', source] system(*untar_cmd) FileUtils.mv "org-mode-release_#{version}", target # Fix a weird unknown package version ::File.write("#{target}/mk/version.mk", "ORGVERSION ?= #{version}") system(*make_org_cmd(target, 'compile', verbose:)) system(*make_org_cmd(target, 'autoloads', verbose:)) end |
.current_version ⇒ Object
16 17 18 19 |
# File 'lib/fronde/org.rb', line 16 def current_version # Do not crash if Org is not yet installed (and thus return nil) Dir.glob('lib/org-*').first&.delete_prefix('lib/org-') end |
.download(destination = 'var/tmp') ⇒ String
Download latest org-mode tarball.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fronde/org.rb', line 70 def download(destination = 'var/tmp') org_last_version = last_version(force: false, cookie_dir: destination) tarball = "org-mode-release_#{org_last_version}.tar.gz" uri = URI("#{CGIT_BASE_URL}snapshot/#{tarball}") # Will crash on purpose if anything goes wrong http_get_client(uri) do |http, request| fetch_org_tarball http, request, destination end org_last_version end |
.fetch_org_tarball(http, request, destination) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fronde/org.rb', line 81 def fetch_org_tarball(http, request, destination) # Remove version number in dest file to allow easy rake file # task naming dest_file = ::File.('org.tar.gz', destination) http.request request do |response| ::File.open(dest_file, 'w') do |io| response.read_body { |chunk| io.write chunk } end end end |
.fetch_version_number ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fronde/org.rb', line 52 def fetch_version_number # 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>' ) uri = URI(CGIT_BASE_URL) response = http_get_client(uri) { |http, req| http.request req } versions = response.body.each_line(chomp: true).filter_map do |line| line.match(tag_rx) { |matchdata| matchdata[:number] } end versions.compact.max_by { Gem::Version.new _1 } end |
.http_get_client(uri) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/fronde/org.rb', line 44 def http_get_client(uri) Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| request = Net::HTTP::Get.new(uri) request['User-Agent'] = Fronde::USER_AGENT yield http, request end end |
.last_version(force: false, cookie_dir: 'var/tmp') ⇒ String
Fetch and return the last published version of Org.
To be nice with Org servers, this method will keep the fetched version number in a cache file. You can bypass it by using the force parameter.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fronde/org.rb', line 32 def last_version(force: false, cookie_dir: 'var/tmp') = "#{cookie_dir}/last_org_version" return ::File.read if !force && ::File.exist?() org_version = fetch_version_number raise 'No remote Org version found' unless org_version FileUtils.mkdir_p ::File.write , org_version org_version end |
.make_org_cmd(org_dir, target, verbose: false) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/fronde/org.rb', line 92 def make_org_cmd(org_dir, target, verbose: false) 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 |