Class: Lissio::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lissio/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
17
18
19
20
21
22
# File 'lib/lissio/builder.rb', line 13

def initialize(&block)
	@sprockets = Sprockets::Environment.new
	@main      = 'app'

	Opal.paths.each {|path|
		@sprockets.append_path path
	}

	block.call(self) if block
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def debug
  @debug
end

#indexObject

Returns the value of attribute index.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def index
  @index
end

#mainObject

Returns the value of attribute main.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def main
  @main
end

#source_mapsObject

Returns the value of attribute source_maps.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def source_maps
  @source_maps
end

#sprocketsObject

Returns the value of attribute sprockets.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def sprockets
  @sprockets
end

#staticObject

Returns the value of attribute static.



10
11
12
# File 'lib/lissio/builder.rb', line 10

def static
  @static
end

Instance Method Details

#buildObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lissio/builder.rb', line 24

def build
	source = if @path
		unless File.exist?(@path)
			raise "index does not exist: #{@path}"
		end

		File.read @path
	elsif File.exist? 'index.html.erb'
		File.read 'index.html.erb'
	else
		<<-HTML
			<!DOCTYPE html>
			<html>
			<head>
				<%= lissio %>
			</head>
			<body>
			</body>
			</html>
		HTML
	end

	::ERB.new(source).result binding
end

#lissio(source = main) ⇒ Object



49
50
51
# File 'lib/lissio/builder.rb', line 49

def lissio(source = main)
	"<script>#{Uglifier.compile(@sprockets[source].to_s)}</script>"
end