diff --git a/app/assets/config/merged_manifest.js b/app/assets/config/merged_manifest.js index cb85549..c1df78b 100644 --- a/app/assets/config/merged_manifest.js +++ b/app/assets/config/merged_manifest.js @@ -1,2 +1,2 @@ //= link_directory ../stylesheets/merged .css -//= link merged/application.css +//= link ../stylesheets/merged/application.css diff --git a/app/controllers/merged/images_controller.rb b/app/controllers/merged/images_controller.rb index 1033582..1de3938 100644 --- a/app/controllers/merged/images_controller.rb +++ b/app/controllers/merged/images_controller.rb @@ -8,7 +8,7 @@ module Merged def create new_image = Image.create_new(params['filename'] , params['image_file']) - redirect = :merge_images + redirect = :merged_images if(params[:redirect]) redirect = params[:redirect].gsub("NEW" ,new_image.name) puts "image redirect #{redirect}" diff --git a/app/controllers/merged/merged_controller.rb b/app/controllers/merged/merged_controller.rb index 7433df3..d08a422 100644 --- a/app/controllers/merged/merged_controller.rb +++ b/app/controllers/merged/merged_controller.rb @@ -1,6 +1,6 @@ module Merged class MergedController < ApplicationController - layout 'merge_layout' + layout 'merged_layout' end end diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index c20ac1b..2099950 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -9,7 +9,7 @@ module Merged def set_image @section.content["image"] = params[:image] @page.save - redirect_to merge_page_section_url(@page.id,@section.id) + redirect_to page_section_url(@page.id,@section.id) end def update @@ -21,7 +21,7 @@ module Merged end end @page.save - redirect_to :merge_page_section + redirect_to :merged_page_section end private diff --git a/app/helpers/merged/section_helper.rb b/app/helpers/merged/section_helper.rb index 4857e99..8cd6cbc 100644 --- a/app/helpers/merged/section_helper.rb +++ b/app/helpers/merged/section_helper.rb @@ -1,7 +1,7 @@ module Merged::SectionHelper def section_form(options) - url = merge_page_section_url( @page.id , @section.id) + url = page_section_url( @page.id , @section.id) puts "URL #{url}" form_tag( url , {method: :patch}) do yield diff --git a/app/models/merged/image.rb b/app/models/merged/image.rb index 6c8f058..b3e76d1 100644 --- a/app/models/merged/image.rb +++ b/app/models/merged/image.rb @@ -19,7 +19,8 @@ module Merged def self.all return @@images unless @@images.empty? - Dir[Rails.root.join Image.asset_root + "*.*"].each do |f| + dir = Rails.root.join Image.asset_root + "/*.*" + Dir[dir].each do |f| file = f.split("/").last self.add( file ) end @@ -40,7 +41,7 @@ module Merged def self.asset_root "app/assets/images/" + root end - + def self.root "cms" end diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index b700536..f694f1f 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -4,7 +4,7 @@ module Merged include ActiveModel::Conversion extend ActiveModel::Naming - @@root + @@root = "cms" @@files = Set.new Dir.new(Rails.root.join(@@root)).children attr_reader :name , :content diff --git a/app/views/layouts/cms_layout.haml b/app/views/layouts/merged_layout.haml similarity index 98% rename from app/views/layouts/cms_layout.haml rename to app/views/layouts/merged_layout.haml index 8b82381..3ad689a 100644 --- a/app/views/layouts/cms_layout.haml +++ b/app/views/layouts/merged_layout.haml @@ -23,10 +23,10 @@ %nav.hidden.md:block{"aria-label" => "Site Nav"} %ul.flex.items-center.gap-6.text-sm %li - %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => merge_pages_path} + %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => pages_path} Pages %li - %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => merge_images_path} + %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => images_path} Images %li %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => "/merged/styles"} diff --git a/app/views/merged/images/index.haml b/app/views/merged/images/index.haml index 5b476f9..171c9f3 100644 --- a/app/views/merged/images/index.haml +++ b/app/views/merged/images/index.haml @@ -6,7 +6,7 @@ %h5.mt-4.text-lg.font-bold Name is optional %p will be taken from uploaded file = file_field_tag 'image_file' - .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_merge_image_path} + .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 => merged.new_image_path} = submit_tag 'Submit' -@images.each do |name , image| .relative.block.border.border-gray-100 diff --git a/app/views/merged/pages/_form.haml b/app/views/merged/pages/_form.haml index 1670884..f804117 100644 --- a/app/views/merged/pages/_form.haml +++ b/app/views/merged/pages/_form.haml @@ -1,9 +1,9 @@ -= form_for @merge_page do |f| - - if @merge_page.errors.any? += form_for @merged_page do |f| + - if @merged_page.errors.any? #error_explanation - %h2= "#{pluralize(@merge_page.errors.count, "error")} prohibited this merge_page from being saved:" + %h2= "#{pluralize(@merged_page.errors.count, "error")} prohibited this merged_page from being saved:" %ul - - @merge_page.errors.full_messages.each do |message| + - @merged_page.errors.full_messages.each do |message| %li= message .actions diff --git a/app/views/merged/pages/edit.haml b/app/views/merged/pages/edit.haml index 8435c15..c1fc387 100644 --- a/app/views/merged/pages/edit.haml +++ b/app/views/merged/pages/edit.haml @@ -1,7 +1,7 @@ -%h1 Editing #{@merge_page.name} +%h1 Editing #{@merged_page.name} = render 'form' -= link_to 'Show', merge_page_url(@merge_page.name) += link_to 'Show', merged_page_url(@merged_page.name) \| -= link_to 'Back', merge_pages_path += link_to 'Back', merged_pages_path diff --git a/app/views/merged/pages/index.haml b/app/views/merged/pages/index.haml index 3d08191..7476ccd 100644 --- a/app/views/merged/pages/index.haml +++ b/app/views/merged/pages/index.haml @@ -14,20 +14,20 @@ %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 Status %tbody.divide-y.divide-gray-200 - - @pages.each do |merge_page| + - @pages.each do |merged_page| %tr %td.whitespace-nowrap.px-4.py-2.text-gray-700 - = link_to merge_page.name , merge_page_path(merge_page.name) + = link_to merged_page.name , page_path(merged_page.name) %td.whitespace-nowrap.px-4.py-2.text-gray-700 - = merge_page.first_template + = merged_page.first_template %td.whitespace-nowrap.px-4.py-2.text-gray-700 - = merge_page.content.length + = merged_page.content.length %td.whitespace-nowrap.px-4.py-2 %strong.rounded.bg-green-100.px-3.text-xs.font-medium.text-green-700{:class => "py-1.5"} - = link_to 'Show', merge_page_path(merge_page.name) + = link_to 'Show', page_path(merged_page.name) %strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"} - = link_to 'Edit', edit_merge_page_path(merge_page.name) + = link_to 'Edit', edit_page_path(merged_page.name) %section - %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_merge_page_path} + %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} New Page diff --git a/app/views/merged/pages/new.haml b/app/views/merged/pages/new.haml index a194a59..7b5cf07 100644 --- a/app/views/merged/pages/new.haml +++ b/app/views/merged/pages/new.haml @@ -1,5 +1,5 @@ -%h1 New merge_page +%h1 New merged_page = render 'form' -= link_to 'Back', merge_pages_path += link_to 'Back', pages_path diff --git a/app/views/merged/pages/show.haml b/app/views/merged/pages/show.haml index 2c402fe..2b47ce3 100644 --- a/app/views/merged/pages/show.haml +++ b/app/views/merged/pages/show.haml @@ -15,7 +15,7 @@ %button.mt-4.rounded-lg.bg-yellow-500.p-4 =link_to "Down" , "/index" %button.mt-4.rounded-lg.bg-blue-400.p-4 - =link_to "Edit" , merge_page_section_path(@page.name , section.id) + =link_to "Edit" , page_section_path(@page.name , section.id) %button.mt-4.rounded-lg.bg-cyan-400.p-4 =link_to "New" , "/index" %button.mt-4.rounded-lg.bg-red-400.p-4 diff --git a/app/views/merged/sections/_form.html.haml b/app/views/merged/sections/_form.html.haml index 75c04a0..7f8e880 100644 --- a/app/views/merged/sections/_form.html.haml +++ b/app/views/merged/sections/_form.html.haml @@ -1,9 +1,9 @@ -= form_for @merge_section do |f| - - if @merge_section.errors.any? += form_for @merged_section do |f| + - if @merged_section.errors.any? #error_explanation - %h2= "#{pluralize(@merge_section.errors.count, "error")} prohibited this merge_section from being saved:" + %h2= "#{pluralize(@merged_section.errors.count, "error")} prohibited this merged_section from being saved:" %ul - - @merge_section.errors.full_messages.each do |message| + - @merged_section.errors.full_messages.each do |message| %li= message .actions diff --git a/app/views/merged/sections/edit.html.haml b/app/views/merged/sections/edit.html.haml index 8aac50c..f0337b1 100644 --- a/app/views/merged/sections/edit.html.haml +++ b/app/views/merged/sections/edit.html.haml @@ -1,7 +1,7 @@ -%h1 Editing merge_section +%h1 Editing merged_section = render 'form' -= link_to 'Show', @merge_section += link_to 'Show', @merged_section \| -= link_to 'Back', merge_sections_path += link_to 'Back', merged_sections_path diff --git a/app/views/merged/sections/editors/_header.haml b/app/views/merged/sections/editors/_header.haml index 2e6c0b2..d637171 100644 --- a/app/views/merged/sections/editors/_header.haml +++ b/app/views/merged/sections/editors/_header.haml @@ -1,6 +1,6 @@ .relative.block.border.border-gray-100 %h3.mt-4.text-lg.font-bold= key.upcase = section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do - = text_field_tag( :header , @section.content["header"], class: "w-full.rounded-lg.border-gray-200.p-4.pr-12.text-sm.shadow-sm") + = text_field_tag( :header , @section.content["header"], class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") %button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-sm.font-medium.text-white{:type => "submit"} Update diff --git a/app/views/merged/sections/editors/_image.haml b/app/views/merged/sections/editors/_image.haml index 7296bf9..e81fd09 100644 --- a/app/views/merged/sections/editors/_image.haml +++ b/app/views/merged/sections/editors/_image.haml @@ -1,9 +1,9 @@ .relative.block.border.border-gray-100 %h3.mt-4.text-lg.font-bold= key.upcase %button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white - =link_to "Change Image" , merge_page_section_select_image_url(@page.name,@section.id) + =link_to "Change Image" , page_section_select_image_url(@page.name,@section.id) %button.ml-3.inline-block.rounded-lg.bg-red-500.px-5.py-3.text-md.font-medium.text-white - = link_to( "Remove image" , merge_page_section_set_image_path( @page.name, @section.id , image: "")) + = link_to( "Remove image" , page_section_set_image_path( @page.name, @section.id , image: "")) .relative.block.border.border-gray-100 diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 3a07049..9d2286f 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing merge_sections +%h1 Listing merged_sections %table %thead @@ -8,12 +8,12 @@ %th %tbody - - @merge_sections.each do |merge_section| + - @merged_sections.each do |merged_section| %tr - %td= link_to 'Show', merge_section - %td= link_to 'Edit', edit_merge_section_path(merge_section) - %td= link_to 'Destroy', merge_section, method: :delete, data: { confirm: 'Are you sure?' } + %td= link_to 'Show', merged_section + %td= link_to 'Edit', edit_merged_section_path(merged_section) + %td= link_to 'Destroy', merged_section, method: :delete, data: { confirm: 'Are you sure?' } %br -= link_to 'New Section', new_merge_section_path += link_to 'New Section', new_merged_section_path diff --git a/app/views/merged/sections/new.html.haml b/app/views/merged/sections/new.html.haml index 1a8a38a..4b64e04 100644 --- a/app/views/merged/sections/new.html.haml +++ b/app/views/merged/sections/new.html.haml @@ -1,5 +1,5 @@ -%h1 New merge_section +%h1 New merged_section = render 'form' -= link_to 'Back', merge_sections_path += link_to 'Back', merged_sections_path diff --git a/app/views/merged/sections/select_image.haml b/app/views/merged/sections/select_image.haml index b0700bd..8ceecf3 100644 --- a/app/views/merged/sections/select_image.haml +++ b/app/views/merged/sections/select_image.haml @@ -1,15 +1,15 @@ .grid.grid-cols-6.gap-2.m-8 .relative.block.border.border-gray-100 %h3.mt-4.text-lg.font-bold Add new image or select (click) - = form_tag(merge_images_path, multipart: true) do + = form_tag(merged.images_path, multipart: true) do = text_field_tag 'filename' %h5.mt-4.text-lg.font-bold Name is optional %p will be taken from uploaded file - = hidden_field_tag :redirect , merge_page_section_set_image_url(@page.name,@section.id,image: "NEW") + = hidden_field_tag :redirect , page_section_set_image_url(@page.name,@section.id,image: "NEW") = file_field_tag 'image_file' - .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_merge_image_path} + .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 => merged.new_image_path} = submit_tag 'Submit' -@images.each do |name , image| .relative.block.border.border-gray-100 - = link_to( merge_page_section_set_image_path( image: name)) do + = link_to( page_section_set_image_path( image: name)) do =image_tag("cms/#{name}" , class: "h-56 w-full object-contain lg:h-72") diff --git a/app/views/merged/sections/show.html.haml b/app/views/merged/sections/show.html.haml index 6ebeb02..d3814e5 100644 --- a/app/views/merged/sections/show.html.haml +++ b/app/views/merged/sections/show.html.haml @@ -13,6 +13,6 @@ - @section.content.each do |key , value| = render "merged/sections/editors/#{key}", section: @section , key: key , value: value -= #link_to 'Edit', edit_merge_section_path(@merge_section) += #link_to 'Edit', edit_merged_section_path(@merged_section) \| -= #link_to 'Back', merge_sections_path += #link_to 'Back', merged_sections_path diff --git a/lib/merged/engine.rb b/lib/merged/engine.rb index 7bcfab5..5921cf9 100644 --- a/lib/merged/engine.rb +++ b/lib/merged/engine.rb @@ -2,8 +2,18 @@ module Merged class Engine < ::Rails::Engine isolate_namespace Merged initializer "merged.assets.precompile" do |app| - app.config.assets.precompile += %w( merged/application.js merged/application.css ) + app.config.assets.precompile += %w( config/merged_manifest.js ) + add_image_assets(app.config , "section_preview") + add_image_assets(app.config , "card_preview") end + private + def add_image_assets(config , sub_dir ) + dir = Dir.new(Engine.root.join("app/assets/images/merged/" , sub_dir)) + dir.children.each do |file| + kid = "merged/" + sub_dir + "/" + file + config.assets.precompile << kid + end + end end end