copy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/copy/server.rb CHANGED
@@ -57,12 +57,16 @@ module Copy
57
57
  content = yield
58
58
  @_out_buf = old_buffer
59
59
 
60
+ # Remove newlines from the beginning
61
+ content.gsub!(/^\n/, '')
60
62
  # Get the first line from captured text.
61
63
  first_line = content.split("\n").first
62
64
  # Determine how much white space it has in front.
63
65
  white_space = first_line.match(/^(\s)*/)[0]
64
66
  # Remove that same amount of white space from the beginning of every line.
65
67
  content.gsub!(Regexp.new("^#{white_space}"), '')
68
+ # Remove all whitespace from the end, but keep the newline if present.
69
+ content.gsub!(/\s*$/, '') << "\n" if content =~ /\n/
66
70
 
67
71
  # Save the content so it can be edited.
68
72
  Copy::Storage.set(name, content) if Copy::Storage.connected?
@@ -9,7 +9,7 @@ module Copy
9
9
  property :id, Serial
10
10
  property :name, String, :unique_index => true
11
11
  property :content, Text
12
- end
12
+ end if defined?(DataMapper::Resource)
13
13
 
14
14
  def initialize(connection_url)
15
15
  DataMapper.setup(:default, connection_url)
data/lib/copy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Copy
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/test/server_test.rb CHANGED
@@ -113,6 +113,16 @@ class ServerCopyHelperTest < Test::Unit::TestCase
113
113
  assert_match %Q(<span class="_copy_editable" data-name="headline">Important!</span>), last_response.body
114
114
  end
115
115
 
116
+ test "copy helper indented in view" do
117
+ Copy::Storage.stubs(:connected?).returns(true)
118
+ Copy::Storage.expects(:get).with(:three).returns(nil)
119
+ Copy::Storage.expects(:set).with(:three, "three\n").returns(true)
120
+
121
+ get 'indented'
122
+ assert last_response.ok?, last_response.errors
123
+ assert_match %Q(<div class="_copy_editable" data-name="three"><p>three</p></div>), last_response.body
124
+ end
125
+
116
126
  test "partial rendering" do
117
127
  get 'renders_partials'
118
128
  assert last_response.ok?, last_response.errors
@@ -0,0 +1,9 @@
1
+ <div>
2
+ <div class="one">
3
+ <div class="two">
4
+ <% copy :three do %>
5
+ three
6
+ <% end %>
7
+ </div>
8
+ </div>
9
+ </div>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Javan Makhmali
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-19 00:00:00 -04:00
18
+ date: 2011-05-20 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -113,6 +113,7 @@ files:
113
113
  - test/test_app/views/about/us.html.erb
114
114
  - test/test_app/views/data/people.csv.erb
115
115
  - test/test_app/views/data/people.xml.erb
116
+ - test/test_app/views/indented.html.erb
116
117
  - test/test_app/views/index.html.erb
117
118
  - test/test_app/views/layout.html.erb
118
119
  - test/test_app/views/renders_partials.html.erb
@@ -164,6 +165,7 @@ test_files:
164
165
  - test/test_app/views/about/us.html.erb
165
166
  - test/test_app/views/data/people.csv.erb
166
167
  - test/test_app/views/data/people.xml.erb
168
+ - test/test_app/views/indented.html.erb
167
169
  - test/test_app/views/index.html.erb
168
170
  - test/test_app/views/layout.html.erb
169
171
  - test/test_app/views/renders_partials.html.erb