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 18 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 @@ -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
38 changes: 25 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,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
175 changes: 175 additions & 0 deletions lib/cocoapods_acknowledgements/html_layout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
module CocoaPodsAcknowledgements
module HTMLLayout
end
end

module CocoaPodsAcknowledgements::HTMLLayout
class HTMLObject
attr_accessor :tag
attr_accessor :children

def tag_begin
"<#{tag}>"
end

def tag_end
"</#{tag}>"
end

def layout
[tag_begin, children.map(&:layout), tag_end].join("\n")
end

def initialize
@children = []
end

def << (object)
@children << object
end

class << self
def tag(tag)
item = new
item.tag = tag
item
end
end
end
end

module CocoaPodsAcknowledgements::HTMLLayout
class MarkdownObject < HTMLObject
def tag_begin
tag
end
def tag_end
tag
end
def layout
([
[tag_begin, children.first.layout, tag_end].join(" ")
] + children.drop(1).map(&:layout)).join("\n\n")
end
end
end

module CocoaPodsAcknowledgements::HTMLLayout
class ContentObject < HTMLObject
attr_accessor :content

def tag_begin
""
end

def tag_end
""
end

def layout
content
end

class << self
def content(html)
new_object = new
new_object.content = html
new_object
end
end
end
end

module CocoaPodsAcknowledgements::HTMLLayout
class HTMLObjectBuilder
attr_accessor :root_object
attr_accessor :current_object
attr_accessor :parent_object

def initialize(&block)
@root_object = nil
@current_object = nil
if block
block.call(self)
end
end

def base_object
HTMLObject
end

def tag_or_object(tag)
if tag.is_a? base_object
tag
else
base_object.tag tag
end
end

def open(tag)
new_object = tag_or_object tag

unless @root_object
@root_object = new_object
@current_object = @root_object
@parent_object = @root_object
else
@parent_object = @current_object
@current_object << new_object
@current_object = new_object
end
end

def close
@current_object = @parent_object
end

def tag(tag, &block)
self.open tag
if block
block.call(self)
end
self.close
end

def content(html)
@current_object << ContentObject.content(html)
end

def layout
root_object.layout
end
end
end

# MARK: DSL
class CocoaPodsAcknowledgements::HTMLLayout::HTMLObjectBuilder
def > (tag)
self.open tag
self
end
def !
self.close
self
end
def << (html)
self.content(html)
self
end
def >= (tag)
self > tag
!self
end
def <= (html)
self << html
!self
end
end

module CocoaPodsAcknowledgements::HTMLLayout
class MarkdownObjectBuilder < HTMLObjectBuilder
def base_object
MarkdownObject
end
end
end
Loading