Class: Awestruct::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



16
17
18
19
20
21
22
23
24
# File 'lib/awestruct/pipeline.rb', line 16

def initialize
  @handler_chains = HandlerChains.new
  @before_all_extensions       = []
  @extensions                  = []
  @helpers                     = []
  @transformers                = []
  @after_all_extensions        = []
  @after_generation_extensions = []
end

Instance Attribute Details

#after_all_extensionsObject (readonly)

Returns the value of attribute after_all_extensions.



11
12
13
# File 'lib/awestruct/pipeline.rb', line 11

def after_all_extensions
  @after_all_extensions
end

#after_generation_extensionsObject (readonly)

Returns the value of attribute after_generation_extensions.



14
15
16
# File 'lib/awestruct/pipeline.rb', line 14

def after_generation_extensions
  @after_generation_extensions
end

#before_all_extensionsObject (readonly)

Returns the value of attribute before_all_extensions.



9
10
11
# File 'lib/awestruct/pipeline.rb', line 9

def before_all_extensions
  @before_all_extensions
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



10
11
12
# File 'lib/awestruct/pipeline.rb', line 10

def extensions
  @extensions
end

#handler_chainsObject (readonly)

Returns the value of attribute handler_chains.



8
9
10
# File 'lib/awestruct/pipeline.rb', line 8

def handler_chains
  @handler_chains
end

#helpersObject (readonly)

Returns the value of attribute helpers.



12
13
14
# File 'lib/awestruct/pipeline.rb', line 12

def helpers
  @helpers
end

#transformersObject (readonly)

Returns the value of attribute transformers.



13
14
15
# File 'lib/awestruct/pipeline.rb', line 13

def transformers
  @transformers
end

Instance Method Details

#add_after_extension(e) ⇒ Object



34
35
36
# File 'lib/awestruct/pipeline.rb', line 34

def add_after_extension(e)
  @after_all_extensions << e
end

#add_after_generation_extension(e) ⇒ Object



46
47
48
# File 'lib/awestruct/pipeline.rb', line 46

def add_after_generation_extension(e)
  @after_generation_extensions << e
end

#add_before_extension(e) ⇒ Object



26
27
28
# File 'lib/awestruct/pipeline.rb', line 26

def add_before_extension(e)
  @before_all_extensions << e
end

#apply_transformers(site, page, rendered) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/awestruct/pipeline.rb', line 103

def apply_transformers(site, page, rendered)
  @transformers.each do |t|
    $LOG.debug "Applying transformer #{t.class} for page #{page}" if site.config.verbose && site.config.debug
    start_time = DateTime.now
    rendered = t.transform( site, page, rendered )
    $LOG.trace "Total time in #{t.class}.transform #{DateTime.now.to_time - start_time.to_time} seconds" if site.config.verbose
  end
  rendered
end

#execute(site, on_reload = false) ⇒ Object



50
51
52
# File 'lib/awestruct/pipeline.rb', line 50

def execute(site, on_reload = false)
  execute_extensions(site, on_reload)
end

#execute_after_generation(site) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/awestruct/pipeline.rb', line 113

def execute_after_generation(site)
  @after_generation_extensions.each do |e|
    $LOG.verbose "Executing after generation #{e.class}" if site.config.verbose
    start_time = DateTime.now
    if e.respond_to? :execute
      e.execute(site)
    else
      e.after_generation(site)
    end
    $LOG.trace "Total time in #{e.class}.after_generation #{DateTime.now.to_time - start_time.to_time} seconds"
  end
end

#execute_extensions(site, on_reload) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/awestruct/pipeline.rb', line 54

def execute_extensions(site, on_reload)
  @before_all_extensions.each do |e|
    $LOG.verbose "Executing before all extension #{e.class}" if site.config.verbose

    if on_reload && e.respond_to?
      start_time = DateTime.now
      e.on_reload(site) if (on_reload && e.respond_to?(:on_reload))
      $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
    end

    start_time = DateTime.now
    if e.respond_to? :execute
      e.execute(site)
    else
      e.before_extensions(site)
    end
    $LOG.trace "Total time in #{e.class}.before_extensions #{DateTime.now.to_time - start_time.to_time} seconds"
  end

  @extensions.each do |e|
    $LOG.verbose "Executing extension #{e.class}" if site.config.verbose
    if on_reload && e.respond_to?(:on_reload)
      start_time = DateTime.now
      e.on_reload(site)
      $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
    end
    start_time = DateTime.now
    e.execute(site)
    $LOG.trace "Total time in #{e.class}.execute #{DateTime.now.to_time - start_time.to_time} seconds"
  end

  @after_all_extensions.each do |e|
    $LOG.verbose "Executing after all extension #{e.class}" if site.config.verbose
    if on_reload && e.respond_to?(:on_reload)
      start_time = DateTime.now
      e.on_reload(site)
      $LOG.trace "Total time in #{e.class}.on_reload #{DateTime.now.to_time - start_time.to_time} seconds"
    end

    start_time = DateTime.now
    if e.respond_to? :execute
      e.execute(site)
    else
      e.after_generation(site)
    end
    $LOG.trace "Total time in #{e.class}.after_generation #{DateTime.now.to_time - start_time.to_time} seconds"
  end
end

#extension(e) ⇒ Object



30
31
32
# File 'lib/awestruct/pipeline.rb', line 30

def extension(e)
  @extensions << e
end

#helper(h) ⇒ Object



38
39
40
# File 'lib/awestruct/pipeline.rb', line 38

def helper(h)
  @helpers << h
end

#mixin_helpers(context) ⇒ Object



126
127
128
129
130
131
# File 'lib/awestruct/pipeline.rb', line 126

def mixin_helpers(context)
  context.extend( Awestruct::ContextHelper )
  @helpers.each do |h|
    context.extend(h)
  end
end

#transformer(t) ⇒ Object



42
43
44
# File 'lib/awestruct/pipeline.rb', line 42

def transformer(t)
  @transformers << t
end