Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html rendering #47

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d7789e2
gem: rvm ruby gemset and version added.
lolgear Feb 13, 2018
eb1543e
gitignore: updated in case of xcode project example project.
lolgear Feb 13, 2018
e5bc6aa
spec: example xcode project added.
lolgear Feb 13, 2018
9a8d14b
gem: html acknowledgements rendering added.
lolgear Feb 13, 2018
bef1e1c
gem: rvm files removed.
lolgear Feb 13, 2018
a455178
gem: fix indentation.
lolgear Feb 13, 2018
694d867
gem: writers html nokogiri dependency removed.
lolgear Feb 13, 2018
d3ee536
gem: gemspec trailing newline added.
lolgear Feb 13, 2018
947f4ca
gemspec: nokogiri dependency removed.
lolgear Feb 13, 2018
3b7c780
changelog: updated.
lolgear Feb 15, 2018
b6e79fa
gem: html generator has been updated.
lolgear Feb 6, 2019
78ecf99
gem: spec assets example project has been updated.
lolgear Feb 6, 2019
c6cdf19
gem: html writer dsl has been added.
lolgear Feb 10, 2019
e571bb6
gem: markdown writer has been added. erb writer variants has been added.
lolgear Feb 10, 2019
b002205
gem: specs assets example project markdown acknowledgements file has …
lolgear Feb 10, 2019
a35e4ad
gem: erb writers variants cleanup.
lolgear Feb 10, 2019
4742148
gem: markdown erb-free writer has been added. gitignore has been fixed.
lolgear Feb 12, 2019
de284c3
gem: html layout module has been added. gitignore ds_store has been a…
lolgear Feb 12, 2019
02dc5fa
gem: markdown render settings have been added. generators have been s…
lolgear Mar 5, 2019
7ca1b48
gem: markdown parser have been removed from writers.
lolgear Mar 5, 2019
5b18d4d
gem: metadata generators have been tangled with writers instead of ba…
lolgear Mar 6, 2019
0dc1721
Merge remote-tracking branch 'upstream/master' into html_rendering.
lolgear Mar 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ spec/reports
test/tmp
test/version_tmp
tmp

# RVM
.ruby-gemset
.ruby-version

# JetBrains
.idea/

# Xcode
xcuserdata/

