-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/trunk' into feature/site-design-…
…revamp
- Loading branch information
Showing
331 changed files
with
5,783 additions
and
1,217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'xcodeproj' | ||
|
||
REPO_ROOT = Pathname.new(__dir__) + '../..' | ||
|
||
def lint(file_path:, target_name:) | ||
violations_count = 0 | ||
File.foreach(file_path, mode: 'rb:BOM|UTF-8').with_index do |line, line_no| | ||
next if line.match? %r(^\s*//) # Skip commented lines | ||
|
||
col_no = line.index('NSLocalizedString') | ||
next if col_no.nil? | ||
|
||
puts "#{file_path}:#{line_no+1}:#{col_no+1}: error: Use `AppLocalizedString` instead of `NSLocalizedString` in source files that are used in the `#{target_name}` extension target. See paNNhX-nP-p2 for more info." | ||
violations_count += 1 | ||
end | ||
violations_count | ||
end | ||
|
||
## Main ## | ||
|
||
project = Xcodeproj::Project.open(REPO_ROOT + 'WordPress/WordPress.xcodeproj') | ||
targets_to_analyze = if ARGV.count.positive? | ||
project.targets.select { |t| t.name == ARGV.first } | ||
else | ||
project.targets.select { |t| t.is_a?(Xcodeproj::Project::Object::PBXNativeTarget) && t.extension_target_type? } | ||
end | ||
|
||
violations_count = 0 | ||
targets_to_analyze.each do |target| | ||
build_phase = target.build_phases.find { |p| p.is_a?(Xcodeproj::Project::Object::PBXSourcesBuildPhase) } | ||
next if build_phase.nil? | ||
|
||
puts "Linting extension target #{target.name} for improper NSLocalizedString usage..." | ||
source_files = build_phase.files_references.map(&:real_path).select { |f| ['.m', '.swift'].any? { |ext| f.extname == ext } } | ||
source_files.each { |f| violations_count += lint(file_path: f, target_name: target.name) } | ||
puts "Done." | ||
end | ||
|
||
exit 1 if violations_count > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash -eu | ||
|
||
# Use this to run a Ruby script from a "Script Build Phase" from Xcode. | ||
# | ||
# Since shell scripts ran by Xcode do not source the user shell profile, typical user setups like the configurations of `rbenv` or `rvm` would not be set up properly. | ||
# This script check if either `rbenv` or `rvm` is installed on the Mac and runs the setup steps as appropriate, before running the ruby script via `bundle exec` | ||
# | ||
# Usage: | ||
# `runRubyScript <script_name.rb> <optional_args>` | ||
# | ||
# Where <script_name.rb` can be either an absolute path, or a path relative to this runRubyScript wrapper script. | ||
# | ||
# Inspiration: https://mgrebenets.github.io/xcode/2019/04/04/xcode-build-phases-and-environment | ||
# | ||
|
||
# Add `rbenv` and `rvm` binaries to PATH, so that we support both | ||
export PATH="$HOME/.rbenv/shims:$HOME/.rvm/bin:$PATH" | ||
RUBY_VERSION="$(cat "${PROJECT_DIR}/../.ruby-version")" | ||
if command -v rvm; then | ||
source "$(rvm "${RUBY_VERSION}" do rvm env --path | tail -n1)" | ||
fi | ||
|
||
# Run the script with bundle exec | ||
echo "Running the script using 'bundle exec' ..." | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
bundle exec ruby "$@" | ||
cd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import CoreData | ||
import WordPressKit | ||
|
||
class BloggingPromptsService { | ||
private let context: NSManagedObjectContext | ||
private let siteID: NSNumber | ||
private let remote: BloggingPromptsServiceRemote | ||
private let calendar: Calendar = .autoupdatingCurrent | ||
|
||
private var defaultDate: Date { | ||
calendar.date(byAdding: .day, value: -10, to: Date()) ?? Date() | ||
} | ||
|
||
/// Fetches a number of blogging prompts starting from the specified date. | ||
/// When no parameters are specified, this method will attempt to return prompts from ten days ago and two weeks ahead. | ||
/// | ||
/// - Parameters: | ||
/// - date: When specified, only prompts from the specified date will be returned. Defaults to 10 days ago. | ||
/// - number: The amount of prompts to return. Defaults to 24 when unspecified. | ||
/// - success: Closure to be called when the fetch process succeeded. | ||
/// - failure: Closure to be called when the fetch process failed. | ||
func fetchPrompts(from date: Date? = nil, | ||
number: Int = 24, | ||
success: @escaping ([BloggingPrompt]) -> Void, | ||
failure: @escaping (Error?) -> Void) { | ||
let fromDate = date ?? defaultDate | ||
remote.fetchPrompts(for: siteID, number: number, fromDate: fromDate) { result in | ||
switch result { | ||
case .success(let remotePrompts): | ||
// TODO: Upsert into CoreData once the CoreData model is available. | ||
success(remotePrompts.map { BloggingPrompt(with: $0) }) | ||
case .failure(let error): | ||
failure(error) | ||
} | ||
} | ||
} | ||
|
||
required init?(context: NSManagedObjectContext = ContextManager.shared.mainContext, | ||
remote: BloggingPromptsServiceRemote? = nil, | ||
blog: Blog? = nil) { | ||
guard let account = AccountService(managedObjectContext: context).defaultWordPressComAccount(), | ||
let siteID = blog?.dotComID ?? account.primaryBlogID else { | ||
return nil | ||
} | ||
|
||
self.context = context | ||
self.siteID = siteID | ||
self.remote = remote ?? .init(wordPressComRestApi: account.wordPressComRestV2Api) | ||
} | ||
} | ||
|
||
// MARK: - Temporary model object | ||
|
||
/// TODO: This is a temporary model to be replaced with Core Data model once the fields have all been finalized. | ||
struct BloggingPrompt { | ||
let promptID: Int | ||
let text: String | ||
let title: String // for post title | ||
let content: String // for post content | ||
let date: Date | ||
let answered: Bool | ||
let answerCount: Int | ||
let displayAvatarURLs: [URL] | ||
|
||
init(with remotePrompt: RemoteBloggingPrompt) { | ||
promptID = remotePrompt.promptID | ||
text = remotePrompt.text | ||
title = remotePrompt.title | ||
content = remotePrompt.content | ||
date = remotePrompt.date | ||
answered = remotePrompt.answered | ||
answerCount = remotePrompt.answeredUsersCount | ||
displayAvatarURLs = remotePrompt.answeredUserAvatarURLs | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.