mediumize 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3f4f4897578775c0af86a686d005a5d52280dd3
4
- data.tar.gz: 00a2e65dd2fef4918f76f2f7d55bca794bf7227f
3
+ metadata.gz: 1c9ffcfc1c79c1f5305e307ee22c7526dd96cc72
4
+ data.tar.gz: ce3d2d0fc18031279ed416887ba92c83c37462e5
5
5
  SHA512:
6
- metadata.gz: e2aa41dc42d8271aaa4540f4c46f0c7c7e88c527e7d7628a47ae47ee06cd1ef66f14035ffe35d603492605a913c83b37ae8a530490abd354c8e9cdd763fd0d39
7
- data.tar.gz: 2b9e2064b3944a15852dcd069546e117fe42362d0a3f14b92e56efd331d603445e1c04f3131991e9f82fafe43a8dc2757c2ff9b3e7ae4a372b505518e193f7c7
6
+ metadata.gz: d4ccae79b21f13d71b2acb65add678d8ad55ff8feec2671ab57c86b8c31f4fb8fd857b0e93122e9c6650094a16001fc2d3adc4d305263acf44aaf70ee21bf379
7
+ data.tar.gz: 4fd7f92e0731abab9ade39884096e9bf6932bc6be49e0f3d4f0cbdf4f15a65f88d5de5df6ab317d8924a67891faac11c5ff3ac8e45982f990ddfb0a90581aa3f
@@ -15,6 +15,7 @@ begin
15
15
  o = Slop::Options.new
16
16
  o.bool '-m', '--frontmatter', '(default: true) Use if files contain a frontmatter', default: true
17
17
  o.bool '-h', '--headline', '(default: true) Use if you want to insert a main headline in addition to a title', default: true
18
+ o.bool '-d', '--dryrun', '(default: false) Perform a dry run (publish to STDOUT, and not to Medium)', default: false
18
19
  o.string '-t', '--token', 'Your Medium integration token'
19
20
  o.string '-b', '--base_url', 'Your blog base url, for relative images and resources. e.g. http://acme.org/blog'
20
21
  o.on '--version', 'print the version' do
@@ -27,11 +28,16 @@ begin
27
28
  end
28
29
  opts = Slop::Parser.new(o).parse(ARGV)
29
30
 
30
- unless opts[:token]
31
+ if !opts[:token] && !opts[:dryrun]
31
32
  bail "Error: please provide a token", opts
32
33
  end
33
34
 
34
- p = Mediumize::Publisher.new(opts.to_h)
35
+ p = if opts[:dryrun]
36
+ Mediumize::StdoutPublisher.new(opts.to_h)
37
+ else
38
+ Mediumize::MediumPublisher.new(opts.to_h)
39
+ end
40
+
35
41
  opts.arguments.each do |arg|
36
42
  res = p.publish(arg)
37
43
  badge = "✔ draft ".colorize(:green)
@@ -1,9 +1,7 @@
1
1
  require "mediumize/version"
2
- require "mediumize/frontmatter"
3
- require "mediumize/normalizers/links"
4
- require "mediumize/normalizers/title"
5
2
  require "mediumize/renderer"
6
- require "medium"
3
+ require "mediumize/medium_publisher"
4
+ require "mediumize/stdout_publisher"
7
5
 
8
6
  module HashExt
9
7
  def slice(*keys)
@@ -13,38 +11,6 @@ module HashExt
13
11
  end
14
12
 
15
13
  Hash.send(:include, HashExt)
16
-
17
- # patch medium api, upstream fix
18
- # with time, replace medium-sdk-ruby entirely
19
- module Medium
20
- class Posts
21
- def create(user, opts)
22
- @client.post "users/#{user['data']['id']}/posts",
23
- build_request_with(opts)
24
- end
25
- end
26
- end
27
-
28
14
  module Mediumize
29
- class Publisher
30
- def initialize(opts={})
31
- @opts = opts
32
- @renderer = Mediumize::Renderer.new(opts)
33
- @client = Medium::Client.new(:integration_token => opts[:token])
34
- end
35
-
36
- def publish(file)
37
- content = @renderer.render(File.read(file), file)
38
- fetch_me!
39
-
40
- res = @client.posts.create(@me, content.merge(:publish_status => "draft"))
41
- data = Medium::Client.validate(res)["data"]
42
- { :id => data["id"], :url => data["url"] }
43
- end
44
-
45
- def fetch_me!
46
- @me ||= @client.users.me
47
- end
48
- end
49
15
  end
50
16
 
