From 306aed5b8a559aad2fb944a946ffdda9713f07ec Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 6 Mar 2010 09:47:55 -0500 Subject: introducing version 2, major patch, (version 1 libraries retained) --- lib/sisu/v2/html_promo.rb | 433 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) create mode 100644 lib/sisu/v2/html_promo.rb (limited to 'lib/sisu/v2/html_promo.rb') diff --git a/lib/sisu/v2/html_promo.rb b/lib/sisu/v2/html_promo.rb new file mode 100644 index 00000000..962184f2 --- /dev/null +++ b/lib/sisu/v2/html_promo.rb @@ -0,0 +1,433 @@ +# coding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2010, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Ralph Amissah + + + + ** Description: html advertising component, build here, mockup + +=end +module SiSU_HTML_promo + require "#{SiSU_lib}/sysenv" # sysenv.rb + include SiSU_Env + class Ad + def initialize(md) + @md=md + @env=SiSU_Env::Info_env.new(@md.fns,@md) + @rc=SiSU_Env::Get_init.instance.yamlrc + @ad=SiSU_Env::Get_init.instance.ads + @vz=SiSU_Env::Get_init.instance.skin + @flag=@env.widget.promo? + end + def div + def major + @flag[:ad] ? '
' : '' + end + def minor + @flag[:ad] ? '
' : '' + end + def close + @flag[:ad] ? '
' : '' + end + self + end + def display #(type=nil,id=nil) + ads_array,promo_array=[],[] + if @flag[:ad] + ads=if @md.promo && @md.promo.length > 0 #promo set in document + promo_array=@md.promo + elsif @flag[:sk] #promo set in associated skin + promo_array=@vz.widget_promo + elsif @flag[:rc] #promo set in rc file + promo_array=if @rc['promo'].class==String + @rc['promo'].split(/[,;]\s*/) + else @rc['promo'] + end + else advert_extract_all + end + ads=if promo_array.length > 0 + promo_array.each do |x| + ads_array << advert_extract_subject(x) + end + ads_array + end + adverts(ads.join) + end + end + def cell(prod,id) + @prod,@id=prod,id + def title + @prod['title'] ? %{#{@prod['title']}} : '' + end + def subtitle + @prod['subtitle'] ? %{ - #{@prod['subtitle']}} : '' + end + def author + @prod['author'] ? %{

#{@prod['author']}

} : '' + end + def editor + @prod['editor'] ? %{

#{@prod['editor']}

} : '' + end + def year + @prod['year'] ? %{

#{@prod['year']}

} : '' + end + def date + @prod['date'] ? %{

On: #{@prod['date']}

} : '' + end + def location + @prod['at'] ? %{

At: #{@prod['at']}

} : '' + end + def pages + @prod['pages'] ? %{

Pages: #{@prod['pages']} pages

} : '' + end + def form + @prod['form'] ? %{

#{@prod['form']}

} : '' + end + def nick + @prod['nick'] ? %{(#{@prod['nick']})
} : '' + end + def update + @prod['update'] ? %{

Updated: #{@prod['update']}

} : '' + end + def issn + @prod['issn'] ? %{

issn: #{@prod['issn']}

} : '' + end + def blurb + @prod['blurb'] ? %{

#{@prod['blurb']}

} : '' + end + def search_form_sisu(table=true) + db=if @prod['db']=~/\S+/ + (@prod['db']=~/^SiSU_\S+/) ? @prod['db'] : "SiSU_#{@prod['db']}" + elsif defined? @rc['search']['sisu']['db'] \ + and @rc['search']['sisu']['db'] =~/\S+/ + (@rc['search']['sisu']['db']=~/^SiSU_\S+/) ? @prod['search']['sisu']['db'] : "SiSU_#{@prod['db']}" + else nil + end + action=if @prod['action']=~/^http:\/\// + @prod['action'] + elsif defined? @rc['search']['sisu']['action'] \ + and @rc['search']['sisu']['action'] =~/^http:\/\// + @rc['search']['sisu']['action'] + else nil + end + form=if action \ + and db + 'SiSU search:
' + @env.widget.search_form('sisusearch',action,db,table) + else '' + end + end + def search_form_hyperestraier(table=true) + action=if defined? @rc['search']['hyperestraier']['action'] \ + and @rc['search']['hyperestraier']['action'] =~/^http:\/\// + @rc['search']['hyperestraier']['action'] + else nil + end + form=if action + '
' + @env.widget.search_form('hyperestraier',action,'',table) + else '' + end + form + end + def links + if @prod['links'] #and @prod['links']==Array + links_a=[] + @prod['links'].each do |x| + if x \ + and x['url'] \ + and x['title'] + subtitle=x['subtitle'] ? %{ - #{x['subtitle']}} : '' + url_=(x['url'] =~/http:/) ? x['url'] : "../#{x['url']}" + links_a << %{\n} + end + end + links_a.join + else '' + end + end + def image + @prod['image'] ? %{
} : '' + end + def url_link + @url_=if @prod['url'] =~/http:/ + "#{@prod['url']}" + else "../#{@prod['url']}" # "#{@env.url.root}/#{@prod['url']}" + end + def show + @prod['url'] ? %{} : '' + end + def url + @prod['url'] ? %{} : '' + end + def url_relative + @prod['url'] ? %{} : '' + end + self + end + def flyer + if @prod['flyer'] + %{

 PDF flyer

} + else '' + end + end + def price + def gbp + if defined? @prod['price']['gbp'] \ + and @prod['price']['gbp'] + "  £ #{@prod['price']['gbp']} (GBP) " + else '' + end + end + def euro + if defined? @prod['price']['euro'] \ + and @prod['price']['euro'] + "  € #{@prod['price']['euro']} (Euro) " + else '' + end + end + def usd + if defined? @prod['price']['usd'] \ + and @prod['price']['usd'] + "  $ #{@prod['price']['usd']} (USD) " + else '' + end + end + %{

Price:#{gbp}#{euro}#{usd}

} + end + def adsense #draw content from a configuration file + def column_right + if defined? @ad[:promo]['ad']['adsense']['column_right'] + @ad[:promo]['ad']['adsense']['column_right'].join("\n") + else '' + end + end + def line_single + if defined? @ad[:promo]['ad']['adsense']['line_single'] + @ad[:promo]['ad']['adsense']['line_single'].join("\n") + else '' + end + end + self + end + def site_link #Work area + if url_link.url + < +#{url_link.url} +#{image} +#{title} +#{subtitle} +#{nick}

