mongoid-textile 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ - ree
7
+ - rbx-18mode
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.2
2
+
3
+ ### Improvements
4
+
5
+ * Removing InstanceMethods module inside of ActiveSupport::Concern because it is deprecated on ActiveSupport 3.2.0.
6
+
1
7
  ## 0.0.1 (2012-01-11)
2
8
 
3
9
  Initial release.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Mongoid::Textile
1
+ # Mongoid::Textile [![Build Status](https://secure.travis-ci.org/tiagogodinho/mongoid-textile.png)](http://travis-ci.org/tiagogodinho/mongoid-textile) [![Build Status](https://gemnasium.com/tiagogodinho/mongoid-textile.png?travis)](http://gemnasium.com/tiagogodinho/mongoid-textile)
2
2
 
3
3
  Textile texts directly from MongoDB.
4
4
 
@@ -23,6 +23,7 @@ Or install it yourself as:
23
23
  ``` ruby
24
24
  class Article
25
25
  include Mongoid::Document
26
+ include Mongoid::Textile
26
27
 
27
28
  field :text
28
29
 
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require 'rspec/core/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
- task default: 'spec'
7
+ task :default => 'spec'
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Textile
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require "mongoid-textile/version"
2
- require 'active_support/concern'
3
- require 'mongoid'
4
- require 'redcloth'
2
+ require "active_support/concern"
3
+ require "mongoid"
4
+ require "redcloth"
5
5
 
6
6
  module Mongoid
7
7
  module Textile
@@ -11,20 +11,25 @@ module Mongoid
11
11
  before_save :textile_to_html
12
12
  end
13
13
 
14
- module InstanceMethods
15
- def textile_to_html
16
- textile_fields = fields.collect{|f| f.first}.select{|f| f =~ /\w+_formatted/}
17
- textile_fields.each do |f|
18
- value = self.send(f.split(/(\w+)_formatted/).reject(&:blank?).first).nil? ? "" : self.send(f.split(/(\w+)_formatted/).reject(&:blank?).first)
19
- self.send "#{f}=".to_sym, RedCloth.new(value).to_html
20
- end
14
+ def textile_to_html
15
+ textile_fields.each do |textile_field_name|
16
+ field_name = textile_field_name.gsub(/_formatted/, '')
17
+ value = self.send(field_name)
18
+ formatted_text = RedCloth.new(value.to_s).to_html
19
+ self.send("#{textile_field_name}=", formatted_text)
21
20
  end
22
21
  end
23
22
 
23
+ private
24
+
25
+ def textile_fields
26
+ fields.collect{ |field| field.first }.select{ |field_name| field_name =~ /\w+_formatted/ }
27
+ end
28
+
24
29
  module ClassMethods
25
30
  def textlize(*fields)
26
- fields.each do |f|
27
- field("#{f}_formatted")
31
+ fields.each do |field_name|
32
+ field("#{field_name}_formatted")
28
33
  end
29
34
  end
30
35
  end
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: UTF-8
2
+
2
3
  require File.expand_path('../lib/mongoid-textile/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
@@ -1,8 +1,4 @@
1
- require 'spec_helper'
2
-
3
- Mongoid.configure do |config|
4
- config.master = Mongo::Connection.new.db('mongoid-textile')
5
- end
1
+ require "spec_helper"
6
2
 
7
3
  class Article
8
4
  include Mongoid::Document
@@ -14,13 +10,36 @@ class Article
14
10
  end
15
11
 
16
12
  describe Mongoid::Textile do
17
- let(:article) { Article.create(text: 'h1. proud to be a rails developer') }
13
+ let(:article) { Article.create(:text => "h1. proud to be a rails developer") }
18
14
 
19
- it 'should build a dynamic field for textilized fields' do
15
+ it "should build a dynamic field for textilized fields" do
20
16
  article.should respond_to(:text_formatted)
21
17
  end
22
18
 
23
- it 'should set formatted field from textile to html' do
24
- article.text_formatted.should eq('<h1>proud to be a rails developer</h1>')
19
+ it "should set formatted field from textile to html" do
20
+ article.text_formatted.should eq("<h1>proud to be a rails developer</h1>")
21
+ end
22
+
23
+ it "should change textlized text" do
24
+ article.text = "p. ruby makes me happy"
25
+ article.save
26
+
27
+ article.text_formatted.should eq("<p>ruby makes me happy</p>")
28
+ end
29
+
30
+ context "when text is nil" do
31
+ let(:article) { Article.create(:text => nil) }
32
+
33
+ it "should set formatted field with an empty string" do
34
+ article.text_formatted.should eq("")
35
+ end
36
+ end
37
+
38
+ context "when text is empty" do
39
+ let(:article) { Article.create(:text => "") }
40
+
41
+ it "should set formatted field with an empty string" do
42
+ article.text_formatted.should eq("")
43
+ end
25
44
  end
26
45
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,29 @@
1
- require 'mongoid-textile'
1
+ require "mongoid-textile"
2
+
3
+ RSpec.configure do |config|
4
+ # Remove this line if you don"t want RSpec"s should and should_not
5
+ # methods or matchers
6
+ require "rspec/expectations"
7
+ config.include RSpec::Matchers
8
+
9
+ # == Mock Framework
10
+ config.mock_with :rspec
11
+
12
+ config.color_enabled = true
13
+ config.full_backtrace = true
14
+
15
+ config.before :suite do
16
+ Mongoid.configure do |config|
17
+ config.master = Mongo::Connection.new.db("mongoid-textile")
18
+ end
19
+ end
20
+
21
+ config.after :each do
22
+ Mongoid.master.collections.select {|c| c.name !~ /^system/ }.each(&:drop)
23
+ end
24
+
25
+ config.after :suite do
26
+ Mongoid.master.connection.drop_database("mongoid-textile")
27
+ Mongoid.master.connection.close
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-textile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-01-12 00:00:00.000000000 Z
13
+ date: 2012-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: RedCloth
17
- requirement: &2156040280 !ruby/object:Gem::Requirement
17
+ requirement: &2156148240 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 4.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156040280
25
+ version_requirements: *2156148240
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &2156039600 !ruby/object:Gem::Requirement
28
+ requirement: &2156147620 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156039600
36
+ version_requirements: *2156147620
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2156039020 !ruby/object:Gem::Requirement
39
+ requirement: &2156147060 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - =
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.8.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156039020
47
+ version_requirements: *2156147060
48
48
  description: Textile texts directly from MongoDB.
49
49
  email:
50
50
  - contato@lucasrenan.com
@@ -55,6 +55,7 @@ extra_rdoc_files: []
55
55
  files:
56
56
  - .gitignore
57
57
  - .rspec
58
+ - .travis.yml
58
59
  - CHANGELOG.md
59
60
  - Gemfile
60
61
  - Gemfile.lock