ascii_press 0.2.0 → 0.3.0

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: dffcb104898a26201bd65d8ee065e16b277d7c9e
4
- data.tar.gz: bcef3472d8592080fffa9f3508311dc841fb2e40
3
+ metadata.gz: 37d6a2018a0f90579ba668606675a3c56476e234
4
+ data.tar.gz: ecb49c8631633d9486776fa24fa0740b95503e64
5
5
  SHA512:
6
- metadata.gz: 75673e806f48540665343e9ce1db0e5bf283ed4d94656f4af9ecade5e5f3d1f3222819d7d3e914e2a40aa1a5417a9e69d3f31cabfaf7b444800936cb189ff750
7
- data.tar.gz: e7da91e2342a3124cf930015accaa915c507c5e20996a769b0ab7cc5b75c3af78bfa97a177af801bed21b95aa03bb186aa9035504a2acad17d58086a81d74b8a
6
+ metadata.gz: 0de878a7dabb9d416bad0672f746f2e53f622c2367c0ec85dd379b2981b64ea5e38e6c25bb70896f9edbe393ab5d2ccdbb1d779e6d0b395f5df816c3b14835de
7
+ data.tar.gz: fe030d7a0600125fa28adb2ba4529eb971026c4a58ee685354542b9f8dcdaf0e9feaefc85c55d03380569ed9ddaa556a3db4ed2e6334b21fc8aa640a7be4e924
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # AsciiPress
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ascii_press`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ AsciiPress is a gem which is designed to make it easy to publish a set of [asciidoc](http://asciidoctor.org/) files to a specific `post_type` in a WordPress site. You can see an example in action in the [`render.rb` file](https://github.com/neo4j-contrib/developer-resources/blob/gh-pages/render.rb) to generate the Neo4j developer website.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,38 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ The main API to synchronize documents with WordPress in the `WordPressSyncer`. To create a new `WordPressSyncer` you need to provide a hostname, username, password, and a `AsciiPress::Renderer` object. The following is an example:
24
+
25
+ ```ruby
26
+ WP_HOSTNAME = 'fakepress.com'
27
+ WP_USERNAME = 'fake'
28
+ WP_PASSWORD = 'pass'
29
+ WP_POST_TYPE = 'faq'
30
+
31
+ # Available keys for options are:
32
+ # `:asciidoc_options`: Passed directly to the `Asciidoctor.load` method
33
+ # `:before_convertion`: Proc which is given the asciidoctor text. Whatever is returned is passed to `Asciidoctor.load`
34
+ # `:after_conversion`: Proc which is given the html text after the Asciidoctor conversion. Whatever is returned will be uploaded to WordPress
35
+ # `:extra_tags_proc`: Proc which is given the `AsciiPress::Renderer::Rendering` object (see below). Whatever is returned will be used as the WordPress Post's tags
36
+ renderer = AsciiPress::Renderer.new(extra_tags_proc: -> (rendering) { ['tag-for-all'] }, asciidoc_options: {attributes: 'allow-uri-read'})
37
+
38
+ wp_syncer = AsciiPress::WordPressSyncer.new(WP_HOSTNAME, WP_USERNAME, WP_PASSWORD, renderer, WP_POST_TYPE
39
+ post_type: ENV['BLOG_POST_TYPE'],
40
+ logger: LOGGER,
41
+ delete_not_found: delete_not_found,
42
+ generate_tags: true,
43
+ filter_proc: filter_proc)
44
+ ```
45
+
46
+ ### `AsciiPress::Renderer::Rendering`
47
+
48
+ Provides the following methods:
49
+
50
+ * `html` The HTML resulting from the asciidoc
51
+ * `doc` The `Asciidoctor::Document` object from the `asciidoctor` gem
52
+ * `data` The adoc file's attributes standardized with symbol keys and string values
53
+ * `tags` The tags which will be set in `WordPress`
54
+
26
55
 
27
56
  ## Development
28
57
 
data/lib/ascii_press.rb CHANGED
@@ -58,7 +58,7 @@ module AsciiPress
58
58
  if before_convertion = @options[:before_convertion]
59
59
  document_text = before_convertion.call(document_text)
60
60
  end
61
- doc = Asciidoctor.load(document_text, @options.merge(base_dir: base_dir))
61
+ doc = Asciidoctor.load(document_text, @options[:asciidoc_options].merge(base_dir: base_dir))
62
62
  end
63
63
  puts errors.split(/[\n\r]+/).reject {|line| line.match(/out of sequence/) }.join("\n")
64
64
 
@@ -95,10 +95,10 @@ module AsciiPress
95
95
  end
96
96
 
97
97
  class WordPressSyncer
98
- def initialize(blog_id, username, password, renderer, options = {})
98
+ def initialize(blog_id, username, password, post_type, renderer, options = {})
99
99
  @blog_id = blog_id
100
100
  @wp_client = Rubypress::Client.new(host: @blog_id, username: username, password: password)
101
- @post_type = options[:post_type] || 'faq'
101
+ @post_type = post_type
102
102
  @logger = options[:logger] || AsciiPress.logger
103
103
  @renderer = renderer || Renderer.new
104
104
  @filter_proc = options[:filter_proc] || Proc.new { true }
@@ -215,10 +215,12 @@ module AsciiPress
215
215
  }
216
216
 
217
217
  def self.slug_valid?(slug, rules = DEFAULT_SLUG_RULES)
218
- rules.values.all? {|rule| rule.call(slug) }
218
+ slug && rules.values.all? {|rule| rule.call(slug) }
219
219
  end
220
220
 
221
221
  def self.violated_slug_rules(slug, rules = DEFAULT_SLUG_RULES)
222
+ return ['No slug'] if slug.nil?
223
+
222
224
  rules.reject do |desc, rule|
223
225
  rule.call(slug)
224
226
  end.map(&:first)
@@ -239,7 +241,7 @@ module AsciiPress
239
241
  require 'colorize'
240
242
  data.each do |path, slug, violations|
241
243
  puts 'WARNING!!'.red
242
- puts "The document #{path.blue} has the #{slug.blue} which in invalid because:"
244
+ puts "The document #{path.light_blue} has the slug #{slug.inspect.light_blue} which in invalid because:"
243
245
  violations.each do |violation|
244
246
  puts " - #{violation.yellow}"
245
247
  end
@@ -1,3 +1,3 @@
1
1
  module AsciiPress
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascii_press
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypress