Class: Vocco::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/vocco/generator.rb

Defined Under Namespace

Classes: SourceFile

Constant Summary collapse

CSS =
<<-'__YOU_ARE_SPECIAL__'
body {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif;
  font-size: 15px; }

html, body {
  height: 100%; }

body {
  padding: 1em; }

.code {
  font-family: Menlo, Monaco, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace;
  font-size: 16px;
  padding: 1em;
  width: 50%; }

.nav {
  width: 40%;
  position: fixed;
  top: 0;
  left: 55%;
  height: 100%;
  font-size: 15px;
  line-height: 22px;
  color: #252519; }
  .nav .wrapper {
    color: black;
    height: 100%; }
    .nav .wrapper .area {
      background-color: #cccccc;
      padding: 1em 1em 1em 1em;
      border-bottom: 1px dashed #bbbbbb;
      border-top: 1px dashed #666666; }
      .nav .wrapper .area .autohide {
        opacity: 0;
        height: 0px;
        -webkit-transition: all 0.2s linear;
        overflow: auto; }
      .nav .wrapper .area:hover .autohide {
        height: 150px;
        opacity: 1; }
    .nav .wrapper .notes {
      max-height: 40%;
      overflow: auto; }

table th {
  text-align: right; }

__YOU_ARE_SPECIAL__

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(opts)
  @globs  = Array(opts[:files]
            ).compact.map do |glob|
              glob.gsub(/(^\.\/)|(\/$)/, '')
            end
  @out    = opts[:out]
  @notes  = Array(opts[:notes]).compact
  @name   = opts[:name].capitalize
  @site   = opts[:site]
  @vim    = Array(opts[:vim]).compact

  FileUtils.mkdir_p(@out) # ensure out dir exists
end

Instance Attribute Details

#globsObject (readonly)

Returns the value of attribute globs.



11
12
13
# File 'lib/vocco/generator.rb', line 11

def globs
  @globs
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/vocco/generator.rb', line 11

def name
  @name
end

#notesObject (readonly)

Returns the value of attribute notes.



11
12
13
# File 'lib/vocco/generator.rb', line 11

def notes
  @notes
end

#outObject (readonly)

Returns the value of attribute out.



11
12
13
# File 'lib/vocco/generator.rb', line 11

def out
  @out
end

#siteObject (readonly)

Returns the value of attribute site.



11
12
13
# File 'lib/vocco/generator.rb', line 11

def site
  @site
end

Instance Method Details

#filesObject

array of SourceFile's mapped from the glob matches



48
49
50
51
52
53
54
# File 'lib/vocco/generator.rb', line 48

def files
  @files ||= @globs.map do |glob|
    Dir[glob]
  end.flatten.uniq.map do |path|
    SourceFile.new(path, self)
  end
end

#glob_regexObject

regex to trim the glob dir scopes off a source file path.



38
39
40
41
42
43
44
45
# File 'lib/vocco/generator.rb', line 38

def glob_regex
  @glob_regex ||= begin
    str = scopes.map do |scope|
      Regexp::escape(scope)
    end.join('|')
    /^(\.\/)?(#{str})(\/)?/
  end
end

#runObject Also known as: run!



56
57
58
# File 'lib/vocco/generator.rb', line 56

def run
  run_vim; postprocess
end

#scopesObject

the paths underneath which the @globs are globbing; the static part of the glob, or "scope" of sorts



29
30
31
32
33
34
# File 'lib/vocco/generator.rb', line 29

def scopes
  @scopes ||= @globs.map do |glob|
    tokens = glob.split('*')
    tokens.size > 1 ? tokens.first : nil
  end.compact
end