Class: Bashly::RenderSource

Inherits:
Object
  • Object
show all
Extended by:
AssetHelper
Defined in:
lib/bashly/render_source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssetHelper

asset, asset_content

Constructor Details

#initialize(selector) ⇒ RenderSource

Returns a new instance of RenderSource.



24
25
26
# File 'lib/bashly/render_source.rb', line 24

def initialize(selector)
  @selector = selector
end

Instance Attribute Details

#selectorObject (readonly)

Returns the value of attribute selector.



3
4
5
# File 'lib/bashly/render_source.rb', line 3

def selector
  @selector
end

Class Method Details

.internalObject



8
9
10
11
12
13
# File 'lib/bashly/render_source.rb', line 8

def internal
  @internal ||= internal_dirs.to_h do |dir|
    selector = File.basename(dir).to_sym
    [selector, new(selector)]
  end
end

.internal_dirsObject



15
16
17
# File 'lib/bashly/render_source.rb', line 15

def internal_dirs
  @internal_dirs ||= Dir["#{internal_root}/*"].select { |x| File.directory? x }
end

.internal_rootObject



19
20
21
# File 'lib/bashly/render_source.rb', line 19

def internal_root
  asset('libraries/render')
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bashly/render_source.rb', line 41

def exist?
  Dir.exist? path
end

#internal?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bashly/render_source.rb', line 33

def internal?
  selector.is_a? Symbol
end

#pathObject



37
38
39
# File 'lib/bashly/render_source.rb', line 37

def path
  internal? ? "#{internal_root}/#{selector}" : selector
end

#readmeObject



49
50
51
# File 'lib/bashly/render_source.rb', line 49

def readme
  File.read readme_file if File.exist? readme_file
end

#render(target, show: nil) ⇒ Object



28
29
30
31
# File 'lib/bashly/render_source.rb', line 28

def render(target, show: nil)
  context = RenderContext.new source: path, target: target, show: show
  context.instance_eval render_script
end

#summaryObject



45
46
47
# File 'lib/bashly/render_source.rb', line 45

def summary
  File.readlines(summary_file)[0].chomp
end