mediawiki-page-replaceable_content 0.1.2 → 0.1.3

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: d1ee35d1058df4b6448c698504b98a6c1ca8619e
4
- data.tar.gz: 73d033433bd1fdeafed00eb37f23d88246eb1e91
3
+ metadata.gz: 6de805495e9a8a705620c1d3c3688401fe5e39b9
4
+ data.tar.gz: 0e2997536489f3ff9ea1bdb29de6137037cb08ef
5
5
  SHA512:
6
- metadata.gz: bb918dcf68bcddae4f88c2f816150e2a5c23583e5eefbffaca0d107525e179688a86747c01b3be51aaed9a56427abd139f9dbb68776442cc8dea6ff11b2bfd9e
7
- data.tar.gz: e8c133b5724ae36ab41ed94defaa696a410831955da5c5e51402f9775276eaf467f37cf1a6b5ce54200b5207b4517dc48b1d812011d9a5e5965aebcfe0933b18
6
+ metadata.gz: c9332c50ef58a03c2076cf6c3f466ebf5621c22292148c9eb62251ba382bbd35d1b97bd43121508aef33e4010520321f3dc2db7839d8570a4aa7926d8d74b211
7
+ data.tar.gz: a4f7c2896b6811bd0ba59ca136164348b38abbfee68310f3ff6e1e072c022861c925eb01bce56e33f7cd7149969e1216b97bca41e619a3a651322dd61644434d
@@ -3,6 +3,8 @@ require 'mediawiki_api'
3
3
  module MediaWiki
4
4
  module Page
5
5
  class ReplaceableContent
6
+ NAMED_TEMPLATE_PARAM_RE = /(.*?)=(.*)/m
7
+
6
8
  def initialize(client:, title:, template:)
7
9
  @client = client
8
10
  @title = title
@@ -24,6 +26,17 @@ module MediaWiki
24
26
  client.edit(title: title, text: new_wikitext)
25
27
  end
26
28
 
29
+ def param_key_value_array(key, value)
30
+ [
31
+ if key.strip =~ /^\d+$/
32
+ Integer(Regexp.last_match[0])
33
+ else
34
+ key.strip.to_sym
35
+ end,
36
+ value,
37
+ ]
38
+ end
39
+
27
40
  def params
28
41
  # Returns the named parameters from the template tag as a Hash
29
42
  # where the keys are symbolized versions of the parameter
@@ -31,9 +44,15 @@ module MediaWiki
31
44
  # FIXME: untemplate these using the MediaWiki API before
32
45
  # returning them.
33
46
  all_parameters.map do |p|
34
- m = /(.*?)=(.*)/m.match(p)
35
- [m[1].strip.to_sym, m[2]]
36
- end.to_h
47
+ m = NAMED_TEMPLATE_PARAM_RE.match(p)
48
+ param_key_value_array(*m.captures) if m
49
+ end.compact.to_h
50
+ end
51
+
52
+ def anonymous_params
53
+ # FIXME: untemplate these using the MediaWiki API before
54
+ # returning them.
55
+ all_parameters.map { |p| NAMED_TEMPLATE_PARAM_RE =~ p ? nil : p }.compact
37
56
  end
38
57
 
39
58
  private
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'mediawiki-page-replaceable_content'
8
- spec.version = '0.1.2'
8
+ spec.version = '0.1.3'
9
9
  spec.authors = ['EveryPolitician']
10
10
  spec.email = ['team@everypolitician.org']
11
11
  spec.licenses = ['MIT']
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency 'mediawiki_api', '~> 0.7'
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 1.15'
35
- spec.add_development_dependency 'rake', '~> 10.0'
36
35
  spec.add_development_dependency 'minitest', '~> 5.0'
37
36
  spec.add_development_dependency 'pry', '~> 0.10'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
38
  spec.add_development_dependency 'rubocop', '~> 0.49'
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki-page-replaceable_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - EveryPolitician
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mediawiki_api
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.15'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '5.0'
48
48
  type: :development
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: '10.0'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '0.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '0.10'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.10'
75
+ version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.10'
82
+ version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement