Module: Fronde::CLI::Commands

Included in:
App
Defined in:
lib/fronde/cli/commands.rb

Overview

Fronde commands

Instance Method Summary collapse

Instance Method Details

#fronde_buildObject



33
34
35
36
37
# File 'lib/fronde/cli/commands.rb', line 33

def fronde_build
  @rake.options.build_all = true
  @rake['site:build'].invoke @options[:force]
  true
end

#fronde_helpObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fronde/cli/commands.rb', line 69

def fronde_help
  # Try to find command in next argv, otherwise fallback again.
  @command = @argv.shift || 'basic' if @command == 'help'
  cmd_opt = OptParse.command_options(@command)
  label = cmd_opt[:label] || @command
  output = [format_label(I18n.t('fronde.bin.usage', label:))]
  cmd = cmd_opt[:name] || @command
  output << format_label(I18n.t("fronde.bin.commands.#{cmd}"))
  output << OptParse.help_command_body(cmd)
  puts output.join
  true
end

#fronde_newObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fronde/cli/commands.rb', line 12

def fronde_new
  new_dir = @argv.first || 'my_fronde_website'
  FileUtils.mkdir new_dir
  Dir.chdir new_dir
  Helpers.init_config_file @options
  Fronde::CONFIG.reset # Correctly compute various path
  Helpers.init_rakefile
  init_rake
  @rake['org:install'].invoke
  @argv = ['src/index.org']
  fronde_open
end

#fronde_openObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fronde/cli/commands.rb', line 49

def fronde_open
  editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
  cmd = [editor]
  file_path = @argv.first || Dir.pwd
  unless File.file?(file_path)
    # file_path may be updated with title given in options
    file_path = create_new_file(file_path)
    # Only move to the end of file for new file. Let the editor handle
    # the best position for already existing files
    cmd << '+6'
  end
  cmd << file_path
  system(*cmd)
end

#fronde_previewObject



39
40
41
42
43
44
45
46
47
# File 'lib/fronde/cli/commands.rb', line 39

def fronde_preview
  Thread.new do
    sleep 1
    port = Fronde::CONFIG.get(%w[preview server_port], 5000)
    Helpers.launch_app_for_uri "http://127.0.0.1:#{port}/"
  end
  @rake['site:preview'].invoke
  true
end

#fronde_publishObject



64
65
66
67
# File 'lib/fronde/cli/commands.rb', line 64

def fronde_publish
  @rake['sync:push'].invoke
  true
end

#fronde_updateObject



25
26
27
28
29
30
31
# File 'lib/fronde/cli/commands.rb', line 25

def fronde_update
  Helpers.init_rakefile
  init_rake
  @rake.options.build_all = true
  @rake['org:upgrade'].invoke
  true
end