aweplug 1.0.0.a4 → 1.0.0.a5

Sign up to get free protection for your applications and to get access to all the features.
data/aweplug.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_development_dependency 'guard-rspec', '~> 3.0.0'
28
28
  gem.add_development_dependency 'rake', '~> 10.0.4'
29
+ gem.add_development_dependency 'pry', '~> 0.9.12'
29
30
  end
@@ -2,6 +2,8 @@ require 'pathname'
2
2
  require 'kramdown'
3
3
  require 'aweplug/helpers/git_commit_metadata'
4
4
  require 'aweplug/helpers/kramdown_metadata'
5
+ require 'aweplug/helpers/searchisko'
6
+ require 'json'
5
7
 
6
8
  module Aweplug
7
9
  module Extensions
@@ -16,19 +18,53 @@ module Aweplug
16
18
  end
17
19
 
18
20
  def execute site
21
+ # Not sure if it's better to do this once per class,
22
+ # once per site, or once per invocation
23
+ searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
24
+ :authenticate => true,
25
+ :searchisko_username => ENV['dcp_user'],
26
+ :searchisko_password => ENV['dcp_password'],
27
+ #:adapter => :excon,
28
+ :logger => site.profile == 'developement'})
19
29
  Dir["#{@repo}/**/README.md"].each do |file|
20
30
  page = add_to_site site, file
21
31
 
22
32
  metadata = extract_metadata(file)
23
33
  metadata[:commits] = commit_info @repo, Pathname.new(file)
34
+ converted_html = metadata.delete :converted
24
35
 
25
36
  page.send 'metadata=', metadata
26
- # TODO: Upload to DCP
37
+
38
+ searchisko_hash =
39
+ {
40
+ :sys_title => metadata[:title],
41
+ :sys_content_id => Digest::SHA1.hexdigest(metadata[:title])[0..7], # maybe change?
42
+ :level => metadata[:level],
43
+ :tags => metadata[:technologies].split(/,\s/),
44
+ :sys_description => metadata[:summary],
45
+ :sys_content => converted_html,
46
+ :sys_url_view => "#{site.base_url}#{'/' + site.ctx_root + '/'}#{page.output_path}",
47
+ :"sys_content_content-type" => 'text/html',
48
+ :sys_type => 'jbossdeveloper_quickstart',
49
+ :sys_content_type => 'quickstart',
50
+ :sys_content_provider => 'jboss-developer',
51
+ :contributors => metadata[:commits].collect { |c| c[:author] }.uniq,
52
+ :sys_created => metadata[:commits].collect { |c| DateTime.parse c[:date] }.last,
53
+ :sys_activity_dates => metadata[:commits].collect { |c| DateTime.parse c[:date] },
54
+ :sys_updated => metadata[:commits].collect { |c| DateTime.parse c[:date] }.first,
55
+ :target_product => metadata[:target_product]
56
+ }
57
+
58
+ unless site.profile =~ /development/
59
+ searchisko.push_content(searchisko_hash[:sys_type],
60
+ searchisko_hash[:sys_content_id],
61
+ searchisko_hash.to_json)
62
+ end
27
63
  end
28
64
  end
29
65
 
30
66
  def extract_metadata(file)
31
- document = (::Kramdown::Document.new File.readlines(file).join, :input => 'QuickStartParser')
67
+ document = parse_kramdown(file)
32
68
  toc = ::Kramdown::Converter::Toc.convert(document.root)
33
69
  toc_items = toc[0].children.select { |el| el.value.options[:level] == 2 }.map do |t|
34
70
  {:id => t.attr[:id], :text => t.value.children.first.value}
@@ -36,6 +72,7 @@ module Aweplug
36
72
 
37
73
  metadata = document.root.options[:metadata]
38
74
  metadata[:toc] = toc_items
75
+ metadata[:converted] = document.to_html
39
76
  metadata
40
77
  end
41
78
 
@@ -47,6 +84,12 @@ module Aweplug
47
84
  site.pages << page
48
85
  page
49
86
  end
87
+
88
+ private
89
+
90
+ def parse_kramdown(file)
91
+ ::Kramdown::Document.new File.readlines(file).join, :input => 'QuickStartParser'
92
+ end
50
93
  end
51
94
  end
52
95
  end
@@ -1,6 +1,6 @@
1
1
  require 'asciidoctor'
2
2
 