# Pods
Pods/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Update matching for `Settings.bundle` file in project.
[Jim Hildensperger](https://github.com/jhildensperger)

* Add HTML acknowledgements file.
[Dmitry Lobanov](https://github.com/lolgear)

##### Bug Fixes

* None.
Expand Down
1 change: 1 addition & 0 deletions cocoapods_acknowledgements.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'activesupport', '>= 4.0.2', '< 5'

spec.add_dependency "redcarpet", "~> 3.3"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end
44 changes: 32 additions & 12 deletions lib/cocoapods_acknowledgements.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
module CocoaPodsAcknowledgements
require 'cocoapods_acknowledgements/plist_generator'
require 'cocoapods_acknowledgements/html_generator'
require 'cocoapods_acknowledgements/settings_plist_generator'

def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
if defined? Xcodeproj::Plist.write_to_path
Xcodeproj::Plist.write_to_path(metadata, plist_path)
else
Xcodeproj.write_plist(metadata, plist_path)
require 'cocoapods_acknowledgements/writers'
def self.write_metadata(metadata, file_path)
extname = Pathname.new(file_path).extname
case extname
when '.plist'
PlistWriter.write(metadata, file_path)
when '.html'
HTMLWriter.write(metadata, file_path)
when '.md'
MarkdownWriter.write(metadata, file_path)
end
end

def self.add_metadata_to_project(plist_path, project, sandbox, user_target_uuid)
# Find a root folder in the users Xcode Project called Pods, or make one
cocoapods_group = project.main_group["Pods"]
unless cocoapods_group
Expand All @@ -17,7 +24,7 @@ def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)

# Add the example plist to the found CocoaPods group
plist_pathname = Pathname.new(File.expand_path(plist_path))
file_ref = cocoapods_group.files.find { |file| file.real_path == plist_pathname }
file_ref = cocoapods_group.files.find {|file| file.real_path == plist_pathname}
unless file_ref
file_ref = cocoapods_group.new_file(plist_path)
end
Expand All @@ -29,11 +36,15 @@ def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
end

project.save
end

def self.save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
write_metadata(metadata, plist_path)
add_metadata_to_project(plist_path, project, sandbox, user_target_uuid)
end

def self.settings_bundle_in_project(project)
file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
file = project.files.find {|f| f.path =~ /Settings\.bundle$/}
file.real_path.to_path unless file.nil?
end

Expand Down Expand Up @@ -63,12 +74,21 @@ def self.settings_bundle_in_project(project)
umbrella_target.user_target_uuids.each do |user_target_uuid|

# Generate a plist representing all of the podspecs
metadata = PlistGenerator.generate(umbrella_target, sandbox, excluded_pods)

next unless metadata
plist_metadata = PlistGenerator.generate(umbrella_target, sandbox, excluded_pods)
html_metadata = HTMLGenerator.generate(umbrella_target, sandbox, excluded_pods)
next unless plist_metadata

# save plist file.
plist_path = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata.plist"
save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
save_metadata(plist_metadata, plist_path, project, sandbox, user_target_uuid)

# save html file.
html_path = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata.html"
save_metadata(html_metadata, html_path, project, sandbox, user_target_uuid)

# save markdown file.
markdown_path = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata.md"
save_metadata(html_metadata, markdown_path, project, sandbox, user_target_uuid)

if should_include_settings
# Generate a plist in Settings format
Expand Down
37 changes: 37 additions & 0 deletions lib/cocoapods_acknowledgements/auxiliaries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module CocoaPodsAcknowledgements
module Auxiliaries
def file_accessor(spec, platform, sandbox)
pod_root = sandbox.pod_dir(spec.name)
if pod_root.exist?
path_list = Pod::Sandbox::PathList.new(pod_root)
Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
end
end

# Returns the text of the license for the given spec.
#
# @param [Specification] spec
# the specification for which license is needed.
#
# @return [String] The text of the license.
# @return [Nil] If not license text could be found.
#
def license_text(spec, file_accessor)
return nil unless spec.license
text = spec.license[:text]
unless text
if file_accessor
if license_file = file_accessor.license
if license_file.exist?
text = IO.read(license_file)
else
Pod::UI.warn "Unable to read the license file `#{license_file }` " \
"for the spec `#{spec}`"
end
end
end
end
text
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing newlines missing in all these files, everything should also be using 2 spaces for indentation

38 changes: 38 additions & 0 deletions lib/cocoapods_acknowledgements/generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'cocoapods_acknowledgements/auxiliaries'
module CocoaPodsAcknowledgements
class Generator
class << self
include Auxiliaries

def generate_specs(target_description, sandbox, excluded, root_specs)
[]
end

def generate(target_description, sandbox, excluded)
root_specs = target_description.specs.map(&:root).uniq.reject {|spec| excluded.include?(spec.name)}
return nil if root_specs.empty?
generate_specs(target_description, sandbox, excluded, root_specs)
end
end
end
end

module CocoaPodsAcknowledgements
class Generator
class SpecObject
attr_accessor :name, :version, :authors, :socialMedialURL, :summary,
:description, :licenseType, :licenseText, :homepage
def initialize(options)
@name = options["name"]
@version = options["version"]
@authors = options["authors"]
@socialMediaURL = options["socialMediaURL"]
@summary = options["summary"]
@description = options["description"]
@licenseType = options["licenseType"]
@licenseText = options["licenseText"]
@homepage = options["homepage"]
end
end
end
end
27 changes: 27 additions & 0 deletions lib/cocoapods_acknowledgements/html_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'cocoapods_acknowledgements/markdown_parser'
require 'cocoapods_acknowledgements/generator'

module CocoaPodsAcknowledgements
class HTMLGenerator < PlistGenerator
class << self
def generate_specs(target_description, sandbox, excluded, root_specs)
metadata = super
specs = metadata["specs"]
metadata["specs"] = specs.map do |spec|
Generator::SpecObject.new(spec)
end
metadata["header"] = header
metadata["footer"] = footer
metadata
end

def header
'Acknowledgements'
end

def footer
'Generated by CocoaPods - https://cocoapods.org'
end
end
end
end
16 changes: 16 additions & 0 deletions lib/cocoapods_acknowledgements/markdown_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'redcarpet'

module CocoaPodsAcknowledgements
class MarkdownParser
class << self
def markdown_parser
@markdown_parser ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to pass render_options to HTML render using user_settings parameter of cocoapods-acknowledgements plugin. Current implementation don't wrap http[s] links with a HTML tag which makes them hard to style.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krin-san How to retrieve user_settings?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I mistyped – it's named user_options. This hash contains any custom parameters user might define in plugin inclusion string. E.g.:

plugin 'cocoapods-acknowledgements', :settings_bundle => true

We can use user_options as a source of extra parameters for Redcarpet::Render::HTML. Example:

plugin 'cocoapods-acknowledgements', :html_render_options => {:no_links => false, :link_attributes => {"link" => "#C0C0C0", "vlink" => "#808080", "alink" => "#FF0000"}}

Just need to figure out how to pass html_render_options through HTMLGenerator to MarkdownParser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krin-san We can extend self.generate method in Generator to accept another parameter options.

      def generate_specs(target_description, sandbox, excluded, root_specs, options = {})
        []
      end
      def generate(target_description, sandbox, excluded, options = {})
        root_specs = target_description.specs.map(&:root).uniq.reject {|spec| excluded.include?(spec.name)}
        return nil if root_specs.empty?
        generate_specs(target_description, sandbox, excluded, root_specs)
      end

I don't see any better option here.
What do you think?

Copy link

@krin-san krin-san Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a Ruby developer actually 😄. Whichever option allowing to define render_options in Podfile plugin inclusion line looks fine for me.

end

def parse_markdown(text)
return nil unless text
markdown_parser.render(text)
end
end
end
end
69 changes: 8 additions & 61 deletions lib/cocoapods_acknowledgements/plist_generator.rb
Original file line number Diff line number Diff line change
@@ -1,87 +1,34 @@
require 'redcarpet'
require 'cocoapods_acknowledgements/markdown_parser'
require 'cocoapods_acknowledgements/generator'

module CocoaPodsAcknowledgements
class PlistGenerator
class PlistGenerator < Generator
class << self

def markdown_parser
@markdown_parser ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML)
end

