Class: TDiary::Plugin
- Inherits:
-
Object
- Object
- TDiary::Plugin
- Includes:
- ERB::Util, ViewHelper
- Defined in:
- lib/tdiary/plugin.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
writeonly
Sets the attribute comment.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#date ⇒ Object
writeonly
Sets the attribute date.
-
#diaries ⇒ Object
writeonly
Sets the attribute diaries.
-
#last_modified ⇒ Object
writeonly
Sets the attribute last_modified.
Instance Method Summary collapse
- #eval_src(src) ⇒ Object
-
#initialize(params) ⇒ Plugin
constructor
A new instance of Plugin.
- #load_plugin(file) ⇒ Object
Methods included from ViewHelper
Constructor Details
#initialize(params) ⇒ Plugin
Returns a new instance of Plugin.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tdiary/plugin.rb', line 15 def initialize( params ) @header_procs = [] @footer_procs = [] @update_procs = [] @title_procs = [] @body_enter_procs = [] @body_leave_procs = [] @section_index = {} @section_enter_procs = [] @comment_leave_procs = [] @subtitle_procs = [] @section_leave_procs = [] @edit_procs = [] @form_procs = [] @conf_keys = [] @conf_procs = {} @conf_genre_label = {} @content_procs = {} @startup_procs = [] @cookies = [] @javascripts = {} @javascript_setting = [] params.each do |key, value| instance_variable_set( "@#{key}", value ) end # for 1.4 compatibility @index = @conf.index @update = @conf.update @author_name = @conf. || '' @author_mail = @conf. || '' @index_page = @conf.index_page || '' @html_title = @conf.html_title || '' @theme = @conf.theme @css = @conf.css @date_format = @conf.date_format @referer_table = @conf.referer_table @options = @conf. # setup plugin storage unless @conf.io_class.method_defined?(:plugin_open) require 'tdiary/io/plugin_pstore' @conf.io_class.extend(TDiary::IO::PluginPStore) end @storage = @conf.io_class.plugin_open(@conf) # loading plugins @plugin_files = [] plugin_path = @conf.plugin_path || "#{File.dirname(__FILE__)}/plugin" plugin_file = '' begin Dir::glob( "#{plugin_path}/*.rb" ).sort.each do |file| plugin_file = file load_plugin( file ) @plugin_files << plugin_file end rescue ::TDiary::ForceRedirect raise rescue Exception raise PluginError::new( "Plugin error in '#{File::basename( plugin_file )}'.\n#{$!}\n#{$!.backtrace[0]}" ) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*m) ⇒ Object (private)
366 367 368 369 |
# File 'lib/tdiary/plugin.rb', line 366 def method_missing( *m ) super if @debug # ignore when no plugin end |
Instance Attribute Details
#comment=(value) ⇒ Object (writeonly)
Sets the attribute comment
13 14 15 |
# File 'lib/tdiary/plugin.rb', line 13 def comment=(value) @comment = value end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
12 13 14 |
# File 'lib/tdiary/plugin.rb', line 12 def @cookies end |
#date=(value) ⇒ Object (writeonly)
Sets the attribute date
13 14 15 |
# File 'lib/tdiary/plugin.rb', line 13 def date=(value) @date = value end |
#diaries=(value) ⇒ Object (writeonly)
Sets the attribute diaries
13 14 15 |
# File 'lib/tdiary/plugin.rb', line 13 def diaries=(value) @diaries = value end |
#last_modified=(value) ⇒ Object (writeonly)
Sets the attribute last_modified
13 14 15 |
# File 'lib/tdiary/plugin.rb', line 13 def last_modified=(value) @last_modified = value end |
Instance Method Details
#eval_src(src) ⇒ Object
94 95 96 97 98 |
# File 'lib/tdiary/plugin.rb', line 94 def eval_src( src ) ret = eval( src, binding, "(TDiary::Plugin#eval_src)", 1 ) @conf.io_class.plugin_close(@storage) return ret end |
#load_plugin(file) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tdiary/plugin.rb', line 79 def load_plugin( file ) @resource_loaded = false begin res_file = File::dirname( file ) + "/#{@conf.lang}/" + File::basename( file ) open( res_file ) do |src| instance_eval( src.read, "(plugin/#{@conf.lang}/#{File::basename( res_file )})", 1 ) end @resource_loaded = true rescue IOError, Errno::ENOENT end File::open( file ) do |src| instance_eval( src.read, "(plugin/#{File::basename( file )})", 1 ) end end |