 WorkoutsView = (workouts) ->
 	html = []
 
-	html.push workouts.renderMeta()
-
-	workouts.getAll().forEach (workout) ->
-		html.push workout.render()
+	workouts.getAll().forEach (section) ->
+		html.push section.render()
 
 	this._html = html.join('')
 	this

WORKOUT_SEPARATOR = '\n\n'

Workouts = (text) ->
	this._chunks = text.split(WORKOUT_SEPARATOR)
	meta = this._meta = new WorkoutsMeta()
	lastMetaIdx = -1
	this._workouts = this._chunks.reduce((workouts, workoutChunk, idx) ->
		w = new Workout(workoutChunk)
		if w.isValid()
			workouts.push(w)
		else
			if lastMetaIdx + 1 is not idx
				console.warn 'Meta section found after a valid workout. Meta idx was', idx
			else
				lastMetaIdx += 1
			meta.add(workoutChunk)

		workouts
	, [])
	this

Workouts.prototype.getAll = () ->
	this._workouts.slice()

Workouts.prototype.getAllMeta = () ->
	this._meta.getAll()

Workouts.prototype.renderMeta = () ->
	this._meta.render()

WorkoutsMeta = (textChunks) ->
	this._meta = []
	this

WorkoutsMeta.prototype.add = (metaText) ->
	this._meta.push(metaText)

WorkoutsMeta.prototype.getAll = () ->
	this._meta.slice()

WorkoutsMeta.prototype.render = () ->
	'<div class="meta">' +
		this._meta.map((metaSection) ->
			'<div class="meta-section">' +
				metaSection +
			'</div>').join('') +
	'</div>'

Workout = (workoutText) ->


WorkoutHeader.prototype.render = () ->
	'<div class="workout-header">' +
		toHtml(this._text) +
	'</div>'

Exercises = (exercises) -> this
