Module: Fronde::CLI::Helpers

Defined in:
lib/fronde/cli/helpers.rb

Overview

Various utilitaries methods

Class Method Summary collapse

Class Method Details

.current_osString

Try to discover the current host operating system.

Returns:

  • (String)

    either apple, windows or linux (default)



43
44
45
46
47
48
49
50
# File 'lib/fronde/cli/helpers.rb', line 43

def self.current_os
  if ENV['OS'] == 'Windows_NT' || RUBY_PLATFORM.include?('cygwin')
    return 'windows'
  end
  return 'apple' if RUBY_PLATFORM.include?('darwin')

  'linux'
end

.init_config_file(config) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fronde/cli/helpers.rb', line 9

def self.init_config_file(config)
  return if File.exist? 'config.yml'

  output = config[:output] || 'html'
  output = 'gemini' if output == 'gmi'
  data = { 'author' => config[:author],
           'lang' => config[:lang],
           'output' => output }
  source = File.expand_path './data/config.yml', __dir__
  template = Liquid::Template.parse(File.read(source))
  File.write('config.yml', template.render(data))
end

.init_rakefileObject



22
23
24
25
26
27
# File 'lib/fronde/cli/helpers.rb', line 22

def self.init_rakefile
  FileUtils.cp(
    File.expand_path('./data/Rakefile', __dir__),
    'Rakefile'
  )
end

.launch_app_for_uri(uri) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/fronde/cli/helpers.rb', line 29

def self.launch_app_for_uri(uri)
  case current_os
  when 'windows'
    system 'start', uri
  when 'apple'
    system 'open', uri
  else
    system 'gio', 'open', uri
  end
end