pages add and destroy
This commit is contained in:
parent
d30ce30370
commit
f5d53b6d1c
@ -11,22 +11,21 @@ module Merged
|
|||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /merged/pages/new
|
|
||||||
def new
|
|
||||||
end
|
|
||||||
|
|
||||||
# GET /merged/pages/1/edit
|
# GET /merged/pages/1/edit
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /merged/pages
|
# POST /merged/pages
|
||||||
def create
|
def create
|
||||||
@page = Merged::Page.new(page_params)
|
name = params[:name]
|
||||||
|
message = Page.check_name(name)
|
||||||
if @page.save
|
if( message.nil?)
|
||||||
redirect_to @page, notice: "Page was successfully created."
|
@page = Page.build_new(name)
|
||||||
|
redirect_to new_page_section_url(@page.name) , notice: "Page was successfully created."
|
||||||
else
|
else
|
||||||
render :new, status: :unprocessable_entity
|
@pages = Page.all.values
|
||||||
|
flash.now.alert = message
|
||||||
|
render :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,8 +40,8 @@ module Merged
|
|||||||
|
|
||||||
# DELETE /merged/pages/1
|
# DELETE /merged/pages/1
|
||||||
def destroy
|
def destroy
|
||||||
@page.destroy
|
Page.destroy(@page)
|
||||||
redirect_to page_url, notice: "Page was successfully destroyed."
|
redirect_to pages_url, notice: "Page #{@page.name} was removed."
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -34,6 +34,23 @@ module Merged
|
|||||||
@@all[@name] = self
|
@@all[@name] = self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.check_name(name)
|
||||||
|
return "only alphanumeric, not #{name}" if name.match(/\A[a-zA-Z0-9]*\z/).nil?
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
def self.build_new(name)
|
||||||
|
raise "only alphanumeric, not #{name}" unless check_name(name).nil?
|
||||||
|
name = name + ".yaml"
|
||||||
|
fullname = Rails.root.join(Page.cms_root , name )
|
||||||
|
File.write(fullname , "--- []\n")
|
||||||
|
Page.new(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.destroy( page )
|
||||||
|
@@all.delete(page.name)
|
||||||
|
File.delete(Rails.root.join(Page.cms_root , page.name + ".yaml"))
|
||||||
|
end
|
||||||
|
|
||||||
def new_section(section_template)
|
def new_section(section_template)
|
||||||
section_template = "section_spacer" if section_template.blank?
|
section_template = "section_spacer" if section_template.blank?
|
||||||
section_data = Section.build_data(section_template)
|
section_data = Section.build_data(section_template)
|
||||||
@ -54,6 +71,7 @@ module Merged
|
|||||||
end
|
end
|
||||||
|
|
||||||
def first_template
|
def first_template
|
||||||
|
return "none" unless @content[0]
|
||||||
@content[0]["template"]
|
@content[0]["template"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@
|
|||||||
%strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"}
|
%strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"}
|
||||||
= link_to 'Edit', edit_page_path(merged_page.name)
|
= link_to 'Edit', edit_page_path(merged_page.name)
|
||||||
|
|
||||||
%section
|
.grid.grid-cols-3.gap-2.m-8
|
||||||
%a.inline-block.rounded.border.border-indigo-600.bg-indigo-600.px-12.py-3.text-sm.font-medium.text-white.hover:bg-transparent.hover:text-indigo-600.focus:outline-none.focus:ring.active:text-indigo-500{:href => new_page_path}
|
.relative.block.border.border-gray-100
|
||||||
New Page
|
= form_tag( pages_url , {method: :post } ) do
|
||||||
|
%label.block
|
||||||
|
%h4.text-lg.font-bold Name
|
||||||
|
= text_field_tag( :name , params[:name], class: "block w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
|
||||||
|
=submit_button( "New Page")
|
||||||
|
@ -4,7 +4,7 @@ Merged::Engine.routes.draw do
|
|||||||
post 'changes/commit'
|
post 'changes/commit'
|
||||||
get "styles/index"
|
get "styles/index"
|
||||||
|
|
||||||
resources :pages , except: [:show] , shallow: true do
|
resources :pages , except: [:show , :new] , shallow: true do
|
||||||
resources :sections do
|
resources :sections do
|
||||||
get :select_image
|
get :select_image
|
||||||
get :set_image
|
get :set_image
|
||||||
|
Loading…
Reference in New Issue
Block a user