Skip to content

Commit

Permalink
json generator for grn-js
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Sep 6, 2014
1 parent 0151d6b commit a86c32a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize
@views_path = File.join(@root, 'views')
@pages_path = File.join(@root, 'pages')
@static_path = File.join(@root, 'site')
@json_path = File.join(@root, 'json')
end

def make_letter(source)
Expand Down Expand Up @@ -128,6 +129,43 @@ def make_rss
end
end

def make_json(edition = nil)
issues = File.join(@json_path, "issues.json")
stories = File.join(@json_path, "stories.json")
issues_data = []
stories_data = []
letters = JSON.parse(File.read(File.join(@static_path, 'editions.json')))
letters.each do |letter,c|
data = to_ostruct(YAML::load_file(File.join(@news_path, "archives/grn-#{letter}.yml")))
issues_data << {
"id" => data.edition.to_i,
"date" => data.pubdate,
"edito" => data.edito,
"contributors" => data.contibutors
}
data.topics.each do |topic|
topic.links.each do |story|
stories_data << {
"issue" => data.edition.to_i,
"title" => story.title,
"link" => story.url,
"description" => story.comment,
"category" => topic.title,
"subject" => story.tags,
"date" => story.pubdate,
"quantity" => story.duration
}
end
end
end
File.open(issues,'w') do |f|
f.puts issues_data.to_json
end
File.open(stories,'w') do |f|
f.puts stories_data.to_json
end
end

private

def to_ostruct(obj)
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/generate_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
Rake::Task["generate:all"].invoke
end

desc "creates json files"
task :json do
builder = Greeby::Builder.new
builder.make_json
end

end

task :generate do
Expand Down

0 comments on commit a86c32a

Please sign in to comment.