Module: Gast::Memo

Extended by:
Helper, Memo
Included in:
Memo
Defined in:
lib/gast/memo.rb

Defined Under Namespace

Classes: Request, Response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

escape_html, get_content, get_content_dir, get_language, unescape_html

Class Method Details

.changed?(content_id, content) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/gast/memo.rb', line 61

def changed?(content_id, content)
  content.to_s.chomp != item(content_id).chomp
end

.create(content, language = DEFAULT_HIGHLIGHT) ⇒ Object



49
50
51
52
# File 'lib/gast/memo.rb', line 49

def create(content, language = DEFAULT_HIGHLIGHT)
  content_id = repository(content, language)
  response(content_id, language, content)
end

.item(id) ⇒ Object



81
82
83
# File 'lib/gast/memo.rb', line 81

def item(id)
  escape_html { get_content(id) }
end

.language(id) ⇒ Object



92
93
94
# File 'lib/gast/memo.rb', line 92

def language(id)
  escape_html { get_language(id) }
end

.listsObject



71
72
73
74
75
76
77
78
# File 'lib/gast/memo.rb', line 71

def lists
  Dir.glob(File.expand_path(Gast::PATH + '/**')).map do |dir|
    {
      content_id: dir.split('/').last,
      updated_at: File.stat(dir + '/content').mtime
    }
  end
end

.numberObject



66
67
68
# File 'lib/gast/memo.rb', line 66

def number
  lists.length
end

.request(content_id, language, content) ⇒ Object



32
33
34
# File 'lib/gast/memo.rb', line 32

def request(content_id, language, content)
  Request.new(content_id, language, content)
end

.response(content_id, language, content) ⇒ Object



27
28
29
# File 'lib/gast/memo.rb', line 27

def response(content_id, language, content)
  Response.new(content_id, language, content)
end

.update(content_id, content, language = DEFAULT_HIGHLIGHT) ⇒ Object



55
56
57
58
# File 'lib/gast/memo.rb', line 55

def update(content_id, content, language = DEFAULT_HIGHLIGHT)
  content_id = repository(content, language, content_id)
  response(content_id, language, content)
end

Instance Method Details

#log(id) ⇒ Object



86
87
88
89
90
# File 'lib/gast/memo.rb', line 86

def log(id)
  repo = Repository.new
  repo.dir_name = id
  repo.log
end

#repository(content, language, content_id = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gast/memo.rb', line 37

def repository(content, language, content_id = nil)
  repo = Repository.new
  repo.dir_name = content_id
  repo.create
  repo.content = unescape_html { content }
  repo.language = unescape_html { language }
  repo.write
  repo.commit!

  repo.dir_name
end