Class: Json

Inherits:
Action
  • Object
show all
Defined in:
lib/bloggit/server.rb

Instance Attribute Summary

Attributes inherited from Action

#content_type, #req, #res

Instance Method Summary collapse

Methods inherited from Action

#do_GET, #do_POST, #post, #render, #site

Instance Method Details

#getObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bloggit/server.rb', line 42

def get
	# Get the URI, somehow...
	#path_parser = Regexp.new("/(\w+)(?:/)()")
	
	path_parts = req.path_info.to_s.split('/')
	path_parts.shift # The first is probably always blank, unless no data type was sent... ?
	
	case path_parts.shift
		when "posts"
			@count = site.all_posts.length 
			@data = site.all_posts.to_json
		
		when "pages"
			@count = site.all_pages.length 
			@data = site.all_pages.to_json
		
		when "settings"
			@count = 0
			@data  = "[]"
		
		else
			@count = 0
			@data  = "[]"
	end
	
	@content_type = 'text/javascript'
	render('json')
end