temp_editor 0.0.1 → 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c399a577be7fb9123f0c642f9810341564d89f9a
4
+ data.tar.gz: 0d032e0a5ddc599dbd6e6a7bf057730e2584e341
5
+ SHA512:
6
+ metadata.gz: 4b8016d7e222f52413ffaba271420c68e67383cf1194d6d79ee3df8db8c9c70a9ec34cf0d0eb5d1aead4db5cd520ca334044574e1acc976e1504b774aa0bb4bf
7
+ data.tar.gz: 54df6463106eca072cd4f83fda4af84cd488211247bb8fde5fa5d928e946c02f86c081fe437b814c9521370f45225bb34ddab97ebc7c879446e1228ef4fd2abc
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'temp_editor'
3
+
4
+ # requirements:
5
+ # - Dayone: http://dayoneapp.com/
6
+ # - Dayone-cli: http://dayoneapp.com/cli
7
+ class Dayone
8
+ COMMAND = "dayone"
9
+
10
+ def initialize(options = [])
11
+ editor(options).edit
12
+ end
13
+
14
+ private
15
+ def editor(options)
16
+ TempEditor.new(["dayone", ".markdown"]) do |file|
17
+ cmd = command(options)
18
+ File.popen(cmd, 'w'){|io| io.write(file.read) }
19
+ end
20
+ end
21
+
22
+ def command(options)
23
+ [COMMAND, options, 'new'].flatten.join(' ')
24
+ end
25
+ end
26
+
27
+ if __FILE__ == $0
28
+ Dayone.new ARGV
29
+ end
@@ -1,6 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
1
+ #!/usr/bin/env ruby
4
2
  require 'temp_editor'
5
3
 
6
4
  class RemoteResource
@@ -0,0 +1,3 @@
1
+ class TempEditor
2
+ VERSION = '0.1.0'
3
+ end
data/lib/temp_editor.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'tempfile'
3
+ require 'temp_editor/version'
3
4
 
4
5
  class TempEditor
5
- VERSION = '0.0.1'
6
-
7
6
  class EditorConfigureError < StandardError; end
8
7
 
9
8
  attr_reader :tempfile
10
9
 
11
- def initialize(basename, *rest)
10
+ def initialize(basename, *rest, &after)
12
11
  @tempfile = Tempfile.new(basename, *rest)
12
+ after(&after) if block_given?
13
13
  end
14
14
 
15
15
  def before(&block)
@@ -14,6 +14,22 @@ describe TempEditor do
14
14
  end
15
15
 
16
16
 
17
+ describe '.new' do
18
+ context 'with callback' do
19
+ it 'should register after callback' do
20
+ result = nil
21
+ editor = TempEditor.new 'example' do |file|
22
+ result = file.read.chomp
23
+ end
24
+ editor.editor = 'echo "text" >'
25
+
26
+ expect {
27
+ editor.edit
28
+ }.to change{ result }.from(nil).to('text')
29
+ end
30
+ end
31
+ end
32
+
17
33
  describe "#edit" do
18
34
  include_context "setup common @temp_editor instance"
19
35
 
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temp_editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - riverpuro
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Edit temporary file with ENV['EDITOR']
@@ -34,40 +31,41 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .rspec
34
+ - ".gitignore"
35
+ - ".rspec"
39
36
  - Gemfile
40
37
  - LICENSE.txt
41
38
  - README.md
42
39
  - Rakefile
40
+ - examples/dayone.rb
43
41
  - examples/remote_editor.rb
44
42
  - lib/temp_editor.rb
43
+ - lib/temp_editor/version.rb
45
44
  - spec/spec_helper.rb
46
45
  - spec/temp_editor_spec.rb
47
46
  - temp_editor.gemspec
48
47
  homepage: https://github.com/riverpuro/temp_editor
49
48
  licenses: []
49
+ metadata: {}
50
50
  post_install_message:
51
51
  rdoc_options: []
52
52
  require_paths:
53
53
  - lib
54
54
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
55
  requirements:
57
- - - ! '>='
56
+ - - ">="
58
57
  - !ruby/object:Gem::Version
59
58
  version: '0'
60
59
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
60
  requirements:
63
- - - ! '>='
61
+ - - ">="
64
62
  - !ruby/object:Gem::Version
65
63
  version: '0'
66
64
  requirements: []
67
65
  rubyforge_project:
68
- rubygems_version: 1.8.24
66
+ rubygems_version: 2.2.0
69
67
  signing_key:
70
- specification_version: 3
68
+ specification_version: 4
71
69
  summary: Edit temporary file with ENV['EDITOR']
72
70
  test_files:
73
71
  - spec/spec_helper.rb