technicalpickles-has_markup 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,42 @@
1
+ = HasMarkup
2
+
3
+ I don't know about you, but I'm not too much of a fan of writing out raw HTML when I'm trying to belt out some blog posts. Keeping track of those pesky closing tags, escaping entities, and so on, can really get in the way of your creativity.
4
+
5
+ As a result, most blogs provide a simplified markup or some sort of editor. For technicalpickles.com[http://technicalpickles.com], I went with markdown[http://daringfireball.net/projects/markdown/].
6
+
7
+ I extracted this markup magic out of my blog, and this plugin is the result. It lets you:
8
+
9
+ * Specify a column contains markup
10
+ * Specify the syntax (markdown and textile, with markdown being the default)
11
+ * Specify if the markup column is required
12
+ * Generate a helper for generating the HTML
13
+ * Specify if the HTML should be cached in the database
14
+ * ... all using only one line
15
+
16
+ == Example
17
+
18
+ In your model:
19
+
20
+ class Post
21
+ has_markup :content, :syntax => :markdown, :required => true, :cache_html => true
22
+ end
23
+
24
+ Now post will have a 'content_html' method for generating the
25
+
26
+ So, you can use it in your view:
27
+
28
+ <h2><%= h @post.title %></h2>
29
+ <div>
30
+ <%= @post.cached_content_html %>
31
+ </div>
32
+
33
+ And you can test it easily using Shoulda:
34
+
35
+ require 'has_markup/shoulda'
36
+ class PostTest < Test::Unit::TestCase
37
+ should_have_markup :content, :syntax => :markdown, :required => true, :cache_html => true
38
+ end
39
+
40
+ == License
41
+
42
+ Copyright (c) 2008 Josh Nichols, released under the MIT license
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 2
4
2
  :major: 0
3
+ :minor: 1
4
+ :patch: 3
@@ -1,5 +1,3 @@
1
- require 'shoulda'
2
-
3
1
  module HasMarkup # :nodoc:
4
2
  # Shoulda macros for has_markup. These get added to <tt>Test::Unit::TestCase</tt>.
5
3
  module Shoulda
@@ -11,14 +9,14 @@ module HasMarkup # :nodoc:
11
9
  should_have_instance_methods "set_cached_#{column}_html"
12
10
  # TODO test that there's before_save action happening
13
11
  end
14
-
12
+
15
13
  # Ensure that markup is required.
16
14
  #
17
15
  # should_require_markup :content
18
16
  def should_require_markup(column)
19
- should_require_attributes column
17
+ should_validate_presence_of column
20
18
  end
21
-
19
+
22
20
  # Ensure that the model has markup. Accepts all the same options that has_markup does.
23
21
  #
24
22
  # should_have_markup :content
@@ -29,14 +27,11 @@ module HasMarkup # :nodoc:
29
27
  should_require_markup column if options[:required]
30
28
 
31
29
  should_cache_markup column if options[:cache_html]
32
- end
30
+ end
33
31
  end
34
32
  end
35
33
 
36
- module Test # :nodoc: all
37
- module Unit
38
- class TestCase
39
- extend HasMarkup::Shoulda
40
- end
41
- end
34
+ class Test::Unit::TestCase # :nodoc:
35
+ extend HasMarkup::Shoulda
42
36
  end
37
+
data/test/post_test.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  class PostTest < Test::Unit::TestCase
4
- should_have_markup :content, :required => true, :syntax => :markdown, :cache_html => true
5
-
4
+ should_have_markup :content,
5
+ :required => true,
6
+ :syntax => :markdown,
7
+ :cache_html => true
8
+
6
9
  context 'A new project without content' do
7
- setup do
8
- @post = Post.new
9
- end
10
-
10
+ setup { @post = Post.new }
11
+
11
12
  context "caching the content, when it's blank" do
12
13
  setup do
13
14
  @post.set_cached_content_html
@@ -17,7 +18,7 @@ class PostTest < Test::Unit::TestCase
17
18
  assert_nil @post.cached_content_html
18
19
  end
19
20
  end
20
-
21
+
21
22
  context "updating the content" do
22
23
  setup do
23
24
  @post.update_attributes(:content => 'hi')
@@ -27,6 +28,5 @@ class PostTest < Test::Unit::TestCase
27
28
  assert_equal '<p>hi</p>', @post.cached_content_html
28
29
  end
29
30
  end
30
-
31
31
  end
32
- end
32
+ end
data/test/test_helper.rb CHANGED
@@ -14,16 +14,17 @@ require 'active_record'
14
14
  require 'shoulda'
15
15
  require 'shoulda/active_record'
16
16
  require 'factory_girl'
17
+ require File.dirname(__FILE__) + '/../shoulda_macros/has_markup'
17
18
 
18
19
  RAILS_ROOT = File.dirname(__FILE__)
19
20
  require 'logger'
20
21
  RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/test.log")
21
22
 
22
23
  require File.dirname(__FILE__) + '/../init'
23
- require File.dirname(__FILE__) + '/post.rb'
24
+ require File.dirname(__FILE__) + '/post'
24
25
 
25
26
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
26
27
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
27
28
  ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'plugin_test'])
28
29
 
29
- load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")
30
+ load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technicalpickles-has_markup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-21 00:00:00 -08:00
12
+ date: 2009-05-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,30 +19,21 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README
24
24
  files:
25
25
  - VERSION.yml
26
- - lib/has_markup
26
+ - lib/has_markup.rb
27
27
  - lib/has_markup/active_record.rb
28
28
  - lib/has_markup/markdown.rb
29
- - lib/has_markup/shoulda.rb
30
29
  - lib/has_markup/textile.rb
31
30
  - lib/has_markup/version.rb
32
- - lib/has_markup.rb
33
- - test/database.yml
34
- - test/debug.log
35
- - test/post.rb
36
- - test/post_test.rb
37
- - test/schema.rb
38
- - test/test.log
39
- - test/test_helper.rb
40
- - shoulda_macros/has_markup_macros.rb
31
+ - shoulda_macros/has_markup.rb
32
+ - README
41
33
  has_rdoc: true
42
34
  homepage: http://github.com/technicalpickles/has_markup
43
35
  post_install_message:
44
36
  rdoc_options:
45
- - --inline-source
46
37
  - --charset=UTF-8
47
38
  require_paths:
48
39
  - lib
@@ -65,5 +56,8 @@ rubygems_version: 1.2.0
65
56
  signing_key:
66
57
  specification_version: 2
67
58
  summary: Manage markup close to home... right in the model! Caching, validation, etc
68
- test_files: []
69
-
59
+ test_files:
60
+ - test/post.rb
61
+ - test/post_test.rb
62
+ - test/schema.rb
63
+ - test/test_helper.rb
@@ -1 +0,0 @@
1
- require 'has_markup/shoulda'
data/test/database.yml DELETED
@@ -1,3 +0,0 @@
1
- plugin_test:
2
- adapter: sqlite3
3
- database: ':memory:'