+WOK + else + < +#{image} +#{title} +#{subtitle} +

+WOK + end + end + self + end + def output_form_sponsor(type,id) + cell=cell(@ad[:promo][type][id],prod_id) + prod_type=((id=~/id_(?:[0-9x]){10,13}/i) ? 'isbn' : 'id') + id_detail=%{

#{prod_type}: #{prod_id}

} + < +#{cell.site_link} +#{cell.blurb} +#{cell.links} +WOK + end + def output_form_link(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) + < +#{cell.site_link} +#{cell.author} +#{cell.year} +#{cell.blurb} +#{cell.links} +WOK + end + def output_form_search_sisu(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) + cell.search_form_sisu(false) + end + def output_form_search_hyperestraier(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) + cell.search_form_hyperestraier(false) + end + def output_form_book(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) + prod_type=((id=~/id_(?:[0-9x]){10,13}/i) ? 'isbn' : 'id') + id_detail=%{

#{prod_type}: #{prod_id}

} + < +#{cell.site_link} +#{cell.author} +#{cell.year} +#{id_detail} +#{cell.pages}#{cell.form} +#{cell.price} +#{cell.flyer} +#{cell.blurb} +#{cell.links} +WOK + end + def output_form_journal(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) + < +#{cell.site_link} +#{cell.editor} +#{cell.issn} +#{cell.update} +#{cell.form} +#{cell.price.gsub(/Price:/,'Subscription:')} +#{cell.flyer} +#{cell.blurb} +#{cell.links} +WOK + end + def output_form_conference(type,id) + prod_id=id.gsub(/id_/,'') + cell=cell(@ad[:promo][type][id],prod_id) +#translate date (dd month yyyy) from 2007-03-04 and ruby conversion + < +#{cell.site_link} +#{cell.date} +#{cell.location} +#{cell.price} +#{cell.flyer} +#{cell.blurb} +#{cell.links} +WOK + end + def output_form_select(type,id) + case type + when /site/ + output_form_link(type,id) + when /sponsor/ + output_form_sponsor(type,id) + when /search/ + if id=~/hyperestraier/ + output_form_search_hyperestraier(type,id) + else output_form_search_sisu(type,id) + end + when /book/ + output_form_book(type,id) + when /journal/ + output_form_journal(type,id) + when /conference/ + output_form_conference(type,id) + end + end + def advert_extract_subject(category) #extracts products from category/subject list + adverts=[] + if defined? @ad[:promo_list][category] \ + and @ad[:promo_list][category] + @ad[:promo_list][category].keys.each do |type| + @ad[:promo_list][category][type].each do |i| + if i + id=((i.inspect =~/^\d/) ? "id_#{i.to_s.strip}" : i.to_s.strip) #watch remove .to_s ? + gbp=usd=euro=nil + if defined? @ad[:promo][type][id] \ + and not @ad[:promo][type][id].nil? + adverts << output_form_select(type,id) + else + if defined? @ad[:promo][category][type][id] \ + and @ad[:promo][category][type][id].class==Array \ + and @ad[:promo][category][type][id].length > 0 + adverts << @ad[:promo][category][type][id].join("\n") + end + end + end + end + end + else + tell=SiSU_Screen::Ansi.new(@md.cmd,"category not found: #{category}") + tell.warn unless @md.cmd =~/q/ + end + adverts.join + end + def advert_extract_all #extracts all products from list (which is broken down into categories) + adverts=[] + @ad[:promo_list].keys.each do |category| + adverts << advert_extract_subject(category) + end + adverts.flatten + end + def adverts(ads) + <