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 0000000..266af56 Binary files /dev/null and b/modules/web_resource/thumbs/thumb.png differ diff --git a/modules/web_resource/web_res_index1.html.erb b/modules/web_resource/web_res_index1.html.erb new file mode 100644 index 0000000..f225a23 --- /dev/null +++ b/modules/web_resource/web_res_index1.html.erb @@ -0,0 +1,17 @@ + +{{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"