Skip to content

Commit

Permalink
* plugin/01sp.rb: no more revision information, links to sources and …
Browse files Browse the repository at this point in the history
…comments

* plugin/01sp.rb: user friendlier sequence of plugin list


git-svn-id: https://tdiary.svn.sourceforge.net/svnroot/tdiary/trunk/core@1585 7f22e88f-374d-0410-998f-c91420d97ba2
  • Loading branch information
zunda committed Oct 1, 2003
1 parent 32564b5 commit e00cf22
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 212 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2003.10.01 zunda <zunda at freeshell.org>
* plugin/01sp.rb: no more revision information, links to sources and comments
* plugin/01sp.rb: user friendlier sequence of plugin list

2003.10.01 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* tdiary.rb: change security error message in Plugin#add_cookie.

Expand Down
209 changes: 43 additions & 166 deletions plugin/01sp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 01sp.rb - select-plugins plugin $Revision: 1.4 $
# 01sp.rb - select-plugins plugin $Revision: 1.5 $

=begin ChangeLog
See ../ChangeLog for changes after this.
Expand Down Expand Up @@ -38,184 +38,66 @@

# get option
def sp_option( key )
@conf["#{SP_PREFIX}.#{key}"] || nil
@conf["#{SP_PREFIX}.#{key}"]
end

# list of plugins
def sp_list_plugins
r = ''
if sp_option( 'showmandatory' ) then
r << @sp_label_mandatory
r << "<ul>\n"
@sp_defs.keys.sort.each do |file|
r << <<-_HTML
<li>#{CGI::escapeHTML( file )}
#{'<a href="' + @conf.update + '?conf=' + SP_PREFIX + ';help=d' + CGI::escape( file ) + '">' + @sp_label_comment + '</a>' if sp_option( 'showhelp' )}
#{', ' if sp_option( 'showhelp' ) and sp_option( 'showsource' )}
#{'<a href="' + @conf.update + '?conf=' + SP_PREFIX + ';src=d' + CGI::escape( file ) + '">' + @sp_label_source + '</a>' if sp_option( 'showsource' )}
#{"(#{@sp_ver[ 'd' + file ]})" if @sp_ver[ 'd' + file ]}
_HTML
end
r << "</ul>\n"
r << @sp_label_optional
end # if sp_option( 'showmandatory' )
unless @sp_opt.empty? then
known = ( sp_option( 'selected' ) ? sp_option( 'selected' ).split( /\n/ ) : []) + ( sp_option( 'notselected' ) ? sp_option( 'notselected' ).split( /\n/ ) : [])
r << @sp_label_optional2
r << "<ul>\n"
@sp_opt.keys.sort.each do |file|
r << <<-_HTML
<li><input name="sp.#{CGI::escapeHTML( file )}" type="checkbox" value="t"#{((sp_option( 'selected' ) and sp_option( 'selected' ).split( /\n/ ).include?( file )) or (sp_option( 'usenew' ) and not known.include?( file ))) ? ' checked' : ''}>
#{CGI::escapeHTML( file )}
#{'<a href="' + @conf.update + '?conf=' + SP_PREFIX + ';help=o' + CGI::escape( file ) + '">' + @sp_label_comment + '</a>' if sp_option( 'showhelp' )}
#{', ' if sp_option( 'showhelp' ) and sp_option( 'showsource' )}
#{'<a href="' + @conf.update + '?conf=' + SP_PREFIX + ';src=o' + CGI::escape( file ) + '">' + @sp_label_source + '</a>' if sp_option( 'showsource' )}
#{'(' + @sp_ver[ 'o' + file ] + ')' if @sp_ver[ 'o' + file ]}
#{@sp_label_new unless known.include?( file )}
_HTML
end
r << "</ul>\n"
else
r << @sp_label_noplugin
end
r
end

