Class: WebsiteBuilderEngine::OfferpagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/website_builder_engine/offerpages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
70
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 44

def create
  @offerpage = Offerpage.new(params[:offerpage])
  if params[:offerpage][:filename].ends_with?(".html")
    params[:offerpage][:filename].gsub!('.html','')
  end
  if params[:format] == 'html'
    p1 = HTMLToTextileParser.new
    p2 = HTMLToTextileParser.new
    p3 = HTMLToTextileParser.new
    p4 = HTMLToTextileParser.new
    p1.feed(params[:offerpage][:content_block1])
    @offerpage.content_block1 = p1.to_textile
    p2.feed(params[:offerpage][:content_block2])
    @offerpage.content_block2 = p2.to_textile
    p3.feed(params[:offerpage][:offer_block])
    @offerpage.offer_block = p3.to_textile
    p4.feed(params[:offerpage][:testimonials])
    @offerpage.testimonials = p4.to_textile
  end
  respond_to do |format|
    if @offerpage.save
      format.html { redirect_to offerpages_path, notice: 'Offerpage was successfully created.' }
    else
      format.html { render action: "new" }
    end
  end
end

#destroyObject



86
87
88
89
90
91
92
93
94
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 86

def destroy
  @offerpage = Offerpage.find(params[:id])
  @offerpage.destroy
  @settings = Setting.first
  FileUtils.remove_file("#{@file_path + @offerpage.filename}.html", force = true)
  respond_to do |format|
    format.html { redirect_to offerpages_url }
  end
end

#editObject



40
41
42
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 40

def edit
  @offerpage = Offerpage.find(params[:id])
end

#indexObject



19
20
21
22
23
24
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 19

def index
  @offerpages = Offerpage.all
  respond_to do |format|
    format.html # index.html.erb
  end
end

#newObject



33
34
35
36
37
38
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 33

def new
  @offerpage = Offerpage.new
  respond_to do |format|
    format.html # new.html.erb
  end
end

#publishObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 6

def publish
  @offerpage = Offerpage.find(params[:id])
  @permalink = "http://#{@settings.domain}/#{@settings.offerpages_directory}/#{@offerpage.filename}.html"
  offerpage_page = render_to_string(:template => "website_builder_engine/templates/offerpage.html.haml", :layout => false )
  FileUtils.makedirs(@file_path) unless File.exists?(@file_path)
  File.open("#{@file_path + @offerpage.filename}.html", 'w') {|f| f.write(offerpage_page) }
  @offerpage.update_attribute(:published, true)
  respond_to do |format|
    format.html { redirect_to offerpages_path, notice: "Built a webpage for the offer page \"#{@offerpage.title}\"" }
  end

end

#showObject



26
27
28
29
30
31
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 26

def show
  @offerpage = Offerpage.find(params[:id])
  respond_to do |format|
    format.html # show.html.erb
  end
end

#updateObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/website_builder_engine/offerpages_controller.rb', line 72

def update
  @offerpage = Offerpage.find(params[:id])
  if params[:offerpage][:filename].ends_with?(".html")
    params[:offerpage][:filename].gsub!('.html','')
  end
  respond_to do |format|
    if @offerpage.update_attributes(params[:offerpage])
      format.html { redirect_to offerpages_path, notice: 'Offerpage was successfully updated.' }
    else
      format.html { render action: "edit" }
    end
  end
end