3
- module Awestruct
3
+ module Aweplug
4
4
  module Extensions
5
5
  # Public: Parses (AsciiDoc files currently) and pulls out h2 sections
6
6
  # (and their contents), setting them as first class page variables.
@@ -0,0 +1,31 @@
1
+ require 'awestruct/handlers/base_handler'
2
+ require 'pathname'
3
+
4
+ module Aweplug
5
+ module Handlers
6
+ class SyntheticHandler < Awestruct::Handlers::BaseHandler
7
+ attr_reader :path
8
+
9
+ def initialize site, content, path
10
+ super(site)
11
+ @content = content
12
+ @input_mtime = DateTime.now.to_time
13
+
14
+ case (path)
15
+ when Pathname
16
+ @path = path
17
+ else
18
+ @path = Pathname.new(path.to_s)
19
+ end
20
+ end
21
+
22
+ def input_mtime(page)
23
+ @input_mtime
24
+ end
25
+
26
+ def rendered_content(context, with_layouts)
27
+ @content
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'pry' # Allow for debugging
4
+
5
+ module Aweplug::Helpers
6
+ # Public: A helper class for using Searchisko.
7
+ class Searchisko
8
+ # Public: Initialization of the object, keeps a Faraday connection cached.
9
+ #
10
+ # opts - symbol keyed hash. Current keys used:
11
+ # :base_url - base url for the searchisko instance
12
+ # :authenticate - boolean flag for authentication
13
+ # :searchisko_username - Username to use for auth
14
+ # :searchisko_password - Password to use for auth
15
+ # :logging - Boolean to log responses
16
+ # :raise_error - Boolean flag if 404 and 500 should raise exceptions
17
+ # :adapter - faraday adapter to use, defaults to :net_http
18
+ def initialize opts={}
19
+ @faraday = Faraday.new(:url => opts[:base_url]) do |builder|
20
+ if opts[:authenticate]
21
+ if opts[:searchisko_username] && opts[:searchisko_password]
22
+ builder.request :basic_auth, opts[:searchisko_username], opts[:searchisko_password]
23
+ else
24
+ $LOG.warn 'Missing username and / or password for searchisko'
25
+ end
26
+ end
27
+ builder.response :logger if opts[:logging]
28
+ builder.response :raise_error if opts[:raise_error]
29
+ #builder.response :json, :content_type => /\bjson$/
30
+ builder.adapter opts[:adapter] || :net_http
31
+ end
32
+ end
33
+
34
+ def search params = {}
35
+ get '/search', params
36
+ end
37
+
38
+ def get path, params = {}
39
+ @faraday.get "/v1/rest/" + path, params
40
+ end
41
+
42
+ def push_content content_type, content_id, params = {}
43
+ post "/content/#{content_type}/#{content_id}", params
44
+ end
45
+
46
+ def post path, params = {}
47
+ response = @faraday.post do |req|
48
+ req.url "/v1/rest/" + path
49
+ req.headers['Content-Type'] = 'application/json'
50
+ req.body = params
51
+ end
52
+ binding.pry # Allow for debugging
53
+ end
54
+ end
55
+ end
@@ -1,4 +1,4 @@
1
1
  module Aweplug
2
- VERSION='1.0.0.a4'
2
+ VERSION='1.0.0.a5'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aweplug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.a4
4
+ version: 1.0.0.a5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-10 00:00:00.000000000 Z
12
+ date: 2013-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 10.0.4
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.9.12
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.12
94
110
  description: A set of Awestruct extensions for building a project website
95
111
  email:
96
112
  - lightguard.jp@gmail.com
@@ -115,9 +131,11 @@ files:
115
131
  - lib/aweplug/extensions/identity/jbosscommunity.rb
116
132
  - lib/aweplug/extensions/kramdown_quickstart.rb
117
133
  - lib/aweplug/extensions/sections.rb
134
+ - lib/aweplug/handlers/synthetic_handler.rb
118
135
  - lib/aweplug/helpers/.gitkeep
119
136
  - lib/aweplug/helpers/git_commit_metadata.rb
120
137
  - lib/aweplug/helpers/kramdown_metadata.rb
138
+ - lib/aweplug/helpers/searchisko.rb
121
139
  - lib/aweplug/transformers/.gitkeep
122
140
  - lib/aweplug/version.rb
123
141
  - spec/aweplug/extensions/identity/collector_spec.rb