Class: Hse::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

desc ‘build_old [FILE]’, ‘read FILE and build json doc with uniq _uuid’ def build_(fname = ‘default’)

document = {}
puts "APDIR.self #{self.appdir}"
puts "APDIR #{self.appdir}"
path = File.expand_path(File.join(appdir, fname))
puts "path #{path}"
uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{fname}"
puts "_ID = #{path} - #{uuid}"
lines = File.readlines path
lines.reject!{|c|c.empty? || c == "\n"}
document[:title] = lines.shift.strip
document[:tags] = lines.shift.strip.split(/[[:punct:]]| /).reject!{|c|c.empty?}
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
body = markdown.render lines.join("\n")
document[:body] = body
say "----------", :green
pp document
document

end



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

def initialize(*)
  super
  self.appdir      = options[:appdir] || File.expand_path(Dir.pwd)
  # self.config_file = options[:config]
  # self.debug = options[:debug]
  self.source_paths << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Attribute Details

#appdirObject

Returns the value of attribute appdir.



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

def appdir
  @appdir
end

#config_fileObject

Returns the value of attribute config_file.



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

def config_file
  @config_file
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

Instance Method Details

#build(fname = 'default') ⇒ Object



100
101
102
103
# File 'lib/hse/cli.rb', line 100

def build(fname = 'default')
  doc = parse.build fname
  pp doc
end

#check(fname = 'default') ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/hse/cli.rb', line 106

def check(fname = 'default')
  doc = parse.build fname
  if doc[:ru].nil?
    say "error: title should be filled", :red
  elsif doc[:en].nil?
    say "error: English title should be filled", :red
  elsif doc[:author].nil?
    say "error: author should be filled", :red
  elsif doc[:tags].nil? || doc[:tags].empty?
    say "error: tags should be filled", :red
  else
    say "module ok", :green
  end
end

#generate(to = nil) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/hse/cli.rb', line 146

def generate(to = nil)
  self.appdir = to if to
  self.destination_root = appdir
  directory('modules')
  directory('posts')
  directory('panels')
  directory('events')
  template('couchapprc.erb', '.couchapprc')
end

#get(id = false, env = 'default') ⇒ Object



90
91
92
# File 'lib/hse/cli.rb', line 90

def get(id = false, env = 'default')
  remote(env).get_id id
end

#push(fname = false, env = 'default') ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/hse/cli.rb', line 134

def push(fname = false, env = 'default')
  doc = build fname
  revision = remote(env).get_doc_revision(doc)
  doc['_rev'] = revision if revision
  puts "rev ====== #{revision}"
  puts "pushing document id #{doc[:_id]}"
  #post_body = JSON.generate doc
  #remote(env).put(doc[:_id], post_body)
  remote(env).push_docs doc
end

#taglist(course = 'default', env = 'default') ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/hse/cli.rb', line 122

def taglist(course = 'default', env = 'default')
  #remote(env).get taglist, course
  case course
  when "Anti4ka"
    say %w(tag tag1 tag2 tag2)
  when ""
  else
    say "error: no course #{course}", :red
  end
end

#user(email = false, push = false, env = 'default') ⇒ Object



95
96
97
# File 'lib/hse/cli.rb', line 95

def user(email = false, push = false, env = 'default')
  remote(env).user email, push
end

#versionObject



157
158
159
# File 'lib/hse/cli.rb', line 157

def version
  say Hse::VERSION
end