# comments
# file is prefixed with 'o' (optional/selectable) or 'd' (default/mandatory)
def sp_help( file )
if sp_option( 'showhelp' ) and @sp_src[file] then
if @sp_resource[file] then
commentsource = @sp_resource[file]
else
commentsource = @sp_src[file]
end
if /^=begin$(.*?)^=end$/m =~ commentsource then
help = $1
elsif /((^#.*?\n)+)/ =~ commentsource then
help = $1.gsub( /^#/, '' )
end
if help then
case @conf.lang
when 'en'
<<-_HTML
<p>Comments in #{CGI::escapeHTML( file.slice( 1..-1 ) )}.#{' Click <a href="' + @conf.update + '?conf=' + SP_PREFIX + ';src=' + CGI::escape( file ) + '">here</a> for the source.' if sp_option( 'showsource' )}</p>
<p><a href="#{@conf.update}?conf=#{SP_PREFIX}">Back</a>
<hr>
<pre>#{CGI::escapeHTML( help )}</pre>
<hr>
_HTML
else
<<-_HTML
<p>#{CGI::escapeHTML( file.slice( 1..-1 ) )}の注釈です。#{'ソースを見るには、<a href="' + @conf.update + '?conf=' + SP_PREFIX + ';src=' + CGI::escape( file ) + '">こちら</a>。' if sp_option( 'showsource' )}</p>
<p><a href="#{@conf.update}?conf=#{SP_PREFIX}">戻る</a>
<hr>
<pre>#{CGI::escapeHTML( help )}</pre>
<hr>
r += @sp_label_please_select
used = sp_option( 'selected' ) ? sp_option( 'selected' ).split( /\n/ ) : []
used.reject! { |plugin| not @sp_opt.keys.include?( plugin ) }
notused = sp_option( 'notselected' ) ? sp_option( 'notselected' ).split( /\n/ ) : []
notused.reject! { |plugin| not @sp_opt.keys.include?( plugin ) }
unknown = @sp_opt.keys.dup
unknown.reject! { |plugin| used.include?( plugin ) }
unknown.reject! { |plugin| notused.include?( plugin ) }
# new plugins
unless unknown.empty? then
r += @sp_label_new
r += "<ul>\n"
unknown.sort.each do |file|
r += <<-_HTML
<li><input name="#{SP_PREFIX}.#{CGI::escapeHTML( file )}" type="checkbox" value="t"#{sp_option( 'usenew' ) ? ' checked' : ''}>#{CGI::escapeHTML( file )}
_HTML
end
else
case @conf.lang
when 'en'
<<-_HTML
<p>There is no comment in #{CGI::escapeHTML( file.slice( 1..-1 ))}.#{' Click <a href="' + @conf.update + '?conf=' + SP_PREFIX + ';src=' + CGI::escape( file ) + '">here</a> for the source.' if sp_option( 'showsource' ) and @sp_src[file]}</p>
r += "</ul>\n"
end
# selected plugins
unless used.empty? then
r += @sp_label_used
r += "<ul>\n"
used.sort.each do |file|
r += <<-_HTML
<li><input name="#{SP_PREFIX}.#{CGI::escapeHTML( file )}" type="checkbox" value="t" checked>#{CGI::escapeHTML( file )}
_HTML
else
<<-_HTML
<p>#{CGI::escapeHTML( file.slice( 1..-1 ))}の注釈はありません。#{'ソースを見るには、<a href="'+ @conf.update + '?conf=' + SP_PREFIX + ';src=' + CGI::escape( file ) + '">こちら</a>。' if sp_option( 'showsource' ) and @sp_src[file]}</p>
end
r += "</ul>\n"
end
# not selected plugins
unless notused.empty? then
r += @sp_label_notused
r += "<ul>\n"
notused.sort.each do |file|
r += <<-_HTML
<li><input name="#{SP_PREFIX}.#{CGI::escapeHTML( file )}" type="checkbox" value="t">#{CGI::escapeHTML( file )}
_HTML
end
r += "</ul>\n"
end
else
case @conf.lang
when 'en'
<<-_HTML
<p>Comments from #{CGI::escapeHTML( file.slice( 1..-1 ))} can't be viewed.</p>
_HTML
else
<<-_HTML
<p>#{CGI::escapeHTML( file.slice( 1..-1 ))}の注釈は見られません。</p>
_HTML
end
r += @sp_label_noplugin
end
r
end

# source
# file is prefixed with 'o' (optional/selectable) or 'd' (default/mandatory)
def sp_src( file )
if sp_option( 'showsource' ) and @sp_src[file] then
case @conf.lang
when 'en'
<<-_HTML
<p>Source for #{CGI::escapeHTML( file.slice( 1..-1 ) )}</p>
<p><a href="#{@conf.update}?conf=#{SP_PREFIX}">Back</a>
<hr>
<pre>#{CGI::escapeHTML( @sp_src[file] )}</pre>
<hr>
_HTML
else
<<-_HTML
<p>#{CGI::escapeHTML( file.slice( 1..-1 ) )}のソースです。</p>
<p><a href="#{@conf.update}?conf=#{SP_PREFIX}">戻る</a>
<hr>
<pre>#{CGI::escapeHTML( @sp_src[file] )}</pre>
<hr>
_HTML
end
else
case @conf.lang
when 'en'
<<-_HTML
<p>Source for #{CGI::escapeHTML( file.slice( 1..-1 ) )} can't be viewed.</p>
_HTML
else
<<-_HTML
<p>#{CGI::escapeHTML( file.slice( 1..-1 ) )}のソースは見られません。</p>
_HTML
end
end
end

if @cgi.params['conf'][0] == SP_PREFIX then
# mandatory plugins
if sp_option( 'showmandatory' ) then
@sp_defs = {} # path to the plugin
def_paths = Dir::glob( ( @conf.plugin_path || "#{PATH}/plugin" ) + '/*.rb' )
def_paths.each do |path|
@sp_defs[ File.basename( path ) ] = path
end
end
# selectable plugins
@sp_opt = {} # path to the plugin
opt_paths = Dir::glob( "#{@sp_path}/*.rb" )
opt_paths.each do |path|
Dir::glob( "#{@sp_path}/*.rb" ).each do |path|
@sp_opt[ File.basename( path ) ] = path
end
# other information
@sp_ver = {} # revision number of the plugin
@sp_src = {} # source
@sp_resource = {} # l10n resource
[['d', def_paths], ['o', opt_paths]].each do |prefix, paths|
next unless paths
paths.each do |path|
file = File.basename( path )
source = File.open( path.untaint ) { |f| f.read }
# source
@sp_src[ prefix + file ] = source
# versions
if /\$(Revision.*?)\s*\$/ =~ source then
@sp_ver[ prefix + file ] = $1
elsif /\$(Id.*?)\s*\$/ =~ source then
@sp_ver[ prefix + file ] = $1
end
# l10n resource
rcpath = File.dirname( path ) + '/' + @conf.lang + '/' + File.basename( path )
rcpath.untaint
if File.exist?( rcpath ) then
@sp_resource[ prefix + file ] = File.open( rcpath ) { |f| f.read }
end
end
end

# update options
# we have to do this when we are eval'ed to update the config menu
Expand All @@ -235,14 +117,7 @@ def sp_src( file )
# configuration menu
# options are updated when we are eval'ed
add_conf_proc( SP_PREFIX, @sp_label ) do
r = @sp_label_description.dup
if @cgi.params['help'][0] then
r += sp_help( @cgi.params['help'][0] )
elsif sp_option( 'showsource' ) and @cgi.params['src'][0] then
r += sp_src( @cgi.params['src'][0] )
else
r += sp_list_plugins
end
r = @sp_label_description.dup + sp_list_plugins
end

# Finally, we can eval the selected plugins as tdiary.rb does
Expand All @@ -254,6 +129,8 @@ def sp_src( file )
load_plugin( path.untaint )
@plugin_files << path
rescue IOError, Errno::ENOENT # for now, just ignore missing plugins
rescue Exception
raise PluginError::new( "Plugin error in '#{File::basename( path )}'.\n#{$!}" )
end
end
end
30 changes: 6 additions & 24 deletions plugin/en/01sp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# English resources of 01sp.rb $Revision: 1.2 $
# English resources of 01sp.rb $Revision: 1.3 $

=begin
= Select-plugin plugin
Expand Down Expand Up @@ -26,18 +26,6 @@
Directory name where the optional plugins are, relative from the
directory where tdiary.rb is or absolute.
:@options['sp.showhelp']
Define true when you want the users (writers of the diaries) to see
the comments of the plugins.
:@options['sp.showsource']
Define true when you want the users to see the sources of the
plugins.
:@options['sp.showmandatory']
Define true when you want to show what plugins are installed in the
non-optional path.
:@options['sp.usenew']
Define true if you want to the users to try a newly installed plugin.
Newly installed plugins are detected next time when the user configures
Expand All @@ -49,18 +37,12 @@
Permission is granted for use, copying, modification, distribution, and
distribution of modified versions of this work under the terms of GPL
version 2 or later.
You should be able to find the latest version of this pluigin at
((<URL:http://zunda.freeshell.org/d/plugin/select_plugins.rb>)).
=end

@sp_label = 'Plugin selection'
@sp_label_description = '<p>Selects which plugins you want to use.</p>'
@sp_label_mandatory = %Q|<h4>Mandatory plugins</h4>
<p>These plugins must always be used.</p>|
@sp_label_optional = "<h4>Optional plugins</h4>"
@sp_label_optional2 = "<p>Please check the plugins you want to use.</p>"
@sp_label_comment = "comments"
@sp_label_source = "source"
@sp_label_new = '[New! Try this.]'
@sp_label_noplugin = "<li>There is no optional plugins."
@sp_label_please_select = '<p>Please check the plugins you want to use.</p>'
@sp_label_new = '<h4>New! Give it a try.</h4>'
@sp_label_used = '<h4>Being used</h4>'
@sp_label_notused = '<h4>Currently not used</h4>'
@sp_label_noplugin = '<p>There is no optional plugins.</p>'
29 changes: 7 additions & 22 deletions plugin/ja/01sp.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Japanese resources of 01sp.rb $Revision: 1.2 $
# Japanese resources of 01sp.rb $Revision: 1.3 $

=begin
= プラグイン選択プラグイン((-$Id: 01sp.rb,v 1.2 2003-09-30 09:41:21 tadatadashi Exp $-))
= プラグイン選択プラグイン((-$Id: 01sp.rb,v 1.3 2003-10-01 14:47:30 zunda Exp $-))
Please see below for an English description.
== 概要
Expand Down Expand Up @@ -31,15 +31,6 @@
'plugin/selectable'などと、選択できるプラグインのあるディレクトリを、
tdiary.rbのあるディレクトリからの相対パスか絶対パスで指定してください。
:@options['sp.showhelp']
注釈を表示したい場合にはtrueに設定してください。
:@options['sp.showsource']
ソースを表示したい場合にはtrueに設定してください。
:@options['sp.showmandatory']
絶対に必要なプラグインの情報を表示したい場合にはtrueに設定してください。
:@options['sp.usenew']
新しくインストールされたプラグインをデフォルトで使うようにする場合は
trueに設定してください。新しくインストールされたプラグインを検出するの
Expand All @@ -55,19 +46,13 @@
Permission is granted for use, copying, modification, distribution, and
distribution of modified versions of this work under the terms of GPL
version 2 or later.
You should be able to find the latest version of this pluigin at
((<URL:http://zunda.freeshell.org/d/plugin/select_plugins.rb>)).
=end


@sp_label = 'プラグイン選択'
@sp_label_description = '<p>どのプラグインを使うか選択します。</p>'
@sp_label_mandatory = %Q|<h4>常に使われるプラグイン</h4>
<p>使うかどうか選択することはできません。</p>|
@sp_label_optional = "<h4>使うかどうか選択できるプラグイン</h4>"
@sp_label_optional2 = "<p>有効にしたいプラグインにチェックしてください。</p>"
@sp_label_comment = "注釈"
@sp_label_source = "ソース"
@sp_label_new = '[新入荷!お試しください。]'
@sp_label_noplugin = "<li>選択可能なプラグインはありません。"
@sp_label_please_select = '<p>有効にしたいプラグインにチェックしてください。</p>'
@sp_label_new = '<h4>新入荷!お試しください</h4>'
@sp_label_used = '<h4>使用中</h4>'
@sp_label_notused = '<h4>休憩中</h4>'
@sp_label_noplugin = '<p>選択可能なプラグインはありません。</p>'

0 comments on commit e00cf22

Please sign in to comment.