Class: Diecut::Mill

Inherits:
Object
  • Object
show all
Defined in:
lib/diecut/mill.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind) ⇒ Mill

Returns a new instance of Mill.



7
8
9
# File 'lib/diecut/mill.rb', line 7

def initialize(kind)
  @kind = kind
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



10
11
12
# File 'lib/diecut/mill.rb', line 10

def kind
  @kind
end

#mediatorObject



13
14
15
# File 'lib/diecut/mill.rb', line 13

def mediator
  @mediator ||= Diecut.mediator(kind)
end

#templatesObject



17
18
19
# File 'lib/diecut/mill.rb', line 17

def templates
  @templates ||= TemplateSet.new
end

#valiseObject



31
32
33
34
35
36
37
38
# File 'lib/diecut/mill.rb', line 31

def valise
  @valise ||= mediator.activated_plugins.map do |plugin|
    stem = plugin.stem_for(kind)
    Valise::Set.define do
      ro stem.template_dir
    end.stemmed(stem.stem)
  end.reduce{|left, right| left + right}.sub_set(kind)
end

Instance Method Details

#activate_pluginsObject



21
22
23
24
25
26
27
28
29
# File 'lib/diecut/mill.rb', line 21

def activate_plugins
  mediator.plugins.map(&:name).each do |name|
    if yield(name)
      mediator.activate(name)
    else
      mediator.deactivate(name)
    end
  end
end

#churn(ui) ⇒ Object



61
62
63
64
65
66
# File 'lib/diecut/mill.rb', line 61

def churn(ui)
  templates.context = mediator.apply_user_input(ui, templates.context_class)
  templates.results do |path, contents|
    yield(path, contents)
  end
end

#context_classObject



46
47
48
# File 'lib/diecut/mill.rb', line 46

def context_class
  templates.context_class
end

#load_filesObject



40
41
42
43
44
# File 'lib/diecut/mill.rb', line 40

def load_files
  valise.filter('**', %i[extended dotmatch]).files do |file|
    templates.add(file.rel_path.to_s, file.contents)
  end
end

#ui_classObject



50
51
52
# File 'lib/diecut/mill.rb', line 50

def ui_class
  mediator.build_ui_class(context_class)
end

#user_interfaceObject



54
55
56
57
58
59
# File 'lib/diecut/mill.rb', line 54

def user_interface
  load_files
  templates.prepare

  ui_class.new
end