Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Configuration option defaults.snippet.filter #174

Closed
wants to merge 2 commits into from

1 participant

@SamWhited
Collaborator

What I've Done

I have added a configuration option to Radiant::Config called 'defaults.snippet.filter' to match the existing 'defaults.page.filter'.

As the title suggests, this option would allow a site administrator, extension developer, etc. to set the default filter for all snippets to something other than "None."

How to use it

In config/environment.rb or in an extension one might write:

Radiant::Config['defaults.snippet.filter'] = 'Markdown' if Radiant::Config.table_exists?

@SamWhited
Collaborator

I'm also working on fixing the spec to include this, but I can't test it on my current dev setup (rvm madness).

@SamWhited SamWhited Updated the snippet's spec to check that the filter will follow the d…
…efault

filter and to make sure the default filter will not overwrite filters which have
been manually set
9220755
@SamWhited
Collaborator

And now I've done it. I think that should work, but the second commit is w/o proper testing.

@SamWhited
Collaborator

Rebased into one commit and merged.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2010
  1. @SamWhited
  2. @SamWhited

    Updated the snippet's spec to check that the filter will follow the d…

    SamWhited authored
    …efault
    
    filter and to make sure the default filter will not overwrite filters which have
    been manually set
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 0 deletions.
  1. +4 −0 app/models/snippet.rb
  2. +18 −0 spec/models/snippet_spec.rb
View
4 app/models/snippet.rb
@@ -16,4 +16,8 @@ class Snippet < ActiveRecord::Base
object_id_attr :filter, TextFilter
+ def after_initialize
+ self.filter_id ||= Radiant::Config['defaults.snippet.filter'] if new_record?
+ end
+
end
View
18 spec/models/snippet_spec.rb
@@ -5,8 +5,26 @@
test_helper :validations
before :each do
+ @original_filter = Radiant::Config['defaults.snippet.filter']
@snippet = @model = Snippet.new(snippet_params)
end
+
+ after :each do
+ Radiant::Config['defaults.snippet.filter'] = @original_filter
+ end
+
+ it "should take the filter from the default filter" do
+ Radiant::Config['defaults.snippet.filter'] = "Textile"
+ snippet = Snippet.new :name => 'new-snippet'
+ snippet.filter_id.should == "Textile"
+ end
+
+ it "shouldn't override existing snippets filters with the default filter" do
+ snippet = Snnippet.find(:first, :conditions => {:filter_id => nil})
+ Radiant::Config['defaults.snippet.filter'] = "Textile"
+ snippet.reload
+ snippet.filter_id.should_not == "Textile"
+ end
it 'should validate length of' do
{
Something went wrong with that request. Please try again.