Skip to content
This repository

Configuration option defaults.snippet.filter #174

Closed
wants to merge 2 commits into from

1 participant

Sam Whited
Sam Whited
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?

Sam Whited
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).

Sam Whited 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
Sam Whited
Collaborator

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

Sam Whited
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

Showing 2 unique commits by 1 author.

Dec 07, 2010
Sam Whited Added a config option 'defaults.snippet.filter' to set the default fi…
…lter for snippets
5a59267
Sam Whited 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
This page is out of date. Refresh to see the latest.
4  app/models/snippet.rb
@@ -16,4 +16,8 @@ class Snippet < ActiveRecord::Base
16 16
   
17 17
   object_id_attr :filter, TextFilter
18 18
 
  19
+  def after_initialize
  20
+    self.filter_id ||= Radiant::Config['defaults.snippet.filter'] if new_record?
  21
+  end
  22
+
19 23
 end
18  spec/models/snippet_spec.rb
@@ -5,8 +5,26 @@
5 5
   test_helper :validations
6 6
   
7 7
   before :each do
  8
+    @original_filter = Radiant::Config['defaults.snippet.filter']
8 9
     @snippet = @model = Snippet.new(snippet_params)
9 10
   end
  11
+
  12
+  after :each do
  13
+    Radiant::Config['defaults.snippet.filter'] = @original_filter
  14
+  end
  15
+
  16
+  it "should take the filter from the default filter" do
  17
+    Radiant::Config['defaults.snippet.filter'] = "Textile"
  18
+    snippet = Snippet.new :name => 'new-snippet'
  19
+    snippet.filter_id.should == "Textile"
  20
+  end
  21
+
  22
+  it "shouldn't override existing snippets filters with the default filter" do
  23
+    snippet = Snnippet.find(:first, :conditions => {:filter_id => nil})
  24
+    Radiant::Config['defaults.snippet.filter'] = "Textile"
  25
+    snippet.reload
  26
+    snippet.filter_id.should_not == "Textile"
  27
+  end
10 28
   
11 29
   it 'should validate length of' do
12 30
     {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.