From dfbc9aa87994f757a9700dffe9679548181047fa Mon Sep 17 00:00:00 2001 From: Bohung Date: Thu, 1 Apr 2021 17:20:29 +0800 Subject: [PATCH] change title's editor to ckeditor. --- app/controllers/web_resources_controller.rb | 9 ++++-- app/views/admin/web_resources/_form.html.erb | 2 +- .../web_resource/_web_res_widget1.html.erb | 13 ++++++++ modules/web_resource/info.json | 30 ++++++++++++++++++ modules/web_resource/thumbs/thumb.png | Bin 0 -> 4075 bytes modules/web_resource/web_res_index1.html.erb | 17 ++++++++++ modules/web_resource/web_res_index2.html.erb | 17 ++++++++++ web_resource.gemspec | 17 +++++++++- 8 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 modules/web_resource/_web_res_widget1.html.erb create mode 100644 modules/web_resource/info.json create mode 100644 modules/web_resource/thumbs/thumb.png create mode 100644 modules/web_resource/web_res_index1.html.erb create mode 100644 modules/web_resource/web_res_index2.html.erb diff --git a/app/controllers/web_resources_controller.rb b/app/controllers/web_resources_controller.rb index 652944a..ce8cd01 100644 --- a/app/controllers/web_resources_controller.rb +++ b/app/controllers/web_resources_controller.rb @@ -1,5 +1,5 @@ class WebResourcesController < ApplicationController - + require 'nokogiri' def index links = WebLink.where(:title.ne => "").can_display.filter_by_categories web_link = links.collect do |link| @@ -14,9 +14,14 @@ class WebResourcesController < ApplicationController elsif link.link_open == "local" target = "_self" end - + doc = Nokogiri::HTML(link.title.to_s) + text = doc.css("body")[0].text rescue "" + if text.blank? && doc.css("img").count != 0 + text = doc.css("img").map{|img| img.attr("alt") rescue ""}.select{|t| t.present?}.first + end { "title" => link.title, + "title_text" => text, "context" => link.context, "statuses" => statuses, "category" => link.category.title, diff --git a/app/views/admin/web_resources/_form.html.erb b/app/views/admin/web_resources/_form.html.erb index ab1aab2..d52f62c 100644 --- a/app/views/admin/web_resources/_form.html.erb +++ b/app/views/admin/web_resources/_form.html.erb @@ -91,7 +91,7 @@
<%= f.fields_for :title_translations do |f| %> - <%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@link.title_translations[locale] rescue nil) %> + <%= f.text_area locale, class: "input-block-level ckeditor", placeholder: t(:title), value: (@link.title_translations[locale] rescue nil) %> <% end %>
diff --git a/modules/web_resource/_web_res_widget1.html.erb b/modules/web_resource/_web_res_widget1.html.erb new file mode 100644 index 0000000..5b3ef48 --- /dev/null +++ b/modules/web_resource/_web_res_widget1.html.erb @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/modules/web_resource/info.json b/modules/web_resource/info.json new file mode 100644 index 0000000..3d1bb8f --- /dev/null +++ b/modules/web_resource/info.json @@ -0,0 +1,30 @@ +{ + "frontend": [ + { + "filename" : "web_res_index1", + "name" : { + "zh_tw" : "1. 列表 ( 模組標題, 連結, 連結說明 )", + "en" : "1. List (widget-title, link, link description)" + }, + "thumbnail" : "thumb.png" + }, + { + "filename" : "web_res_index2", + "name" : { + "zh_tw" : "2. 三欄式列表 ( 模組標題, 連結, 連結說明 )", + "en" : "2. 3 column List (widget-title, link, link description)" + }, + "thumbnail" : "thumb.png" + } + ], + "widgets" : [ + { + "filename" : "web_res_widget1", + "name" : { + "zh_tw" : "1. 列表 ( 模組標題, 連結 )", + "en" : "1. List (widget-title, link)" + }, + "thumbnail" : "thumb.png" + } + ] +} \ No newline at end of file diff --git a/modules/web_resource/thumbs/thumb.png b/modules/web_resource/thumbs/thumb.png new file mode 100644 index 0000000000000000000000000000000000000000..266af5606742714c262a949cd58aedc2b84b1959 GIT binary patch literal 4075 zcmcgvYdBPE`=8Q@or=MZk}-~jIXD}qFebzhVvsZ#jA2HMW=0OFFbKQkR5@2;7{)1- z&=wM+oMYofvU8{uIS&7&UHkuj*w_2v{qU~qTI;!=weH`2-_Lz|o)v3@JtZh0Apin_ z1kKIRw!l~h+!g!w0MC|jUMDb!Q%!MHJBk;Th7Tlwj65ms1cm?>ZoCb zunI6C_z=xP0tt2@SbL8Ul825b)X)H;M@Iny{0US%gzoQ04nooOq2J}A0DAj1918i) zLM7=#|1t_^Wdkvx1QH+`F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p`wN=HxBhpv`O?}1||BTG*852Fdi zf=bq!Y)hxw^KZ}{@?OYaIJ4|?Z86-WfT&Z+h7^$wIQ)6H8xhTE`Qp%t27{yI5x&}n zjGJe_fr|$Pt|~uDnhZ1N{|vMz!Q7S573!lkX`w*`M_tsqp5B&;jQ4iu-%6ZvY&d?S z(Yb!KKCBjcBfE4hloZ^UW{2r=yHy0PzyN)UnCjQ^&}bh?xwb$$BT+V%+b{b zq?WOa<=b6)e-`d$?21O2jFEohz$tKYMmUzXr zv!G#9d=mkj!$T|>;o(^`Q6(9fne#dcS*H7Knqnn^b1|?Q$ +

+ {{page-title}} +

+
    +
  • +

    + {{title}} + + {{status}} + +

    + {{context}} +
  • +
+ +{{pagination_goes_here}} \ No newline at end of file diff --git a/modules/web_resource/web_res_index2.html.erb b/modules/web_resource/web_res_index2.html.erb new file mode 100644 index 0000000..6432ea6 --- /dev/null +++ b/modules/web_resource/web_res_index2.html.erb @@ -0,0 +1,17 @@ + +{{pagination_goes_here}} \ No newline at end of file diff --git a/web_resource.gemspec b/web_resource.gemspec index 729a01a..5e137c0 100644 --- a/web_resource.gemspec +++ b/web_resource.gemspec @@ -2,7 +2,22 @@ $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "web_resource/version" - +app_path = File.expand_path(__dir__) +template_path = ENV['PWD'] + '/app/templates' +all_template = Dir.glob(template_path+'/*/') +puts 'copying module' +all_template.each do |folder| + if !folder.include?('mobile') + if folder.split('/')[-1] != 'mobile' && Dir.exist?("#{folder}/modules/") + begin + system ('cp -r '+ app_path + '/modules/. ' + folder+'/modules/.') + puts "Updating websource to #{folder}" + rescue + puts "error updating websource in #{folder}" + end + end + end +end # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "web_resource"