Skip to content

Commit

Permalink
config field templates added
Browse files Browse the repository at this point in the history
  • Loading branch information
danwrong committed Apr 10, 2009
1 parent be494de commit d54b776
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/evil/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def partial(template, options={})
haml(partial_name(template), options.merge( :layout => false ))
end

def render_config_field(field)
partial("plugins/fields/#{field.type}", :locals => { :field => field })
end

def not_authorized(message=nil)
status 401
halt haml(:login)
Expand Down
1 change: 1 addition & 0 deletions lib/evil/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Plugin
autoload :Tag, 'evil/plugin/tag'
autoload :Environment, 'evil/plugin/environment'
autoload :Filesystem, 'evil/plugin/filesystem'
autoload :Configuration, 'evil/plugin/configuration'

def self.evaluate(plugin_source)
Environment.module_eval plugin_source
Expand Down
4 changes: 2 additions & 2 deletions lib/evil/plugin/base.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module Evil
module Plugin
class Base
attr_reader :name
attr_reader :name, :configurator

def initialize(name, &block)
@name = name
@configurator = Configuration::Configurator.new
block.call(self)
end

Expand Down Expand Up @@ -43,7 +44,6 @@ def http
end

def configure
@configurator ||= Configuration::Configurator.new
yield @configurator
end

Expand Down
4 changes: 3 additions & 1 deletion lib/evil/plugin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Configuration

class ConfigField

attr_accessor :name, :type, :options

def initialize(type, name, options={})
@type, @name, @options = type, name, options
end
Expand All @@ -23,7 +25,7 @@ def text(field, options={})
end

def password(field, options={})
@fields << ConfigField.new(:text, field, options)
@fields << ConfigField.new(:password, field, options)
end

end
Expand Down
10 changes: 9 additions & 1 deletion test/example/plugins/test.evil
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
plugin 'Delicious' do |p|
p.description 'Include links from your delicious account'
p.http.base_uri 'https://api.del.icio.us/v1'
p.http.basic_auth 'user', 'pass'

p.configure do |c|
c.text :username
c.password :password
end

p.setup do
p.http.basic_auth p.config[:username], p.config[:password]
end

p.tag :recent do |args|
resp = p.http.get('/posts/recent', :query => args)
Expand Down
3 changes: 2 additions & 1 deletion views/plugins/_fields.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Evil::Plugin::Environment.plugins.each do |p|
%option{ :selected => (params[:plugin] == p.name ) }= p.name
- if @plugin
%p Config here...
- @plugin.configurator.fields.each do |field|
= render_config_field(field)
%p
%input.submit{ :value => 'Save', :type => 'submit' }

0 comments on commit d54b776

Please sign in to comment.