Class: Zine::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/zine/cli.rb

Overview

CLI for zine

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#the_siteObject

only used in testing



13
14
15
# File 'lib/zine/cli.rb', line 13

def the_site
  @the_site
end

Instance Method Details

#buildObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/zine/cli.rb', line 22

def build
  # set_trace_func proc { |event, file, line, id, _binding, classname|
  #  if event == 'call' && classname.name.split('::').first == 'Zine'
  #    printf "%25s\#%s\t\t\t%s:%-2d\n", classname, id, file, line
  #  end
  # }
  init_site
  @the_site.build_site
  puts Rainbow('Site built').green
end

#forceObject



34
35
36
37
38
# File 'lib/zine/cli.rb', line 34

def force
  init_site
  @the_site.build_site_forcing_writes
  puts Rainbow('Site built').green
end

#notice(file) ⇒ Object



41
42
43
44
45
# File 'lib/zine/cli.rb', line 41

def notice(file)
  init_site
  @the_site.notice(file)
  puts Rainbow('Site built').green
end

#nukeObject



48
49
50
51
52
53
# File 'lib/zine/cli.rb', line 48

def nuke
  init_site
  FileUtils.remove_dir @the_site.options['directories']['build'],
                       force: true
  puts Rainbow('Site nuked. It\'s the only way to be sure.').green
end

#post(name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/zine/cli.rb', line 56

def post(name)
  init_site
  options = @the_site.options
  option_dir = options['directories']
  Zine::CLI.source_root option_dir['templates']
  @date = DateTime.now
  @name = name
  file = "#{@date.strftime('%Y-%m-%d')}-#{Zine::Page.slug(name)}.md"
  new_post_name = options['templates']['new_post']
  template new_post_name,
           File.join(Dir.pwd, option_dir['posts'], file)
end

#siteObject



70
71
72
73
74
75
# File 'lib/zine/cli.rb', line 70

def site
  # @skeleton_dir ?
  skeleton_dir = File.join File.dirname(__FILE__), 'skeleton', '/.'
  FileUtils.cp_r skeleton_dir, Dir.pwd
  puts Rainbow('New skeleton site created').green
end

#styleObject



78
79
80
81
82
83
# File 'lib/zine/cli.rb', line 78

def style
  init_site
  style = Zine::Style.new(@the_site.options['directories'])
  style.process(File)
  puts Rainbow('Stylesheet rendered').green
end

#versionObject



86
87
88
# File 'lib/zine/cli.rb', line 86

def version
  puts VERSION
end