Class: Tonka::HTML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = []) ⇒ HTML

Returns a new instance of HTML.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/tonka.rb', line 125

def initialize(options=[])
	@layout_arrays = []
	@layout_array_0 = ["<!DOCTYPE html>\n"]
	if options.include?("-angular")
		@layout_array_1 = ["<html ng-app>\n"]
	else
		@layout_array_1 = ["<html>\n"]
	end
	@layout_array_2 = ["<head>\n","\t<title>#{$SITE_NAME}</title>\n"]
	@link_array = add_css_files(options)
	@script_array = add_js_files(options)
	@layout_array_3 = ["</head>\n","<body>\n"]
	@script_array_2 = add_handlebars_template(options)
	@layout_array_4 = ["</body>\n","</html>"]
end

Instance Attribute Details

#layoutObject

CSS processing module



123
124
125
# File 'lib/tonka.rb', line 123

def layout
  @layout
end

Instance Method Details

#add_css_files(options) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/tonka.rb', line 180

def add_css_files(options)
	tags = []
	options.each do |option|
		library_name = option.gsub("-","")
		Tonka::CSS.libraries.each do |library|
			if library[library_name]
				css = Tonka::CSS.new(library_name)
				tags << (css.link_tag + "\n")

			end
		end
	end
	tags << (Tonka::CSS.new("style").link_tag + "\n")
	return tags
end

#add_handlebars_template(options) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/tonka.rb', line 196

def add_handlebars_template(options)
	tag = []
	handlebars_template = "\t<script id='template' type='text/x-handlebars-template'>\n \t</script>\n"

	options.each do |option|
		library_name = option.gsub("-","")
		if library_name == "handlebars"
			tag << handlebars_template
		end
	end

	return tag
end

#add_js_files(options) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/tonka.rb', line 152

def add_js_files(options)
	tags = []
	options.each do |option|
		library_name = option.gsub("-","")
		if library_name == "backbone" && !options.include?("jquery")
			jquery = Tonka::JS.new("jquery")
			tags << jquery.script_tag
		end
		if library_name == "backbone" && !options.include?("underscore")
			underscore = Tonka::JS.new("underscore")
			tags << underscore.script_tag
		end
		if library_name == "bootstrap" && !options.include?("jquery")
			jquery = Tonka::JS.new("jquery")
			tags << jquery.script_tag
		end
		Tonka::JS.libraries.each do |library|
			if library[library_name]
				js = Tonka::JS.new(library_name)
				tags << js.script_tag

			end
		end
	end
	tags << Tonka::JS.new("app").script_tag
	return tags
end

#render(options) ⇒ Object



141
142
143
144
145
146
147
148
149
150
# File 'lib/tonka.rb', line 141

def render(options)
	@index_html = File.new("#{$SITE_NAME}/index.html","w")

	@layout = @layout_array_0.join("") + @layout_array_1.join("") + @layout_array_2.join("") + @link_array.join("") + @script_array.join("") + @layout_array_3.join("") + @script_array_2.join("") + @layout_array_4.join("")

	@index_html.puts @layout
	@index_html.close
	puts "\t\tbuilt ".green+"#{$SITE_NAME}/index.html"

end