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 all 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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# macOS
.DS_Store

# Ruby
*.gem
*.rbc
.bundle
Expand All @@ -15,3 +19,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 @@ -18,6 +18,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
39 changes: 26 additions & 13 deletions lib/cocoapods_acknowledgements.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module CocoaPodsAcknowledgements
require 'cocoapods_acknowledgements/plist_generator'
require 'cocoapods_acknowledgements/html_generator'
require 'cocoapods_acknowledgements/settings_plist_generator'
require 'cocoapods_acknowledgements/writers'
def self.write_metadata(metadata, filepath)
Writers.write(metadata, filepath)
end

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)
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 +16,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 +28,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 +66,22 @@ 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)
metadata_and_filepath =
[PlistGenerator, HTMLGenerator, MarkdownGenerator].zip([PlistWriter, HTMLWriter, MarkdownWriter]).map do |pair|
generator, writer = pair
extension = writer.file_extension
filepath = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata#{extension}"
[generator.generate(umbrella_target, sandbox, excluded_pods), filepath]
end.reject do |pair|
pair.first.nil?
end

next unless metadata
next if metadata_and_filepath.empty?

plist_path = sandbox.root + "#{umbrella_target.cocoapods_target_label}-metadata.plist"
save_metadata(metadata, plist_path, project, sandbox, user_target_uuid)
metadata_and_filepath.each do |pair|
metadata, filepath = pair
save_metadata(metadata, filepath, project, sandbox, user_target_uuid)
end

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

42 changes: 42 additions & 0 deletions lib/cocoapods_acknowledgements/generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
def header
'Acknowledgements'
end
def footer
'Generated by CocoaPods - https://cocoapods.org'
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
37 changes: 37 additions & 0 deletions lib/cocoapods_acknowledgements/html_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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|
spec["licenseText"] = MarkdownParser.parse_markdown(spec["licenseText"])
Generator::SpecObject.new(spec)
end
metadata["header"] = header
metadata["footer"] = footer
metadata
end
end
end
end

module CocoaPodsAcknowledgements
class MarkdownGenerator < 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
end
end
end
Loading