⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typo_textfilter_flickr.rb

📁 用ruby on rails写的一个博客程序,还不错..ruby on rails的确是个好框架
💻 RB
字号:
require 'net/http'require 'flickr/flickr'class Typo  class Textfilter    class Flickr < TextFilterPlugin::MacroPost      plugin_display_name "Flickr"      plugin_description "Automatically generate image tags for Flickr images"      def self.help_text        %{You can use `<typo:flickr>` to display images from [Flickr](http://flickr.com).  Example:    <typo:flickr img="31367273" size="small"/>will produce an `<img>` tag showing image number 31367273 from Flickr.  This image will be linked tothe Flickr page for this image, so you can zoom in and see larger versions.  It will also have acomment block attached if a description has been attached to the picture in Flickr.This macro takes a number of parameters:* **img** The Flickr image ID of the picture that you wish to use.  This shows up in the URL whenever  you're viewing a picture in Flickr; for example, the image ID for <http://flickr.com/photos/scottlaird/31367273>  is 31367273.* **size** The image size that you'd like to display.  Options are:  * square (75x75)  * thumbnail (maximum size 100 pixels)  * small (maximum size 240 pixels)  * medium (maximum size 500 pixels)  * large (maximum size 1024 pixels)  * original* **style** This is passed through to the enclosing `<div>` that this macro generates.  To float the flickr  image on the right, use `style="float:right"`.* **caption** The caption displayed below the image.  By default, this is Flickr's description of the image.  to disable, use `caption=""`.* **title** The tooltip title associated with the image.  Defaults to Flickr's image title.* **alt** The alt text associated with the image.  By default, this is the same as the title.}      end      def self.macrofilter(blog,content,attrib,params,text="")        img     = attrib['img']        size    = attrib['size'] || "square"        style   = attrib['style']        caption = attrib['caption']        title   = attrib['title']        alt     = attrib['alt']        begin          flickr      = ::Flickr.new(FLICKR_KEY)          flickrimage = ::Flickr::Photo.new(img)          sizes       = flickrimage.sizes          details     = sizes.find {|s| s['label'].downcase == size.downcase } || sizes.first          width       = details['width']          height      = details['height']          imageurl    = details['source']          imagelink   = flickrimage.url          caption   ||= sanitize(CGI.unescapeHTML(flickrimage.description)) unless flickrimage.description.blank?          title     ||= flickrimage.title          alt       ||= title          if(caption.blank?)            captioncode=""          else            captioncode = "<p class=\"caption\" style=\"width:#{width}px\">#{caption}</p>"          end          "<div style=\"#{style}\" class=\"flickrplugin\"><a href=\"#{imagelink}\"><img src=\"#{imageurl}\" width=\"#{width}\" height=\"#{height}\" alt=\"#{alt}\" title=\"#{title}\"/></a>#{captioncode}</div>"        rescue Exception => e          logger.info e          %{<div class='broken_flickr_link'>`#{img}' could not be displayed because: <br />#{e}</div>}        end      end    end  endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -