Class: Nsume::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/nsume/cli.rb

Instance Method Summary collapse

Instance Method Details

#init(path = Dir.pwd) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nsume/cli.rb', line 14

def init(path=Dir.pwd)
  Nsume.config.dest_path = path

  Nsume::Prepare.generator options
  Nsume::Prepare.jquery
  Nsume::Prepare.bootstrap_js
  Nsume::Prepare.bootswatch_css
  Nsume::Prepare.bootswatch_js
  Nsume::Prepare.bootswatch_theme options['theme']

  Nsume::Logger.info "Successfully initialized."
end


65
66
67
# File 'lib/nsume/cli.rb', line 65

def navbar(site='blog')
  Nsume::Prepare.navbar site
end

#post(title = 'title', content = '') ⇒ Object



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

def post(title='title', content='')
  name = "#{Date.today.strftime("%Y-%m-%d")}-#{title}.md"
  path = File.expand_path(name, Nsume.config.posts_path)
  unless File.exists?(path)
    file = ERB.new(Nsume.config.post_template).result(binding)
    File.write(path, file)
    Nsume::Logger.info "Created a posts."
  else
    Nsume::Logger.info "Existed a posts."
  end
end

#switch(theme) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/nsume/cli.rb', line 41

def switch(theme)
  path = File.join(Nsume.config.dest_path, '_config.yml')
  raw = YAML.load_file(path)
  raw['theme'] = theme
  file = YAML.dump(raw)
  File.write(path, file)

  Nsume::Prepare.bootswatch_theme theme
  Nsume::Logger.info "Switched theme."
end

#themeObject



53
54
55
56
57
# File 'lib/nsume/cli.rb', line 53

def theme
  path = File.join(Nsume.config.dest_path, '_config.yml')
  raw = YAML.load_file(path)
  puts raw['theme']
end

#themesObject



60
61
62
# File 'lib/nsume/cli.rb', line 60

def themes
  puts Nsume.config.themes
end

#upObject



70
71
72
73
# File 'lib/nsume/cli.rb', line 70

def up
  system "cd #{Nsume.config.dest_path} && jekyll server --watch --baseurl ''"
rescue Interrupt
end

#versionObject



76
77
78
# File 'lib/nsume/cli.rb', line 76

def version
  puts "nSume #{Nsume::VERSION}"
end