def generate(target_description, sandbox, excluded)
root_specs = target_description.specs.map(&:root).uniq.reject { |spec| excluded.include?(spec.name) }

return nil if root_specs.empty?

def generate_specs(target_description, sandbox, excluded, root_specs)
specs_metadata = []
root_specs.each do |spec|
specs = root_specs.map do |spec|
pod_root = sandbox.pod_dir(spec.name)
platform = Pod::Platform.new(target_description.platform_name)
file_accessor = file_accessor(spec, platform, sandbox)
license_text = license_text(spec, file_accessor)

spec_metadata = {
metadata = {
"name" => spec.name,
"version" => spec.version,
"authors" => spec.authors,
"socialMediaURL" => spec.social_media_url,
"summary" => spec.summary,
"description" => parse_markdown(spec.description),
"description" => MarkdownParser.parse_markdown(spec.description),
"licenseType" => spec.license[:type],
"licenseText" => license_text,
"homepage" => spec.homepage,
}
specs_metadata << spec_metadata
end

specs_metadata += specs
metadata = {}
metadata["specs"] = specs_metadata
metadata
end

#-----------------------------------------------------------------------#

def file_accessor(spec, platform, sandbox)
pod_root = sandbox.pod_dir(spec.name)
if pod_root.exist?
path_list = Pod::Sandbox::PathList.new(pod_root)
Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
end
end

# Returns the text of the license for the given spec.
#
# @param [Specification] spec
# the specification for which license is needed.
#
# @return [String] The text of the license.
# @return [Nil] If not license text could be found.
#
def license_text(spec, file_accessor)
return nil unless spec.license
text = spec.license[:text]
unless text
if file_accessor
if license_file = file_accessor.license
if license_file.exist?
text = IO.read(license_file)
else
Pod::UI.warn "Unable to read the license file `#{license_file }` " \
"for the spec `#{spec}`"
end
end
end
end
text
end

def parse_markdown(text)
return nil unless text
markdown_parser.render(text)
end

#-----------------------------------------------------------------------#

end
end
end
12 changes: 4 additions & 8 deletions lib/cocoapods_acknowledgements/settings_plist_generator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
require 'cocoapods_acknowledgements/plist_generator'
require 'cocoapods_acknowledgements/markdown_parser'
require 'cocoapods_acknowledgements/generator'

module CocoaPodsAcknowledgements
class SettingsPlistGenerator < PlistGenerator
class SettingsPlistGenerator < Generator
class << self

def generate(target_description, sandbox, excluded)
root_specs = target_description.specs.map(&:root).uniq.reject { |spec| excluded.include?(spec.name) }

return nil if root_specs.empty?

def generate_specs(target_description, sandbox, excluded, root_specs)
specs_metadata = [header]

root_specs.each do |spec|
Expand Down
Loading