@@ -0,0 +1,18 @@
1
+ require 'redcarpet'
2
+ require 'rouge'
3
+ require 'rouge/plugins/redcarpet'
4
+
5
+ module Mediumize
6
+ class Markdown
7
+ class HTMLWithRouge < Redcarpet::Render::HTML
8
+ include Rouge::Plugins::Redcarpet
9
+ end
10
+ def initialize
11
+ @redcarpet = Redcarpet::Markdown.new(HTMLWithRouge,:fenced_code_blocks => true)
12
+ end
13
+ def render(content)
14
+ @redcarpet.render(content)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,37 @@
1
+ require "medium"
2
+
3
+
4
+ # patch medium api, upstream fix
5
+ # with time, replace medium-sdk-ruby entirely
6
+ module Medium
7
+ class Posts
8
+ def create(user, opts)
9
+ @client.post "users/#{user['data']['id']}/posts",
10
+ build_request_with(opts)
11
+ end
12
+ end
13
+ end
14
+
15
+
16
+ module Mediumize
17
+ class MediumPublisher
18
+ def initialize(opts={})
19
+ @opts = opts
20
+ @renderer = Mediumize::Renderer.new(opts)
21
+ @client = Medium::Client.new(:integration_token => opts[:token])
22
+ end
23
+
24
+ def publish(file)
25
+ content = @renderer.render(File.read(file), file)
26
+ fetch_me!
27
+
28
+ res = @client.posts.create(@me, content.merge(:publish_status => "draft"))
29
+ data = Medium::Client.validate(res)["data"]
30
+ { :id => data["id"], :url => data["url"], :content => content }
31
+ end
32
+
33
+ def fetch_me!
34
+ @me ||= @client.users.me
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,8 @@
1
- require "github/markup"
2
1
  require "mediumize/frontmatter"
2
+ require "mediumize/markdown"
3
+ require "mediumize/normalizers/links"
4
+ require "mediumize/normalizers/title"
5
+
3
6
  require "nokogiri"
4
7
 
5
8
  module Mediumize
@@ -12,6 +15,7 @@ module Mediumize
12
15
  if @opts[:base_url]
13
16
  @normalizers << Normalizers::Links.new(@opts[:base_url])
14
17
  end
18
+ @markdown = Markdown.new
15
19
  end
16
20
 
17
21
  def render(content, file, opts={})
@@ -20,7 +24,7 @@ module Mediumize
20
24
  opts[:title] ||= meta["title"]
21
25
  end
22
26
 
23
- markup = GitHub::Markup.render(file, content)
27
+ markup = @markdown.render(content)
24
28
  doc = Nokogiri::HTML(markup)
25
29
 
26
30
  @normalizers.each{|n| doc = n.normalize(doc) }
@@ -0,0 +1,15 @@
1
+ module Mediumize
2
+ class StdoutPublisher
3
+ def initialize(opts={})
4
+ @renderer = Mediumize::Renderer.new(opts)
5
+ end
6
+
7
+ def publish(file)
8
+ content = @renderer.render(File.read(file), file)
9
+ puts content[:content]
10
+ { :id => "id/dry-run", :url => "http://example.com/dry-run", :content => content }
11
+ end
12
+
13
+ end
14
+ end
15
+
@@ -1,3 +1,3 @@
1
1
  module Mediumize
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency 'nokogiri', '~> 1.6.7'
23
- spec.add_dependency 'github-markup', '~> 1.4.0'
24
- spec.add_dependency 'kramdown', '~> 1.9.0'
23
+ spec.add_dependency 'redcarpet'
24
+ spec.add_dependency 'rouge'
25
25
  spec.add_dependency 'medium-sdk-ruby', '~> 1.0.1'
26
26
  spec.add_dependency 'slop', '~> 4.2.1'
27
27
  spec.add_dependency 'colorize', '~> 0.7.7'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediumize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dotan Nahum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.7
27
27
  - !ruby/object:Gem::Dependency
28
- name: github-markup
28
+ name: redcarpet
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: kramdown
42
+ name: rouge
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.9.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.9.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: medium-sdk-ruby
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -182,9 +182,12 @@ files:
182
182
  - bin/mediumize
183
183
  - lib/mediumize.rb
184
184
  - lib/mediumize/frontmatter.rb
185
+ - lib/mediumize/markdown.rb
186
+ - lib/mediumize/medium_publisher.rb
185
187
  - lib/mediumize/normalizers/links.rb
186
188
  - lib/mediumize/normalizers/title.rb
187
189
  - lib/mediumize/renderer.rb
190
+ - lib/mediumize/stdout_publisher.rb
188
191
  - lib/mediumize/version.rb
189
192
  - mediumize.gemspec
190
193
  homepage: https://github.com/jondot/mediumize