Class: Tehranjs::Web::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/tehranjs/web/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(flash = nil) ⇒ Controller

Returns a new instance of Controller.



9
10
11
# File 'lib/tehranjs/web/controller.rb', line 9

def initialize flash=nil
    @flash=flash
end

Instance Method Details

#_render(temp) ⇒ Object



63
64
65
# File 'lib/tehranjs/web/controller.rb', line 63

def _render temp
    ERB.new(temp).result( binding )
end

#aboutObject



16
17
18
# File 'lib/tehranjs/web/controller.rb', line 16

def about
    render 'about.html.erb'
end

#build_article(response, params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tehranjs/web/controller.rb', line 24

def build_article response, params
    @params = params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
    filename = parameterize([@params[:date],@params[:permalink]].join(' '),'-')
    if @params[:rw] == 'dl'
        response.content_type = "application/octet-stream"
        response.[]=('Content-Disposition',"attachment; filename='#{filename}.md'")
        render 'build_article.md.erb',false 
    else
        article=render 'build_article.md.erb',false 
        begin
         File.open("#{Dir.pwd}/_posts/#{filename}.md", 'w') { |file| file.write(article) }
         response.set_redirect(WEBrick::HTTPStatus::MovedPermanently, "/new_article?message=#{I18n.t('flash.successfull')}")  
         
        rescue
         response.set_redirect(WEBrick::HTTPStatus::MovedPermanently, "/new_article?message=#{I18n.t('flash.faile_to_write')}")  
            
    end
    end
end

#indexObject



12
13
14
# File 'lib/tehranjs/web/controller.rb', line 12

def index
    render 'index.html.erb'
end

#new_articleObject



20
21
22
# File 'lib/tehranjs/web/controller.rb', line 20

def new_article
    render 'new_article.html.erb'
end

#not_foundObject



49
50
51
# File 'lib/tehranjs/web/controller.rb', line 49

def not_found
    
end

#render(template, layout = true) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/tehranjs/web/controller.rb', line 53

def render template , layout=true
    @template = File.read(::File.join(::File.dirname(__FILE__),"views", template))
    @layout = File.read(::File.join(::File.dirname(__FILE__),"views", '_layouts','application.html.erb'))
    return ERB.new(@template).result(binding) unless layout
    templates = [@template, @layout]
    templates.inject(nil) do | prev, temp |
       _render(temp) { prev }
    end
end

#version_labelObject



45
46
47
# File 'lib/tehranjs/web/controller.rb', line 45

def version_label
    return Tehranjs::Identity.version_label
end