news section and page with links

This commit is contained in:
Torsten 2023-01-08 23:48:20 +02:00
parent bcb02ea4a4
commit d522fc7600
9 changed files with 31 additions and 20 deletions

View File

@ -17,8 +17,7 @@ module Merged
def update
if( !params[:name].blank? && (params[:name] != @page.name))
@page.add_redirect
@page.name = params[:name]
@page.set_name params[:name]
@page.edit_save(current_member.email)
message = "Page renamed"
end

View File

@ -1,19 +1,17 @@
module Merged
module PagesHelper
def last_blog
sections = Section.all.select{|s| s.page.type == "blog"}
sorted = sections.sort_by(&:updated_at)
last = sorted.pop
puts last.template.class
puts last.template
if (last&.template == "blog_header") or (last&.template == "section_news")
return sorted.last
end
return last
blog = Page.where(type: :blog).order(updated_at: :asc).first
blog&.sections.last
end
def header_list
markdown("- one \n- two\n- three\n- four")
return "" unless blog_section = last_blog
blog = blog_section.page
headers = blog.sections.collect{|s| "- " + s.header}
headers.shift
return "" if headers.empty?
markdown headers.join("\n")
end
end
end

View File

@ -9,10 +9,12 @@ module Merged
self.name
end
def add_redirect
def set_name new_name
new_name = Page.fix_name(new_name)
olds = self.redirects.to_s.split(" ")
olds << self.name unless olds.include?(self.name)
self.redirects = olds.join(" ")
self.name = new_name
end
def sections
@ -63,8 +65,12 @@ module Merged
super
end
def self.fix_name(name)
name.gsub(" ", "_").downcase
end
def self.new_page(name , type)
data = { name: name.dup , updated_at: Time.now , type: type}
data = { name: self.fix_name(name) , updated_at: Time.now , type: type}
Page.new(data)
end

View File

@ -42,10 +42,10 @@ module Merged
end
def set_option( option , value)
if( !value.is_a?(String) && value.respond_to?(:[]) && value[:month] )
year = value[:year] || Time.new.year
value = Time.new( year , value[:month] , value[:day]).to_date
if( option.ends_with?"_date" )
puts "date is #{value}"
year = value[:year] || Time.new.year
value = Time.new( year.to_i , value[:month] , value[:day]).to_date
end
options[option] = value
end

View File

@ -4,6 +4,7 @@
= link_to @page.name , merged.page_path(@page)
.text-xl.text-gray-900
=link_to "View live" , "/#{@page.name}" , target: @page.name
= link_to( "New Section" , merged.new_page_section_path(@page.id) , class: "p-2 border border-gray-200 bg-cyan-100 font-bold rounded-lg hover:bg-sky-100")
= render "layouts/merged_header"

View File

@ -8,7 +8,6 @@
= section.header
.font-bold.text-center.mb-4.lg:mb-8
= date_precision(section.page , "published_date")
.max-w-full.mt-4.gap-16{ options(section , :text_column , :prose ) }
= markdown(section)
= header_list

View File

@ -5,6 +5,7 @@
= section.header
.text-lg
= distance_of_time_in_words_to_now last_blog.updated_at
ago
%hr.mt-2.border.border-4.border-gray-600
- template = find_template(last_blog)
= render( template , section: last_blog)
@ -12,5 +13,5 @@
.ml-20.mb-2.text-lg
= section.text
.mr-20.mb-2.text-lg
%a.transition{:class => "hover:text-gray-500/75", :href => merged.pages_path}
%a.transition{:class => "hover:text-gray-500/75", :href => main_app.view_blog_path(blog.page.name)}
Read More . . .

View File

@ -1,6 +1,6 @@
Rails.application.routes.draw do
mount Merged::Engine => "/merged"
get ":id" , to: "merged/view#view" , id: :id
get ":id" , to: "merged/view#page" , id: :id
end

View File

@ -15,6 +15,13 @@ module Merged
assert_equal page.sections.length , 0
end
def test_creates_removes_spce
name = "Cap Space"
page = Page.new_page( name , "page")
assert_equal page.name , "cap_space"
assert_equal page.sections.length , 0
end
def test_creates_blog
name = "randomname"
page = Page.new_page( name , "blog")