From 4a78dd1a08f6f555cdfc541cd7280b8729572b9c Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Fri, 30 Sep 2016 16:50:21 -0700 Subject: [PATCH 01/13] Create LICENSE.md --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..d932105e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Quran.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From cb5d2e49adb281258df1a6c4fed88263b219dabf Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Wed, 9 Nov 2016 23:43:44 -0800 Subject: [PATCH 02/13] media models --- app/models/media.rb | 5 +++++ app/models/media/content.rb | 8 ++++++++ app/models/media/resource.rb | 5 +++++ spec/models/media/content_spec.rb | 5 +++++ spec/models/media/resource_spec.rb | 5 +++++ 5 files changed, 28 insertions(+) create mode 100644 app/models/media.rb create mode 100644 app/models/media/content.rb create mode 100644 app/models/media/resource.rb create mode 100644 spec/models/media/content_spec.rb create mode 100644 spec/models/media/resource_spec.rb diff --git a/app/models/media.rb b/app/models/media.rb new file mode 100644 index 00000000..b3c51403 --- /dev/null +++ b/app/models/media.rb @@ -0,0 +1,5 @@ +module Media + include Schema + + Schema.schema_name('Media', 'media') +end diff --git a/app/models/media/content.rb b/app/models/media/content.rb new file mode 100644 index 00000000..15060911 --- /dev/null +++ b/app/models/media/content.rb @@ -0,0 +1,8 @@ +class Media::Content < ActiveRecord::Base + extend Media + + self.primary_keys = :resource_id, :ayah_key + + belongs_to :resource, class_name: 'Media::Resource' + belongs_to :ayah, class_name: 'Quran::Ayah', foreign_key: 'ayah_key' +end diff --git a/app/models/media/resource.rb b/app/models/media/resource.rb new file mode 100644 index 00000000..6e0839b0 --- /dev/null +++ b/app/models/media/resource.rb @@ -0,0 +1,5 @@ +class Media::Resource < ActiveRecord::Base + extend Media + + has_many :content +end diff --git a/spec/models/media/content_spec.rb b/spec/models/media/content_spec.rb new file mode 100644 index 00000000..7a2ebef1 --- /dev/null +++ b/spec/models/media/content_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Media::Content, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/media/resource_spec.rb b/spec/models/media/resource_spec.rb new file mode 100644 index 00000000..39bb3266 --- /dev/null +++ b/spec/models/media/resource_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Media::Resource, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From df0b7a718f8dd35bcde8bc73983f26f6b20647f8 Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Thu, 10 Nov 2016 00:02:29 -0800 Subject: [PATCH 03/13] Dump 14 --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index f1572602..a60d46b7 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit f15726020ae5df5f5990b0c642b7cd547772feb6 +Subproject commit a60d46b7f574442535bbf33af82c3e9e98ba0857 From 073088d6eae82894a7ad1ca9760c5bbc7f3d5c5d Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Thu, 10 Nov 2016 00:04:02 -0800 Subject: [PATCH 04/13] unneeded code --- app/models/content/resource.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/models/content/resource.rb b/app/models/content/resource.rb index 1d05a717..a763a821 100644 --- a/app/models/content/resource.rb +++ b/app/models/content/resource.rb @@ -62,12 +62,6 @@ def self.list_language_options .order("language.language_code") end - def self.trial - self.enabled.joins(:language) - .group(language: [:language_code]) - # .order("i18n.language.language_code") - end - def view_json as_json(only: [:name, :description, :is_available, :slug]).merge( language: language_code, From c914bd0936115e821aae5ca398f471366af7c7b6 Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Thu, 10 Nov 2016 00:07:10 -0800 Subject: [PATCH 05/13] do not add db --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 29a3c537..f123ccf9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,6 @@ config/deploy.rb vendor/cache vendor/bundle/ -db/structure.sql +db dump.rdb passenger.* From ceacfa4903de5538f9ba4faa09337082c977221a Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Sun, 13 Nov 2016 14:14:35 -0800 Subject: [PATCH 06/13] Media content in API --- app/controllers/v2/ayahs_controller.rb | 1 + app/models/media/content.rb | 4 ++++ app/models/quran/ayah.rb | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/v2/ayahs_controller.rb b/app/controllers/v2/ayahs_controller.rb index 5bf3ebae..0fa5ac20 100644 --- a/app/controllers/v2/ayahs_controller.rb +++ b/app/controllers/v2/ayahs_controller.rb @@ -14,6 +14,7 @@ def index ayahs = Quran::Ayah .preload(glyphs: {word: [:corpus, :token]}) .preload(:text_tashkeel) + .preload(:media_content) .by_range(params[:surah_id], range[0], range[1]) ayahs.as_json_with_resources(ayahs, params) diff --git a/app/models/media/content.rb b/app/models/media/content.rb index 15060911..7aa78436 100644 --- a/app/models/media/content.rb +++ b/app/models/media/content.rb @@ -5,4 +5,8 @@ class Media::Content < ActiveRecord::Base belongs_to :resource, class_name: 'Media::Resource' belongs_to :ayah, class_name: 'Quran::Ayah', foreign_key: 'ayah_key' + + def as_json(options = {}) + super(include: :resource) + end end diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index fbbe57da..f8da811f 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -29,6 +29,9 @@ class Quran::Ayah < ActiveRecord::Base has_many :lemmas, class_name: 'Quran::Lemma', through: :words has_many :roots, class_name: 'Quran::Root', through: :words + has_many :media_resources, class_name: 'Media::Resource', through: :media_content, source: :resource + has_many :media_content, class_name: 'Media::Content', foreign_key: 'ayah_key' + has_many :_tafsir_ayah, class_name: 'Content::TafsirAyah', foreign_key: 'ayah_key' has_many :tafsirs, class_name: 'Content::Tafsir', through: :_tafsir_ayah @@ -106,7 +109,7 @@ def self.as_json_with_resources(ayahs, options = {}) end ayahs.map do |ayah| - ayah_json = ayah.as_json + ayah_json = ayah.as_json(include: {media_content: {include: :resource}}) ayah_json.merge({ content: content_option && content[ayah.ayah_key] ? content[ayah.ayah_key] : [], From 7ebef56b1c09c9a993d944e4a722a94b2e279b42 Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Sun, 13 Nov 2016 23:21:21 -0800 Subject: [PATCH 07/13] submodule update --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index a60d46b7..11d6f342 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit a60d46b7f574442535bbf33af82c3e9e98ba0857 +Subproject commit 11d6f342b83cf0294273942607c0d83c85a48212 From 48e471fdbb6cf7d7dcfe62665e9aaf7064ad43b6 Mon Sep 17 00:00:00 2001 From: Naveed Ahmad Date: Sun, 18 Dec 2016 21:28:12 +0500 Subject: [PATCH 08/13] Time to move surah info into database (#79) * time to move surah info into database * retrun info wrt to language --- Gemfile | 2 +- .../concerns/language_detection.rb | 3 +- app/controllers/v2/surahs_controller.rb | 9 ++ app/models/content/surah_info.rb | 29 ++++ app/models/media/content.rb | 11 ++ app/models/media/resource.rb | 12 ++ app/models/quran/surah.rb | 7 + config/routes.rb | 4 + lib/tasks/importer.rake | 141 ++++++++++++++++++ spec/models/content/ayah_detail_spec.rb | 19 +++ spec/models/content/sura_detail_spec.rb | 17 +++ spec/models/media/content_spec.rb | 11 ++ spec/models/media/resource_spec.rb | 12 ++ 13 files changed, 275 insertions(+), 2 deletions(-) create mode 100644 app/models/content/surah_info.rb create mode 100644 lib/tasks/importer.rake create mode 100644 spec/models/content/ayah_detail_spec.rb create mode 100644 spec/models/content/sura_detail_spec.rb diff --git a/Gemfile b/Gemfile index f4c2bb5c..36a1b9e3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' - +ruby '2.2.3' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' #gem 'rails', '4.1.1' diff --git a/app/controllers/concerns/language_detection.rb b/app/controllers/concerns/language_detection.rb index 910c1c34..c45eba8e 100644 --- a/app/controllers/concerns/language_detection.rb +++ b/app/controllers/concerns/language_detection.rb @@ -22,7 +22,8 @@ module LanguageDetection :portuguese => :pt, :russian => :ru, :spanish => :es, - :swedish => :sv + :swedish => :sv, + :urdu => :ur } def indices_boost diff --git a/app/controllers/v2/surahs_controller.rb b/app/controllers/v2/surahs_controller.rb index 2a867574..121919cf 100644 --- a/app/controllers/v2/surahs_controller.rb +++ b/app/controllers/v2/surahs_controller.rb @@ -21,6 +21,15 @@ def show render json: surah end + api :GET, '/v2/surahs/:id/info', 'Get a details of specific Surah' + api_version '2.0' + param :id, :number + def info + surah_info = Quran::Surah.find(surah_params).get_surah_info_for_language(params[:lang]) + + render json: surah_info.as_json + end + private def surah_params diff --git a/app/models/content/surah_info.rb b/app/models/content/surah_info.rb new file mode 100644 index 00000000..20209720 --- /dev/null +++ b/app/models/content/surah_info.rb @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: content.surah_infos +# +# id :integer not null, primary key +# language_code :string +# description :text +# surah_id :integer +# content_source :text +# short_description :text +# created_at :datetime not null +# updated_at :datetime not null +# + +class Content::SurahInfo < ActiveRecord::Base + extend Content + + self.table_name = 'surah_infos' + self.primary_key = 'id' + + belongs_to :language, class_name: 'Locale::Language', foreign_key: 'language_code' + belongs_to :surah, class_name: 'Quran::Surah' + + validates :language, :surah, presence: true + + def as_json(options = {}) + super(options.merge(only: [:language_code, :description, :content_source, :short_description, :surah_id])) + end +end diff --git a/app/models/media/content.rb b/app/models/media/content.rb index 7aa78436..6a9e9722 100644 --- a/app/models/media/content.rb +++ b/app/models/media/content.rb @@ -1,3 +1,14 @@ +# == Schema Information +# +# Table name: media.content +# +# resource_id :integer not null, primary key +# ayah_key :string primary key +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# + class Media::Content < ActiveRecord::Base extend Media diff --git a/app/models/media/resource.rb b/app/models/media/resource.rb index 6e0839b0..cc10572e 100644 --- a/app/models/media/resource.rb +++ b/app/models/media/resource.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: media.resource +# +# resource_id :integer not null, primary key +# name :string +# url :string +# provider :string +# created_at :datetime not null +# updated_at :datetime not null +# + class Media::Resource < ActiveRecord::Base extend Media diff --git a/app/models/quran/surah.rb b/app/models/quran/surah.rb index 5f9ac901..6917c1e1 100644 --- a/app/models/quran/surah.rb +++ b/app/models/quran/surah.rb @@ -21,6 +21,13 @@ class Quran::Surah < ActiveRecord::Base self.primary_key = 'surah_id' has_many :ayahs, class_name: 'Quran::Ayah', foreign_key: 'surah_id' + has_many :surah_infos, class_name: 'Content::SurahInfo' + + def get_surah_info_for_language(language_code) + language = Locale::Language.find_by_language_code(language_code) || Locale::Language.find('en') + + surah_infos.where(language: language) + end def name { diff --git a/config/routes.rb b/config/routes.rb index 096422c8..5efe3c69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,10 @@ resources :surahs, only: [:index, :show], defaults: { format: 'json' } do resources :ayahs, only: [:index], defaults: { format: 'json' } + + member do + get :info + end end resources :options, only: [], defaults: { format: 'json' } do diff --git a/lib/tasks/importer.rake b/lib/tasks/importer.rake new file mode 100644 index 00000000..4f265817 --- /dev/null +++ b/lib/tasks/importer.rake @@ -0,0 +1,141 @@ +namespace :importer do + + task import_surah_detail: :environment do + Content::SurahInfo.delete_all + + 1.upto(114) do |surah_number| + puts "Importing Surah##{surah_number}" + url = "https://raw.githubusercontent.com/quran/quran.com-frontend/master/src/components/SurahInfo/htmls/#{surah_number}.html.js" + content = HTTParty.get(url) + formatted_content = content.gsub("export default `", '').strip.chop + + surah = Quran::Surah.find(surah_number) + #elastic search is breaking. DO we need to index this content ? + surah_info = Content::SurahInfo.where(surah: surah, language: Locale::Language.find('en')).first_or_create + surah_info.description = formatted_content + surah_info.content_source = "Sayyid Abul Ala Maududi - Tafhim al-Qur'an - The Meaning of the Quran" + surah_info.short_description = get_short_description(surah_number) + surah_info.save + end + end + + def get_short_description(sura_number) + { + 1 => 'This Surah is named Al-Fatihah because of its subject-matter. Fatihah is that which opens a subject or a book or any other thing. In other words, Al-Fatihah is a sort of preface.', + 2 => 'Al-Baqarah (the Cow) has been so named from the story of the Cow occurring in this Surah (vv. 67-73). It has not, however, been used as a title to indicate the subject of the Surah. It will, therefore, be as wrong to translate the name Al-Baqarah into "The Cow" or "The Heifer" as to translate any English name, say Mr. Baker, Mr. Rice, Mr. Wolf etc., into their equivalents in other languages or vice versa, because this would imply that the Surah dealt with the subject of "The Cow". Many more Surahs of the Quran have been named in the same way because no comprehensive words exist in Arabic (in spite of its richness) to denote the wide scope of the subject discussed in them. As a matter of fact all human languages suffer from the same limitation.', + 3 =>'This Surah takes its name from v.33. Al-i-Imran, like the names of many other surahs, is merely a name to distinguish it from other surahs and does not imply that the family of Imran has been discussed in it.', + 4 =>'This Surah comprises several discourses which were revealed on different occasions during the period ranging probably between the end of A.H. 3 and the end of A.H. 4 or the beginning of A.H. 5. Although it is difficult to determine the exact dates of their revelations, yet it is possible to assign to them a fairly correct period with the help of the Commandments and the events mentioned therein and the Traditions concerning them.', + 5 =>"This Surah takes its' name from verse 112 in which the word mai'dah occurs. Like the names of many other surahs, this name has no special relation to the subject of the Surah but has been used merely as a symbol to distinguish it from other surahs.", + 6 =>"This Surah takes its name from vv. 136, 138 and 139 in which some superstitious beliefs of the idolatrous Arabs concerning the lawfulness of some cattle (an`am) and the unlawfulness of some others have been refuted.", + 7 =>"This Surah takes its name from vv. 46-47 in which mention of A'araf occurs.", + 8 =>"The Surah takes its name Al-Anfal (The Bounties) from the first verse.", + 9 =>"This Surah is known by two names -- At-Taubah and Al-Bara'at. It is called At-Taubah because it enunciates the nature of taubah (repentance) and mentions the conditions of its acceptance.(vv. 102. 118). The second name Bara'at (Release) is taken from the first word of the Surah.", + 10 =>"The Surah takes its name from V. 98, in which there is a reference to Prophet Yunus (Jonah). The name, as usual, is symbolical and does not indicate that the Surah deals with the story of Prophet Jonah.", + 11 =>"This Surah has been named after Prophet Hud whose story has been related in vv. 50-60.", + 12 =>"The subject matter of this Surah indicates that it was revealed during the last stage of the Holy Prophet's residence at Makkah, when the Quraish were considering the question of killing or exiling or imprisoning him. At that time some of the unbelievers put this question (probably at the instigation of the Jews) to test him :'Why did the Israelites go to Egypt?'' This question was asked because they knew that their story was not known to the Arabs for there was no mention of it whatever in their traditions and the Holy Prophet had never even referred to it before.", + 13 =>"This Surah takes its name from the word (ar-Ra'ad) (thunder) that occurs in v. 13. It is merely the symbolic name of the Surah and does not in any way mean that the Surah deals with the scientific problems connected with thunder.", + 14 =>"The Surah takes its name from v. 35 in which mention has been made of Prophet Ibrahim (Abraham). But it does not mean that it contains the life story of Prophet Abraham. The name is merely a symbol lid the names of many other surahs, i.e., the Surah in which Abraham's mention has been made.", + 15 =>"This Surah takes its name from v. 80.", + 16 =>"The name, An-Nahl, of this Surah has been taken from v. 68. This is merely to distinguish it from other Surahs.", + 17 =>"This Surah takes its name (Bani Israil) from v. 4. But this name is merely a distinctive appellation like the names of many other surahs and not a descriptive title, and does not mean that 'Bani Isra'il' is the theme of this Surah.", + 18 =>"This Surah takes its name from v. 9 in which the word (al-kahf) occurs.", + 19 =>"It takes its name from v. 16.", + 20 =>"This Surah takes its name from its 'first word 'Ta Ha.' This name, like the names of many other Surahs, is merely symbolic.", + 21 =>"The name of this Surah has not been taken from any verse but it has been called Al-Anbiyaa because it contains a continuous account of many Anbiyaa (Prophets). Nevertheless, it is a symbolic name and not a title.", + 22 =>"This Surah takes its name from v. 27.", + 23 =>"The surah takes its name, Al-Mu'minun, from the first verse.", + 24 =>"This Surah takes its name, An Nur, from verse 35.", + 25 =>"The Surah takes its name 'Al-Furqan' from the first verse. Though it is symbolic like the names of many other Surahs, it has a close relation to its subject matter.", + 26 =>"The Surah takes its name from verse 224 in which the word Ash-Shu`araa' occurs.", + 27 =>"The Surah takes its name from the phrase wad-in-naml which occurs in verse 18, implying that it is a Surah in which the story of An-Naml (the Ant) has been related.", + 28 =>"The Surah takes its name from verse 25 in which the word Al-Qasas occurs. Lexically, qasas means to relate events in their proper sequence. Thus, from the viewpoint of the meaning too, this word can be a suitable title for this Surah, for in it the detailed story of the Prophet Moses has been related.", + 29 =>"The Surah takes its name from verse 41 in which the word Ankabut (Spider) has occurred.", + 30 =>"The Surah takes its name Ar-Rum from the second verse in which the words ghulibat-ir-Rum have occurred.", + 31 =>"The Surah has been named Luqman after Luqman the Sage, whose admonitions to his son have been related in vv. 12-19 of this Surah.", + 32 =>"The Surah has been entitled As-Sajdah after the theme of Sajdah (prostration) as expressed in verse 15.", + 33 =>"The Surah derives its name Al-Ahzab from verse 20.", + 34 =>"The Surah takes its name from verse 15 in which the word Saba has occurred, which implies that it is the Surah in which mention has been made of Saba (i. e. the Sabaeans).", + 35 =>"The word Fatir of the first very verse is the title given to this Surah, which simply means that it is a Surah in which the word Fatir has occurred. The other name is Al Malaika, which also occurs in the first verse.", + 36 =>"The Surah takes its name from the two letters of the alphabet with which it begins. It is written in English as Yasin, Ya-sin or Yaseen.", + 37 =>"The name is derived from the word was saaffat with which the Surah begins.", + 38 =>"The Surah takes its name from the alphabetic letter Suad with which it begins.", + 39 =>"The Surah derives its name from verse 71 and 73 in which the word zumar has occurred.", + 40 =>"The Surah takes its name Al Mu'min from verse 28, implying thereby, that it is a Surah in which Al Mu'min (the Believer of Pharaoh's people) has been mentioned.", + 41 =>"The name of this Surah is composed of two words, Ha-Mim and As-Sajdah, which implies that it is a Surah which begins with Ha-Mim and in which a verse requiring the performance of sajdah (prostration) has occurred.", + 42 =>"It is derived frog the sentence, wa amru-hum shura baina hum, of verse 38, implying thereby that it is a Surah in which the word shura has occurred.", + 43 =>"It is derived from the word zukhruf-an which occurs in verse 33 of this Surah.", + 44 =>"The Surah takes its name from the word dukhan which occurs in verse 10.", + 45 =>"It is derived from the sentence wa tartt kullu ummat- in jathiyat-un of verse 28, implying thereby that it is the Surah in which the word jathiyah has occurred.", + 46 =>"It is derived from the sentence idh andhara qauma-hu bil Ahqaf-i of verse 21.", + 47 =>"The Surah derives its name from the sentence wa amanu bi-ma nuzzila ala Muhammad-in of verse 2, thereby implying that it is the Surah in which the holy name of Muhammad (upon wham be Allah's peace and blessings) has occurred. Besides, it has another well known name 'al-Qital' also, which is derived from the sentence wa dhukira fi-hal-qital of verse 20.", + 48 =>"It is derived from the words Inna fatah-na laka fat-han mubina of the very first verse. This is not only a name of the Surah but also its title in view of the subject matter, for it deals with the great victory that Allah granted to the Holy Prophet and the Muslims in the form of the Truce of Hudaibiyah.", + 49 =>"The Surah takes its name from verse 4 in which the word hujurat has occurred.", + 50 =>"The Surah derives its name from the initial letter Qaf, thereby implying that it is the Surah which opens with the alphabetic letter Qaf.", + 51 =>"It is derived from the very first word wadh-dhariyat, which implies that it is a Surah which begins with the word adh-dhariyat.", + 52 =>"It is derived from the very first cord 'Wat Tur-i.'", + 53 =>"The Surah derives its name from the very first word wan Najm. This title also does not relate to the subject matter, but is a name given to the Surah as a symbol.", + 54 =>"The Surah takes its name from the very first verse Wan shaqq al-Qamar, thereby implying that it is a Surah in which the word al-Qamar has occurred.", + 55 =>"This Surah is entitled Ar Rahman, the word with which it begins. This title, however, deeply relates to the subject matter of the Surah too, for in it, from the beginning to the end, the manifestations and fruits of Allah's attribute of mercy and grace have been mentioned.", + 56 =>"The Surah takes its name from the word al-waqi`ah of the very first verse.", + 57 =>"The Surah takes its title from the sentence, Wa anzalna' l-hadida, of verse 25.", + 58 =>"This Surah is entitled Al Mujadalah as well as Al Mujadilah, the title being derived from the word tujadiluka of the very first verse. As at the outset mention has been made of the woman who pleaded with the Holy Prophet (upon whom be Allah's peace) the case of zihar pronounced by her husband and urged him to suggest a way out of the difficult situation in order to save her and, her children's life from ruin, and Allah has described her pleading by the word 'mujadalah', the Surah came to be known by this very title. If it is read as 'mujadalah', it would mean 'pleading and arguing', and if it is read as 'mujadilah', it would mean 'the woman who pleaded and argued.'", + 59 =>"The Surah derives its name from the mention of the word al-hashr in verse thereby implying that it is the Surah in which the word al-hashr has occurred.", + 60 =>"In verse 10 of this Surah it has been enjoined that the women who emigrate to dar al-Islam (the Islamic State) and claim to be Muslims, should be examined hence the title Al-Mumtahinah. The word is pronounced both as mumtahinah and as mumtahanah, the meaning according to the first pronunciation being 'the Surah which examines', and according to the second, 'the woman who is examined.'", + 61 =>"The Surah derives its name from the sentence yuqatiluna fi sabil-i- hlsaff-an of verse 4; thereby implying that it is a Surah in which the word saff occurred.", + 62 =>"It is derived from the sentence idha nudiya-lis-salat-imin-yaum-il- Jumu'ati of verse 9. Although in this Surah injunctions about the Friday congregational Prayer also have been given, yet 'Jumu'ah' is not the title of its subject-matter as a whole, but this name too, like the names of other Surahs, is only a symbolic title.", + 63 =>"The Surah takes its name from the sentence Idha jaa kal-munafiquna of verse 1. This is the name of the Surah as well as the title of its subject matter, for in it a review has been made of the conduct and attitude of the hypocrites themselves.", + 64 =>"The Surah takes its name from the sentence Dhalika yaum-ut taghabun of verse 9, thereby implying that it is the Surah in which the word at taghabun has occurred.", + 65 =>"At-Talaq is not only the name of this Surah but also the title of its subject matter, for it contains commandments about Talaq (divorce) itself. Hadrat `Abdullah bin Mas`ud has described it as Surah an-Nisa al-qusra also, i.e. the shorter Surah an-Nisa.", + 66 =>"The Surah derived its name from the words lima tuharrimu of the very first verse. This too is not a title of its subject matter, but the name implies that it is the Surah in which the incident of tahrim (prohibition, forbiddance) has been mentioned.", + 67 =>"The Surah takes its name al-Mulk from the very first sentence.", + 68 =>"This Surah is called Nun as well as Al-Qalam, the words with which it begins.", + 69 =>"The Surah takes its name from the word al-Haaqqah with which it opens.", + 70 =>"The Surah takes its name from the word dhil Ma'arij in verse 3.", + 71 =>"'Nuh' is the name of this Surah as well as the title of its subject matter, for in it, from beginning to the end, the story of the Prophet Noah has been related.", + 72 =>"'Al-Jinn' is the name of this Surah as well as the title of its subject matter, for in it the event of the Jinn's hearing the Qur'an and returning to their people to preach Islam to them, has been related in detail.", + 73 =>"The Surah has been so designated after the word al-muzzammil occurring in the very first verse. This is only a name and not a title of its subject matter.", + 74 =>"The Surah takes its name from the word al-muddaththir in the first verse. This also is only a name, not a title of its subject matter.", + 75 =>"The Surah has been so named after the word al-Qiyamah in the first verse. This is not only the name but also the title of this Surah, for it is devoted to Resurrection itself.", + 76 =>"This Surah is called Ad-Dahr as well as Al-Insan after the words occurring in the first verse.", + 77 =>"The Surah takes its name from the word wal-mursalat in the first verse.", + 78 =>"The Surah derived its name from the word an-Naba in the second verse. This is not only a name but also a title of its subject matter, for Naba implies the news of Resurrection and Hereafter and the whole Surah is devoted to the same theme.", + 79 =>"It is derived from the word wan-nazi`at with which the Surah opens.", + 80 =>"The Surah is so designated after the word `abasa with which it opens.", + 81 =>"It is derived from the word kuwwirat in the first verse. Kuwwirat is passive voice from takvir in the past tense, and means 'that which is folded up', thereby implying that it is a Surah in which the 'folding up' has been mentioned.", + 82 =>"It is derived from the word infatarat in the first verse. Infitar is an infinitive which means to cleave or split asunder, thereby implying that it is the Surah in which the splitting asunder of the sky has been mentioned.", + 83 =>"It is derived from the very first verse; Wayl-ul-lil mutaffifin.", + 84 =>"It is derived from the word inshaqqat in the first verse. Inshaqqat is infinitive which means to split asunder, thereby implying that it is the Surah in which mention has been made of the splitting asunder of the heavens.", + 85 =>"The Surah is so designated after the word al buruj appearing in the first verse.", + 86 =>"The Surah taken its name from the word at-tariq in its first verse.", + 87 =>"The Surah takes its name from the word al-A`la in the very first verse.", + 88 =>"The Surah takes its name from the word al-ghishiyah in the first verse.", + 89 =>"The Surah is so designated after the word wal-fajr with which it opens.", + 90 =>"The Surah has been so named after the word al balad in the first verse.", + 91 =>"The Surah has been so designated after the word ash-shams with which it opens.", + 92 =>"The Surah takes its name from the word wal-lail with which it opens.", + 93 =>"The Surah takes its name Ad-Duha from the very first word.", + 94 =>"The Surah is so designated after the first sentence.", + 95 =>"The Surah has been so named after the very first word at-tin.", + 96 =>"The Surah is so entitled after the word `alaq in the second verse.", + 97 =>"The Surah has been so designated after the word al-qadr in the very first verse.", + 98 =>"The Surah is so designated after the word al-bayyinah occurring at the end of the first verse.", + 99 =>"It is derived from the word zilzal in the first verse.", + 100 =>"The Surah has been so entitled after the word al `adiyat with which it opens.", + 101 =>"The Surah takes its name from its first word al-qari`ah. This is not only a name but also the title of its subject matter, for the Surah is devoted to Resurrection.", + 102 =>"The Surah taken its name from the word at takathur in the first verse.", + 103 =>"The Surah takes its name from the word al-`asr occurring in the first verse.", + 104 =>"The Surah takes its name from the word humazah occurring in the first verse.", + 105 =>"The Surah derives its name from the word ashab al fil in the very first verse.", + 106 =>"The Surah has been so entitled after the word Quraish in the very first verse.", + 107 =>"The Surah has been so designated after the word al-ma`un occurring at the end of the last verse.", + 108 =>"The Surah has been so designated after the word al-kauthar occurring in the first verse.", + 109 =>"The Surah takes its name from the word al-kafirun occurring in the first verse.", + 110 =>"The Surah takes its name from the word nasr occurring in the first verse.", + 111 =>"The Surah takes its name from the word Lahab in the first verse.", + 112 =>"Al-Ikhlas is not merely the name of this Surah but also the title of its contents, for it deals exclusively with Tauhid. The other Surahs of the Quran generally have been designated after a word occurring in them, but in this Surah the word Ikhlas has occurred nowhere. It has been given this name in view of its meaning and subject matter. Whoever understands it and believes in its teaching, will get rid of shirk (polytheism) completely.", + 113 =>"Although these two Surahs of the Qur'an are separate entities and are written in the Mushaf also under separate names, yet they are so deeply related mutually and their contents so closely resemble each other's that they have been designated by a common name Mu'awwidhatayn (the two Surahs in which refuge with Allah has been sought). Imam Baihaqi in Dala'il an-Nubuwwat has written that these Surahs were revealed together, that is why the combined name of both is Mu'awwidhatayn. We are writing the same one Introduction to both, for they discuss and deal with just the same matters and topics. However, they will be explained and commented on separately below.", + 114 =>"Although these two Surahs of the Qur'an are separate entities and are written in the Mushaf also under separate names, yet they are so deeply related mutually and their contents so closely resemble each other's that they have been designated by a common name Mu'awwidhatayn (the two Surahs in which refuge with Allah has been sought). Imam Baihaqi in Dala'il an-Nubuwwat has written that these Surahs were revealed together, that is why the combined name of both is Mu'awwidhatayn. We are writing the same one Introduction to both, for they discuss and deal with just the same matters and topics. However, they will be explained and commented on separately below." + }[sura_number] + end +end + diff --git a/spec/models/content/ayah_detail_spec.rb b/spec/models/content/ayah_detail_spec.rb new file mode 100644 index 00000000..391b0a65 --- /dev/null +++ b/spec/models/content/ayah_detail_spec.rb @@ -0,0 +1,19 @@ +# == Schema Information +# +# Table name: ayah_detail +# +# ayah_detail_id :integer not null, primary key +# language_code :string +# description :text +# name :text +# theme :text +# period_of_revelation :text +# created_at :datetime not null +# updated_at :datetime not null +# + +require 'rails_helper' + +RSpec.describe Content::AyahDetail, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/content/sura_detail_spec.rb b/spec/models/content/sura_detail_spec.rb new file mode 100644 index 00000000..3e189632 --- /dev/null +++ b/spec/models/content/sura_detail_spec.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: content.surah_details +# +# id :integer not null +# language_code :string +# description :text +# surah_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +require 'rails_helper' + +RSpec.describe Content::SuraDetail, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/media/content_spec.rb b/spec/models/media/content_spec.rb index 7a2ebef1..c40c4e14 100644 --- a/spec/models/media/content_spec.rb +++ b/spec/models/media/content_spec.rb @@ -1,3 +1,14 @@ +# == Schema Information +# +# Table name: media.content +# +# resource_id :integer not null, primary key +# ayah_key :string primary key +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# + require 'rails_helper' RSpec.describe Media::Content, type: :model do diff --git a/spec/models/media/resource_spec.rb b/spec/models/media/resource_spec.rb index 39bb3266..37515acd 100644 --- a/spec/models/media/resource_spec.rb +++ b/spec/models/media/resource_spec.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: media.resource +# +# resource_id :integer not null, primary key +# name :string +# url :string +# provider :string +# created_at :datetime not null +# updated_at :datetime not null +# + require 'rails_helper' RSpec.describe Media::Resource, type: :model do From ecda4bcd43ed166341ac4095e1c80a94ea7a15e9 Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Mon, 19 Dec 2016 01:23:51 +0200 Subject: [PATCH 09/13] surah infos --- Gemfile | 4 +- Gemfile.lock | 9 +- app/models/content/surah_info.rb | 2 - db | 2 +- lib/tasks/importer.rake | 141 ------------------------------- 5 files changed, 9 insertions(+), 149 deletions(-) delete mode 100644 lib/tasks/importer.rake diff --git a/Gemfile b/Gemfile index 36a1b9e3..a07bf90c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,12 @@ source 'https://rubygems.org' -ruby '2.2.3' +ruby '2.3.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' #gem 'rails', '4.1.1' gem 'rails', '4.2.6' # Use postgresql as the database for Active Record -gem 'pg', '~> 0.18.2' +gem 'pg', '~> 0.19.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'execjs' gem 'therubyracer', platforms: :ruby diff --git a/Gemfile.lock b/Gemfile.lock index 67b764c4..d93c4fd8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -178,7 +178,7 @@ GEM parallel (1.8.0) parallel_tests (2.5.0) parallel - pg (0.18.4) + pg (0.19.0) posix-spawn (0.3.11) prose (0.2.2) pry (0.9.12.6) @@ -344,7 +344,7 @@ DEPENDENCIES oj_mimic_json parallel parallel_tests - pg (~> 0.18.2) + pg (~> 0.19.0) prose pry-byebug pry-rails @@ -364,5 +364,8 @@ DEPENDENCIES whatlanguage zeus +RUBY VERSION + ruby 2.3.0p0 + BUNDLED WITH - 1.11.2 + 1.13.6 diff --git a/app/models/content/surah_info.rb b/app/models/content/surah_info.rb index 20209720..0b9f59a0 100644 --- a/app/models/content/surah_info.rb +++ b/app/models/content/surah_info.rb @@ -8,8 +8,6 @@ # surah_id :integer # content_source :text # short_description :text -# created_at :datetime not null -# updated_at :datetime not null # class Content::SurahInfo < ActiveRecord::Base diff --git a/db b/db index 11d6f342..5dbfe0ac 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 11d6f342b83cf0294273942607c0d83c85a48212 +Subproject commit 5dbfe0acb921cbc5454e86681b84de89cd553c93 diff --git a/lib/tasks/importer.rake b/lib/tasks/importer.rake deleted file mode 100644 index 4f265817..00000000 --- a/lib/tasks/importer.rake +++ /dev/null @@ -1,141 +0,0 @@ -namespace :importer do - - task import_surah_detail: :environment do - Content::SurahInfo.delete_all - - 1.upto(114) do |surah_number| - puts "Importing Surah##{surah_number}" - url = "https://raw.githubusercontent.com/quran/quran.com-frontend/master/src/components/SurahInfo/htmls/#{surah_number}.html.js" - content = HTTParty.get(url) - formatted_content = content.gsub("export default `", '').strip.chop - - surah = Quran::Surah.find(surah_number) - #elastic search is breaking. DO we need to index this content ? - surah_info = Content::SurahInfo.where(surah: surah, language: Locale::Language.find('en')).first_or_create - surah_info.description = formatted_content - surah_info.content_source = "Sayyid Abul Ala Maududi - Tafhim al-Qur'an - The Meaning of the Quran" - surah_info.short_description = get_short_description(surah_number) - surah_info.save - end - end - - def get_short_description(sura_number) - { - 1 => 'This Surah is named Al-Fatihah because of its subject-matter. Fatihah is that which opens a subject or a book or any other thing. In other words, Al-Fatihah is a sort of preface.', - 2 => 'Al-Baqarah (the Cow) has been so named from the story of the Cow occurring in this Surah (vv. 67-73). It has not, however, been used as a title to indicate the subject of the Surah. It will, therefore, be as wrong to translate the name Al-Baqarah into "The Cow" or "The Heifer" as to translate any English name, say Mr. Baker, Mr. Rice, Mr. Wolf etc., into their equivalents in other languages or vice versa, because this would imply that the Surah dealt with the subject of "The Cow". Many more Surahs of the Quran have been named in the same way because no comprehensive words exist in Arabic (in spite of its richness) to denote the wide scope of the subject discussed in them. As a matter of fact all human languages suffer from the same limitation.', - 3 =>'This Surah takes its name from v.33. Al-i-Imran, like the names of many other surahs, is merely a name to distinguish it from other surahs and does not imply that the family of Imran has been discussed in it.', - 4 =>'This Surah comprises several discourses which were revealed on different occasions during the period ranging probably between the end of A.H. 3 and the end of A.H. 4 or the beginning of A.H. 5. Although it is difficult to determine the exact dates of their revelations, yet it is possible to assign to them a fairly correct period with the help of the Commandments and the events mentioned therein and the Traditions concerning them.', - 5 =>"This Surah takes its' name from verse 112 in which the word mai'dah occurs. Like the names of many other surahs, this name has no special relation to the subject of the Surah but has been used merely as a symbol to distinguish it from other surahs.", - 6 =>"This Surah takes its name from vv. 136, 138 and 139 in which some superstitious beliefs of the idolatrous Arabs concerning the lawfulness of some cattle (an`am) and the unlawfulness of some others have been refuted.", - 7 =>"This Surah takes its name from vv. 46-47 in which mention of A'araf occurs.", - 8 =>"The Surah takes its name Al-Anfal (The Bounties) from the first verse.", - 9 =>"This Surah is known by two names -- At-Taubah and Al-Bara'at. It is called At-Taubah because it enunciates the nature of taubah (repentance) and mentions the conditions of its acceptance.(vv. 102. 118). The second name Bara'at (Release) is taken from the first word of the Surah.", - 10 =>"The Surah takes its name from V. 98, in which there is a reference to Prophet Yunus (Jonah). The name, as usual, is symbolical and does not indicate that the Surah deals with the story of Prophet Jonah.", - 11 =>"This Surah has been named after Prophet Hud whose story has been related in vv. 50-60.", - 12 =>"The subject matter of this Surah indicates that it was revealed during the last stage of the Holy Prophet's residence at Makkah, when the Quraish were considering the question of killing or exiling or imprisoning him. At that time some of the unbelievers put this question (probably at the instigation of the Jews) to test him :'Why did the Israelites go to Egypt?'' This question was asked because they knew that their story was not known to the Arabs for there was no mention of it whatever in their traditions and the Holy Prophet had never even referred to it before.", - 13 =>"This Surah takes its name from the word (ar-Ra'ad) (thunder) that occurs in v. 13. It is merely the symbolic name of the Surah and does not in any way mean that the Surah deals with the scientific problems connected with thunder.", - 14 =>"The Surah takes its name from v. 35 in which mention has been made of Prophet Ibrahim (Abraham). But it does not mean that it contains the life story of Prophet Abraham. The name is merely a symbol lid the names of many other surahs, i.e., the Surah in which Abraham's mention has been made.", - 15 =>"This Surah takes its name from v. 80.", - 16 =>"The name, An-Nahl, of this Surah has been taken from v. 68. This is merely to distinguish it from other Surahs.", - 17 =>"This Surah takes its name (Bani Israil) from v. 4. But this name is merely a distinctive appellation like the names of many other surahs and not a descriptive title, and does not mean that 'Bani Isra'il' is the theme of this Surah.", - 18 =>"This Surah takes its name from v. 9 in which the word (al-kahf) occurs.", - 19 =>"It takes its name from v. 16.", - 20 =>"This Surah takes its name from its 'first word 'Ta Ha.' This name, like the names of many other Surahs, is merely symbolic.", - 21 =>"The name of this Surah has not been taken from any verse but it has been called Al-Anbiyaa because it contains a continuous account of many Anbiyaa (Prophets). Nevertheless, it is a symbolic name and not a title.", - 22 =>"This Surah takes its name from v. 27.", - 23 =>"The surah takes its name, Al-Mu'minun, from the first verse.", - 24 =>"This Surah takes its name, An Nur, from verse 35.", - 25 =>"The Surah takes its name 'Al-Furqan' from the first verse. Though it is symbolic like the names of many other Surahs, it has a close relation to its subject matter.", - 26 =>"The Surah takes its name from verse 224 in which the word Ash-Shu`araa' occurs.", - 27 =>"The Surah takes its name from the phrase wad-in-naml which occurs in verse 18, implying that it is a Surah in which the story of An-Naml (the Ant) has been related.", - 28 =>"The Surah takes its name from verse 25 in which the word Al-Qasas occurs. Lexically, qasas means to relate events in their proper sequence. Thus, from the viewpoint of the meaning too, this word can be a suitable title for this Surah, for in it the detailed story of the Prophet Moses has been related.", - 29 =>"The Surah takes its name from verse 41 in which the word Ankabut (Spider) has occurred.", - 30 =>"The Surah takes its name Ar-Rum from the second verse in which the words ghulibat-ir-Rum have occurred.", - 31 =>"The Surah has been named Luqman after Luqman the Sage, whose admonitions to his son have been related in vv. 12-19 of this Surah.", - 32 =>"The Surah has been entitled As-Sajdah after the theme of Sajdah (prostration) as expressed in verse 15.", - 33 =>"The Surah derives its name Al-Ahzab from verse 20.", - 34 =>"The Surah takes its name from verse 15 in which the word Saba has occurred, which implies that it is the Surah in which mention has been made of Saba (i. e. the Sabaeans).", - 35 =>"The word Fatir of the first very verse is the title given to this Surah, which simply means that it is a Surah in which the word Fatir has occurred. The other name is Al Malaika, which also occurs in the first verse.", - 36 =>"The Surah takes its name from the two letters of the alphabet with which it begins. It is written in English as Yasin, Ya-sin or Yaseen.", - 37 =>"The name is derived from the word was saaffat with which the Surah begins.", - 38 =>"The Surah takes its name from the alphabetic letter Suad with which it begins.", - 39 =>"The Surah derives its name from verse 71 and 73 in which the word zumar has occurred.", - 40 =>"The Surah takes its name Al Mu'min from verse 28, implying thereby, that it is a Surah in which Al Mu'min (the Believer of Pharaoh's people) has been mentioned.", - 41 =>"The name of this Surah is composed of two words, Ha-Mim and As-Sajdah, which implies that it is a Surah which begins with Ha-Mim and in which a verse requiring the performance of sajdah (prostration) has occurred.", - 42 =>"It is derived frog the sentence, wa amru-hum shura baina hum, of verse 38, implying thereby that it is a Surah in which the word shura has occurred.", - 43 =>"It is derived from the word zukhruf-an which occurs in verse 33 of this Surah.", - 44 =>"The Surah takes its name from the word dukhan which occurs in verse 10.", - 45 =>"It is derived from the sentence wa tartt kullu ummat- in jathiyat-un of verse 28, implying thereby that it is the Surah in which the word jathiyah has occurred.", - 46 =>"It is derived from the sentence idh andhara qauma-hu bil Ahqaf-i of verse 21.", - 47 =>"The Surah derives its name from the sentence wa amanu bi-ma nuzzila ala Muhammad-in of verse 2, thereby implying that it is the Surah in which the holy name of Muhammad (upon wham be Allah's peace and blessings) has occurred. Besides, it has another well known name 'al-Qital' also, which is derived from the sentence wa dhukira fi-hal-qital of verse 20.", - 48 =>"It is derived from the words Inna fatah-na laka fat-han mubina of the very first verse. This is not only a name of the Surah but also its title in view of the subject matter, for it deals with the great victory that Allah granted to the Holy Prophet and the Muslims in the form of the Truce of Hudaibiyah.", - 49 =>"The Surah takes its name from verse 4 in which the word hujurat has occurred.", - 50 =>"The Surah derives its name from the initial letter Qaf, thereby implying that it is the Surah which opens with the alphabetic letter Qaf.", - 51 =>"It is derived from the very first word wadh-dhariyat, which implies that it is a Surah which begins with the word adh-dhariyat.", - 52 =>"It is derived from the very first cord 'Wat Tur-i.'", - 53 =>"The Surah derives its name from the very first word wan Najm. This title also does not relate to the subject matter, but is a name given to the Surah as a symbol.", - 54 =>"The Surah takes its name from the very first verse Wan shaqq al-Qamar, thereby implying that it is a Surah in which the word al-Qamar has occurred.", - 55 =>"This Surah is entitled Ar Rahman, the word with which it begins. This title, however, deeply relates to the subject matter of the Surah too, for in it, from the beginning to the end, the manifestations and fruits of Allah's attribute of mercy and grace have been mentioned.", - 56 =>"The Surah takes its name from the word al-waqi`ah of the very first verse.", - 57 =>"The Surah takes its title from the sentence, Wa anzalna' l-hadida, of verse 25.", - 58 =>"This Surah is entitled Al Mujadalah as well as Al Mujadilah, the title being derived from the word tujadiluka of the very first verse. As at the outset mention has been made of the woman who pleaded with the Holy Prophet (upon whom be Allah's peace) the case of zihar pronounced by her husband and urged him to suggest a way out of the difficult situation in order to save her and, her children's life from ruin, and Allah has described her pleading by the word 'mujadalah', the Surah came to be known by this very title. If it is read as 'mujadalah', it would mean 'pleading and arguing', and if it is read as 'mujadilah', it would mean 'the woman who pleaded and argued.'", - 59 =>"The Surah derives its name from the mention of the word al-hashr in verse thereby implying that it is the Surah in which the word al-hashr has occurred.", - 60 =>"In verse 10 of this Surah it has been enjoined that the women who emigrate to dar al-Islam (the Islamic State) and claim to be Muslims, should be examined hence the title Al-Mumtahinah. The word is pronounced both as mumtahinah and as mumtahanah, the meaning according to the first pronunciation being 'the Surah which examines', and according to the second, 'the woman who is examined.'", - 61 =>"The Surah derives its name from the sentence yuqatiluna fi sabil-i- hlsaff-an of verse 4; thereby implying that it is a Surah in which the word saff occurred.", - 62 =>"It is derived from the sentence idha nudiya-lis-salat-imin-yaum-il- Jumu'ati of verse 9. Although in this Surah injunctions about the Friday congregational Prayer also have been given, yet 'Jumu'ah' is not the title of its subject-matter as a whole, but this name too, like the names of other Surahs, is only a symbolic title.", - 63 =>"The Surah takes its name from the sentence Idha jaa kal-munafiquna of verse 1. This is the name of the Surah as well as the title of its subject matter, for in it a review has been made of the conduct and attitude of the hypocrites themselves.", - 64 =>"The Surah takes its name from the sentence Dhalika yaum-ut taghabun of verse 9, thereby implying that it is the Surah in which the word at taghabun has occurred.", - 65 =>"At-Talaq is not only the name of this Surah but also the title of its subject matter, for it contains commandments about Talaq (divorce) itself. Hadrat `Abdullah bin Mas`ud has described it as Surah an-Nisa al-qusra also, i.e. the shorter Surah an-Nisa.", - 66 =>"The Surah derived its name from the words lima tuharrimu of the very first verse. This too is not a title of its subject matter, but the name implies that it is the Surah in which the incident of tahrim (prohibition, forbiddance) has been mentioned.", - 67 =>"The Surah takes its name al-Mulk from the very first sentence.", - 68 =>"This Surah is called Nun as well as Al-Qalam, the words with which it begins.", - 69 =>"The Surah takes its name from the word al-Haaqqah with which it opens.", - 70 =>"The Surah takes its name from the word dhil Ma'arij in verse 3.", - 71 =>"'Nuh' is the name of this Surah as well as the title of its subject matter, for in it, from beginning to the end, the story of the Prophet Noah has been related.", - 72 =>"'Al-Jinn' is the name of this Surah as well as the title of its subject matter, for in it the event of the Jinn's hearing the Qur'an and returning to their people to preach Islam to them, has been related in detail.", - 73 =>"The Surah has been so designated after the word al-muzzammil occurring in the very first verse. This is only a name and not a title of its subject matter.", - 74 =>"The Surah takes its name from the word al-muddaththir in the first verse. This also is only a name, not a title of its subject matter.", - 75 =>"The Surah has been so named after the word al-Qiyamah in the first verse. This is not only the name but also the title of this Surah, for it is devoted to Resurrection itself.", - 76 =>"This Surah is called Ad-Dahr as well as Al-Insan after the words occurring in the first verse.", - 77 =>"The Surah takes its name from the word wal-mursalat in the first verse.", - 78 =>"The Surah derived its name from the word an-Naba in the second verse. This is not only a name but also a title of its subject matter, for Naba implies the news of Resurrection and Hereafter and the whole Surah is devoted to the same theme.", - 79 =>"It is derived from the word wan-nazi`at with which the Surah opens.", - 80 =>"The Surah is so designated after the word `abasa with which it opens.", - 81 =>"It is derived from the word kuwwirat in the first verse. Kuwwirat is passive voice from takvir in the past tense, and means 'that which is folded up', thereby implying that it is a Surah in which the 'folding up' has been mentioned.", - 82 =>"It is derived from the word infatarat in the first verse. Infitar is an infinitive which means to cleave or split asunder, thereby implying that it is the Surah in which the splitting asunder of the sky has been mentioned.", - 83 =>"It is derived from the very first verse; Wayl-ul-lil mutaffifin.", - 84 =>"It is derived from the word inshaqqat in the first verse. Inshaqqat is infinitive which means to split asunder, thereby implying that it is the Surah in which mention has been made of the splitting asunder of the heavens.", - 85 =>"The Surah is so designated after the word al buruj appearing in the first verse.", - 86 =>"The Surah taken its name from the word at-tariq in its first verse.", - 87 =>"The Surah takes its name from the word al-A`la in the very first verse.", - 88 =>"The Surah takes its name from the word al-ghishiyah in the first verse.", - 89 =>"The Surah is so designated after the word wal-fajr with which it opens.", - 90 =>"The Surah has been so named after the word al balad in the first verse.", - 91 =>"The Surah has been so designated after the word ash-shams with which it opens.", - 92 =>"The Surah takes its name from the word wal-lail with which it opens.", - 93 =>"The Surah takes its name Ad-Duha from the very first word.", - 94 =>"The Surah is so designated after the first sentence.", - 95 =>"The Surah has been so named after the very first word at-tin.", - 96 =>"The Surah is so entitled after the word `alaq in the second verse.", - 97 =>"The Surah has been so designated after the word al-qadr in the very first verse.", - 98 =>"The Surah is so designated after the word al-bayyinah occurring at the end of the first verse.", - 99 =>"It is derived from the word zilzal in the first verse.", - 100 =>"The Surah has been so entitled after the word al `adiyat with which it opens.", - 101 =>"The Surah takes its name from its first word al-qari`ah. This is not only a name but also the title of its subject matter, for the Surah is devoted to Resurrection.", - 102 =>"The Surah taken its name from the word at takathur in the first verse.", - 103 =>"The Surah takes its name from the word al-`asr occurring in the first verse.", - 104 =>"The Surah takes its name from the word humazah occurring in the first verse.", - 105 =>"The Surah derives its name from the word ashab al fil in the very first verse.", - 106 =>"The Surah has been so entitled after the word Quraish in the very first verse.", - 107 =>"The Surah has been so designated after the word al-ma`un occurring at the end of the last verse.", - 108 =>"The Surah has been so designated after the word al-kauthar occurring in the first verse.", - 109 =>"The Surah takes its name from the word al-kafirun occurring in the first verse.", - 110 =>"The Surah takes its name from the word nasr occurring in the first verse.", - 111 =>"The Surah takes its name from the word Lahab in the first verse.", - 112 =>"Al-Ikhlas is not merely the name of this Surah but also the title of its contents, for it deals exclusively with Tauhid. The other Surahs of the Quran generally have been designated after a word occurring in them, but in this Surah the word Ikhlas has occurred nowhere. It has been given this name in view of its meaning and subject matter. Whoever understands it and believes in its teaching, will get rid of shirk (polytheism) completely.", - 113 =>"Although these two Surahs of the Qur'an are separate entities and are written in the Mushaf also under separate names, yet they are so deeply related mutually and their contents so closely resemble each other's that they have been designated by a common name Mu'awwidhatayn (the two Surahs in which refuge with Allah has been sought). Imam Baihaqi in Dala'il an-Nubuwwat has written that these Surahs were revealed together, that is why the combined name of both is Mu'awwidhatayn. We are writing the same one Introduction to both, for they discuss and deal with just the same matters and topics. However, they will be explained and commented on separately below.", - 114 =>"Although these two Surahs of the Qur'an are separate entities and are written in the Mushaf also under separate names, yet they are so deeply related mutually and their contents so closely resemble each other's that they have been designated by a common name Mu'awwidhatayn (the two Surahs in which refuge with Allah has been sought). Imam Baihaqi in Dala'il an-Nubuwwat has written that these Surahs were revealed together, that is why the combined name of both is Mu'awwidhatayn. We are writing the same one Introduction to both, for they discuss and deal with just the same matters and topics. However, they will be explained and commented on separately below." - }[sura_number] - end -end - From 628a0639c1a857842e978b5e1d8c4e320e3523be Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Mon, 19 Dec 2016 13:47:33 +0200 Subject: [PATCH 10/13] no more tafsir search --- app/models/search/query/indices.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/search/query/indices.rb b/app/models/search/query/indices.rb index 28db6095..d009f8c8 100644 --- a/app/models/search/query/indices.rb +++ b/app/models/search/query/indices.rb @@ -4,8 +4,7 @@ module Indices def index_boost if @query.is_arabic? { - 'text-font' => 4, - 'tafsir' => 1 + 'text-font' => 4 } else if @indices_boost @@ -18,7 +17,7 @@ def index_boost def indices if @query.is_arabic? - ['text-font', 'tafsir'] + ['text-font'] else ['trans*', 'text-font'] end From 72392e01c61b10ef29b72a894999f74aaa6207ac Mon Sep 17 00:00:00 2001 From: Mohamed El Mahallawy Date: Thu, 22 Dec 2016 09:19:34 +0200 Subject: [PATCH 11/13] Segments and Surah info apis --- app/models/audio/file.rb | 22 +++++++++++----------- app/models/quran/ayah.rb | 2 +- app/models/quran/surah.rb | 4 ++-- db | 2 +- lib/tasks/segments.rake | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 lib/tasks/segments.rake diff --git a/app/models/audio/file.rb b/app/models/audio/file.rb index ee9d8647..b2f2ba53 100644 --- a/app/models/audio/file.rb +++ b/app/models/audio/file.rb @@ -2,16 +2,16 @@ # # Table name: audio.file # -# file_id :integer not null, primary key -# recitation_id :integer not null -# ayah_key :text not null -# format :text not null -# duration :float -# mime_type :text not null -# is_enabled :boolean default(TRUE), not null -# url :text -# segments :text -# encrypted_segments :text +# file_id :integer not null, primary key +# recitation_id :integer not null +# ayah_key :text not null +# format :text not null +# duration :float +# mime_type :text not null +# is_enabled :boolean default(TRUE), not null +# url :text +# segments :text is an Array +# segments_stats :json # class Audio::File < ActiveRecord::Base @@ -31,6 +31,6 @@ def as_json(options = {}) ayah = ayah_key.split(':')[1] - super(only: [:duration, :url, :encrypted_segments]) + super(only: [:duration, :url, :segments]) end end diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index f8da811f..9203f8e7 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -95,7 +95,7 @@ def self.as_json_with_resources(ayahs, options = {}) if audio_option = options[:audio] audio = Audio::File - .where(ayah_key: keys, recitation_id: audio_option, is_enabled: true) + .where(ayah_key: keys, recitation_id: audio_option, is_enabled: true, format: 'mp3') .order(:ayah_key) .group_by(&:ayah_key) end diff --git a/app/models/quran/surah.rb b/app/models/quran/surah.rb index 6917c1e1..ef463129 100644 --- a/app/models/quran/surah.rb +++ b/app/models/quran/surah.rb @@ -25,8 +25,8 @@ class Quran::Surah < ActiveRecord::Base def get_surah_info_for_language(language_code) language = Locale::Language.find_by_language_code(language_code) || Locale::Language.find('en') - - surah_infos.where(language: language) + + surah_infos.find_by(language: language) end def name diff --git a/db b/db index 5dbfe0ac..8dbe996a 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 5dbfe0acb921cbc5454e86681b84de89cd553c93 +Subproject commit 8dbe996a336dbb57f1a0ff8119e6659d994b3c24 diff --git a/lib/tasks/segments.rake b/lib/tasks/segments.rake new file mode 100644 index 00000000..84e59143 --- /dev/null +++ b/lib/tasks/segments.rake @@ -0,0 +1,33 @@ +# May need this if @cpfair changes the files. +# files = [ +# { recitation_id: 1, filename: 'Abdul_Basit_Mujawwad_128kbps.json' }, +# { recitation_id: 2, filename: 'Abdul_Basit_Murattal_64kbps.json' }, +# { recitation_id: 3, filename: 'Abdurrahmaan_As-Sudais_192kbps.json' }, +# { recitation_id: 4, filename: 'Abu_Bakr_Ash-Shaatree_128kbps.json' }, +# { recitation_id: 5, filename: 'Hani_Rifai_192kbps.json' }, +# { recitation_id: 7, filename: 'Husary_Muallim_128kbps.json' }, +# { recitation_id: 8, filename: 'Alafasy_128kbps.json' }, +# { recitation_id: 9, filename: 'Minshawy_Mujawwad_192kbps.json' }, +# { recitation_id: 10, filename: 'Minshawy_Murattal_128kbps.json' }, +# { recitation_id: 11, filename: 'Saood_ash-Shuraym_128kbps.json' }, +# { recitation_id: 12, filename: 'Mohammad_al_Tablaway_128kbps.json' }, +# { recitation_id: 13, filename: 'Husary_64kbps.json' }, +# ] +# +# +# Parallel.each(files, in_processes: 4, progress: 'Importing segments') do |file| +# begin +# puts file[:filename] +# json = Oj.load_file("../quran-align-data/#{file[:filename]}") +# audio_files = Audio::File.where(recitation_id: file[:recitation_id], segments: nil) +# +# json.each do |ayah_json| +# record = audio_files.find_by(ayah_key: "#{ayah_json['surah']}:#{ayah_json['ayah']}") +# record.update(segments: ayah_json["segments"], segments_stats: ayah_json["stats"]) +# end +# +# rescue Exception => e +# puts e.message +# puts e.backtrace.inspect +# end +# end From d65af73feb3f3a385ca14c1af8e7d493b55a8b99 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 21 Dec 2016 23:40:29 -0800 Subject: [PATCH 12/13] Upgrade ruby to 2.3.1 --- .travis.yml | 2 +- Dockerfile | 8 ++++---- Gemfile | 2 +- Gemfile.lock | 2 +- docker/backend.quran.com | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0868a1e2..0cbd12e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ git: submodules: false rvm: - - 2.2.3 + - 2.3.1 cache: bundler diff --git a/Dockerfile b/Dockerfile index 79339f8c..b1d31794 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM phusion/passenger-customizable:0.9.17 +FROM phusion/passenger-customizable:0.9.19 # set correct environment variables ENV HOME /root @@ -7,14 +7,14 @@ ENV HOME /root CMD ["/sbin/my_init"] # customizing passenger-customizable image -RUN /pd_build/ruby2.2.sh +RUN /pd_build/ruby-2.3.*.sh RUN /pd_build/redis.sh ENV RAILS_ENV production # native passenger -RUN ruby2.2 -S passenger-config build-native-support -RUN setuser app ruby2.2 -S passenger-config build-native-support +RUN ruby2.3 -S passenger-config build-native-support +RUN setuser app ruby2.3 -S passenger-config build-native-support # nginx RUN rm /etc/service/nginx/down diff --git a/Gemfile b/Gemfile index a07bf90c..eb7d3468 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.0' +ruby '2.3.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' #gem 'rails', '4.1.1' diff --git a/Gemfile.lock b/Gemfile.lock index d93c4fd8..d3b9bed2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -365,7 +365,7 @@ DEPENDENCIES zeus RUBY VERSION - ruby 2.3.0p0 + ruby 2.3.1 BUNDLED WITH 1.13.6 diff --git a/docker/backend.quran.com b/docker/backend.quran.com index 1bb36401..a92982cf 100644 --- a/docker/backend.quran.com +++ b/docker/backend.quran.com @@ -8,7 +8,7 @@ server { location / { passenger_enabled on; passenger_user app; - passenger_ruby /usr/bin/ruby2.2; + passenger_ruby /usr/bin/ruby2.3; passenger_app_env production; passenger_max_request_queue_size 200; root /home/app/quran/public; From a765ff1d7afdd829ee1b5a52d0bff17b2c24ab47 Mon Sep 17 00:00:00 2001 From: Naveed Ahmad Date: Fri, 30 Dec 2016 18:53:58 +0500 Subject: [PATCH 13/13] fixed specs and added check for audio availability (#81) --- app/models/quran/ayah.rb | 2 +- config/routes.rb | 4 ++++ db | 2 +- spec/controllers/v2/ayahs_controller_spec.rb | 2 +- spec/controllers/v2/surahs_controller_spec.rb | 12 ++++++++++++ spec/models/content/ayah_detail_spec.rb | 19 ------------------- ...sura_detail_spec.rb => surah_info_spec.rb} | 2 +- 7 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 spec/models/content/ayah_detail_spec.rb rename spec/models/content/{sura_detail_spec.rb => surah_info_spec.rb} (87%) diff --git a/app/models/quran/ayah.rb b/app/models/quran/ayah.rb index 9203f8e7..d41681cd 100644 --- a/app/models/quran/ayah.rb +++ b/app/models/quran/ayah.rb @@ -113,7 +113,7 @@ def self.as_json_with_resources(ayahs, options = {}) ayah_json.merge({ content: content_option && content[ayah.ayah_key] ? content[ayah.ayah_key] : [], - audio: audio_option ? audio[ayah.ayah_key].first : {}, + audio: audio_option && audio[ayah.ayah_key] ? audio[ayah.ayah_key].first : {}, }) end end diff --git a/config/routes.rb b/config/routes.rb index 5efe3c69..73276eaa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,10 @@ resources :surahs, only: [:index, :show], defaults: { format: 'json' } do resources :ayahs, only: [:index], defaults: { format: 'json' } + + member do + get :info + end end resources :options, only: [], defaults: { format: 'json' } do diff --git a/db b/db index 8dbe996a..5dbfe0ac 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 8dbe996a336dbb57f1a0ff8119e6659d994b3c24 +Subproject commit 5dbfe0acb921cbc5454e86681b84de89cd553c93 diff --git a/spec/controllers/v2/ayahs_controller_spec.rb b/spec/controllers/v2/ayahs_controller_spec.rb index d012ce25..a4d8a5ac 100644 --- a/spec/controllers/v2/ayahs_controller_spec.rb +++ b/spec/controllers/v2/ayahs_controller_spec.rb @@ -9,7 +9,7 @@ context "getting surah #{id}" do before { get :index, { surah_id: id, from: 1, to: 30, content: [19], audio: 8 } } - it 'returns http success and returns corret number of ayahs' do + it 'returns http success and returns correct number of ayahs' do expect(response).to have_http_status(:success) if surah.ayat > 30 diff --git a/spec/controllers/v2/surahs_controller_spec.rb b/spec/controllers/v2/surahs_controller_spec.rb index 33e4f91d..6ca6b308 100644 --- a/spec/controllers/v2/surahs_controller_spec.rb +++ b/spec/controllers/v2/surahs_controller_spec.rb @@ -28,4 +28,16 @@ end end + describe 'GET #info' do + before { get :info, { id: 1 } } + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'returns information of first surah' do + expect(response_json['surah_id']).to eql(1) + end + end + end diff --git a/spec/models/content/ayah_detail_spec.rb b/spec/models/content/ayah_detail_spec.rb deleted file mode 100644 index 391b0a65..00000000 --- a/spec/models/content/ayah_detail_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# == Schema Information -# -# Table name: ayah_detail -# -# ayah_detail_id :integer not null, primary key -# language_code :string -# description :text -# name :text -# theme :text -# period_of_revelation :text -# created_at :datetime not null -# updated_at :datetime not null -# - -require 'rails_helper' - -RSpec.describe Content::AyahDetail, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/content/sura_detail_spec.rb b/spec/models/content/surah_info_spec.rb similarity index 87% rename from spec/models/content/sura_detail_spec.rb rename to spec/models/content/surah_info_spec.rb index 3e189632..287e5189 100644 --- a/spec/models/content/sura_detail_spec.rb +++ b/spec/models/content/surah_info_spec.rb @@ -12,6 +12,6 @@ require 'rails_helper' -RSpec.describe Content::SuraDetail, type: :model do +RSpec.describe Content::SurahInfo, type: :model do pending "add some examples to (or delete) #{__FILE__}" end