Skip to content

Commit

Permalink
The iOS Times Newsletter automation πŸ‘
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Jul 19, 2015
0 parents commit 749d962
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "issues"]
path = issues
url = [email protected]:mokacoding/the-ios-times-issues.git
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
gem 'redcarpet'
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
rake (10.4.2)
redcarpet (3.2.3)

PLATFORMS
ruby

DEPENDENCIES
rake
redcarpet
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The iOS Times - Newsletter
===

This repo contains the automation used to generated the source for [The iOS Times](http://theiostimes.com) weekly newsletter.

```bash
rake build
```

---

(c) 2015 - mokacoding [@mokacoding](https://twitter.com/mokacoding) & Giovanni Lodi [@mokagio](https://twitter.com/mokagio)
55 changes: 55 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'tempfile'

issues_folder = 'issues'

desc "Update the issues list"
task :update do
sh "git submodule foreach git pull"
end

def stripped_front_matter_temp_file(issue)
f = Tempfile.new('title')
begin
found_start = false
found_end = false
issue.each_line do |line|
line = line.strip
if not found_start
found_start = line == '---'
elsif not found_end
found_end = line == '---'
else
f.puts line
end
end
ensure
f.close
end
return f
end

def title_temp_file(issue)
f = Tempfile.open('title')
begin
f.puts '# The iOS Times'
issue_number = File.basename(issue, '.*').split('-').last.to_i
f.puts "## Year #{2015 - Time.now.year + 1} Issue #{issue_number}"
f.puts "### #{File.basename(issue)[0, 10]}"
ensure
f.close
end
return f
end

desc "Generate the HTML code for the latest issue, and copy it to the clipboar"
task :build => [:update] do
latest = Dir["#{issues_folder}/*.md"].reject { |f| File.basename(f) == "README.md" }.last
issue = File.open(latest)
temp_issue = stripped_front_matter_temp_file(issue)
temp_title = title_temp_file(issue)
sh "redcarpet --parse-fenced_code_blocks --smarty #{temp_title.path} header.md #{temp_issue.path} footer.md | pbcopy"
puts "πŸ‘ HTML code for #{latest} copied to clipboard"
temp_issue.unlink
temp_title.unlink
issue.close
end
8 changes: 8 additions & 0 deletions footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<!-- Footer start, empty line on top needed -->

Thank you for reading **The iOS Times**, if you have comments, complaints, suggestions, or any other feedback please tweet me at [@mokagio](https://twitter.com/mokagio).

_Have a happy week, and don't forget to contriubte to open source projects._

<!-- Footer end -->
4 changes: 4 additions & 0 deletions header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

**Your weekly digest with the most interesting Swift and Objective-C project from the past 7 days. Find useful tools, inspiration, projects to contribute to.**

<!-- Header end -->
1 change: 1 addition & 0 deletions issues
Submodule issues added at 753266

0 comments on commit 749d962

Please sign in to comment.