Skip to content

Commit

Permalink
Add compatibility info #30
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBarnabe committed Mar 18, 2015
1 parent 6c1b410 commit 32432ff
Show file tree
Hide file tree
Showing 120 changed files with 294 additions and 18 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/browsericons/chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/browsericons/firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/browsericons/opera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def store_location
def versionned_script(script_id, version_id)
return nil if script_id.nil?
script_id = script_id.to_i
current_script = Script.includes({:user => {}, :license => {}, :localized_attributes => :locale}).find(script_id)
current_script = Script.includes({:user => {}, :license => {}, :localized_attributes => :locale, :compatibilities => :browser}).find(script_id)
return [current_script, current_script.get_newest_saved_script_version] if version_id.nil?
version_id = version_id.to_i
script_version = ScriptVersion.find(version_id)
Expand Down
2 changes: 2 additions & 0 deletions app/models/browser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Browser < ActiveRecord::Base
end
4 changes: 4 additions & 0 deletions app/models/compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Compatibility < ActiveRecord::Base
belongs_to :script
belongs_to :browser
end
16 changes: 16 additions & 0 deletions app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Script < ActiveRecord::Base
has_many :localized_names, -> {where(:attribute_key => 'name')}, :class_name => 'LocalizedScriptAttribute'
has_many :localized_descriptions, -> {where(:attribute_key => 'description')}, :class_name => 'LocalizedScriptAttribute'
has_many :localized_additional_infos, -> {where(:attribute_key => 'additional_info')}, :class_name => 'LocalizedScriptAttribute'
has_many :compatibilities, :autosave => true

has_one :syntax_highlighted_code

Expand Down Expand Up @@ -193,6 +194,21 @@ def apply_from_script_version(script_version)
else
self.support_url = nil
end

self.compatibilities.each{|c| c.mark_for_destruction}
['compatible', 'incompatible'].each do |key|
next if !meta.has_key?(key)
compatible = key == 'compatible'
meta[key].each do |line|
browser_match = /\A([a-z]+).*/i.match(line)
next if browser_match.nil?
browser = Browser.where(code: browser_match[1].downcase).first
next if browser.nil?
comments_split = line.split(' ', 2)
comments = comments_split.length == 2 ? comments_split[1] : nil
compatibilities.build(compatible: compatible, browser: browser, comments: comments)
end
end
end

def get_newest_saved_script_version
Expand Down
2 changes: 1 addition & 1 deletion app/views/help/credits.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<% end %>
</ul>

<p>Discussion icons are from <a href="https://www.iconfinder.com/search/?q=iconset:softwaredemo">"Vista Style Base Software"</a> by <a href="http://www.icons-land.com/">Icons Land</a>.</p>
<p>Discussion icons are from <a href="https://www.iconfinder.com/search/?q=iconset:softwaredemo">"Vista Style Base Software"</a> by <a href="http://www.icons-land.com/">Icons Land</a>. Browser icons are from <a href="https://github.com/alrra/browser-logos/">alrra/browser-logos</a>.</p>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
if request.get? %>
<option data-language-url="<%=url_for(params.except(:locale).merge({:locale => code, :only_path => true, :locale_override => locale_with_override_param}))%>" value="<%=code%>"<%if params[:locale] == code%> selected<%end%>><%=name%> (<%=code%>)</option>
<% else %>
<option data-language-url="<%=root_path({:locale => code, :only_path => true, :locale_override => locale_with_override_param})%>" value="<%=code%>"<%if params[:locale] == code%> selected<%end%>><%=name%> (<%=code%>)</option>
<option data-language-url="<%=root_path({:locale => code, :locale_override => locale_with_override_param})%>" value="<%=code%>"<%if params[:locale] == code%> selected<%end%>><%=name%> (<%=code%>)</option>
<% end
end %>
<option value="help">Help us translate!</option>
Expand Down
24 changes: 24 additions & 0 deletions app/views/scripts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
<dd class="script-show-updated-date"><span><%=markup_date(@script.code_updated_at)%></span></dd>
<dt class="script-show-license"><span><%=t('scripts.license')%></span></dt>
<dd class="script-show-license"><span><%=@script.license_display%></span></dd>
<% if !@script.compatibilities.empty? %>
<dt class="script-show-compatibility"><span><%=t('scripts.compatibility')%></span></dt>
<dd class="script-show-compatibility"><span>
<% Browser.all.each do |b|
b_compatibilities = @script.compatibilities.select{|c| c.browser == b}
if b_compatibilities.empty?
status = 'unknown'
elsif b_compatibilities.all?{|c| c.compatible}
status = 'compatible'
elsif b_compatibilities.all?{|c| !c.compatible}
status = 'incompatible'
else
# a mixture
status = 'unknown'
end
# show icons for compatible and incompatible
if status == 'incompatible' %>
<img src="<%=asset_path "browsericons/#{b.code}-incompatible.png"%>" alt="<%=t('scripts.incompatible_with_browser', browser: b.name)%>" title="<%=b_compatibilities.map{|c|c.comments}.join("\n")%>">
<% elsif status == 'compatible' %>
<img src="<%=asset_path "browsericons/#{b.code}.png"%>" alt="<%=t('scripts.compatible_with_browser', browser: b.name)%>" title="<%=b_compatibilities.map{|c|c.comments}.join("\n")%>">
<% end %>
<% end %>
</span></dd>
<% end %>
</dl>
<div>
<dl id="script-applies-to" data-show-more-text="<%=t('common.expander_show_more')%>" data-show-less-text="<%=t('common.expander_show_less')%>">
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ en:
license: "License"
# what is shown as the license when no license is provided in a script
no_license: "N/A"
# label for the browser compatibility for a script
compatibility: "Compatibility"
compatible_with_browser: "Compatible with %{browser}"
incompatible_with_browser: "Incompatible with %{browser}"
# label for the list of sites or patterns a script applies to
applies_to: "Applies to"
# a title (tooltip) for the links in the "applies to" section going to a list of scripts for that site. count is the number of other scripts, site is the name of the site. add subkeys for your language per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20150316170754_add_compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class AddCompatibility < ActiveRecord::Migration
def change
create_table :browsers do |t|
t.string :code, :null => false, :limit => 20
t.string :name, :null => false, :limit => 20
end
reversible do |dir|
dir.up do
execute <<-EOF
insert into browsers (code, name) values ('firefox', 'Firefox'), ('chrome', 'Chrome'), ('opera', 'Opera');
EOF
end
end
create_table :compatibilities do |t|
t.belongs_to :script, :index => true, :null => false
t.belongs_to :browser, :null => false
t.boolean :compatible, :null => false
t.string :comments, :limit => 200
end
add_foreign_key :compatibilities, :scripts, on_delete: :cascade
add_foreign_key :compatibilities, :browsers, on_delete: :cascade
end
end
66 changes: 52 additions & 14 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ CREATE TABLE `GDN_Draft` (
KEY `FK_Draft_DiscussionID` (`DiscussionID`),
KEY `FK_Draft_CategoryID` (`CategoryID`),
KEY `FK_Draft_InsertUserID` (`InsertUserID`)
) ENGINE=InnoDB AUTO_INCREMENT=9975 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=9971 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1012,6 +1012,42 @@ CREATE TABLE `author_email_notification_types` (
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `browsers`
--

DROP TABLE IF EXISTS `browsers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `browsers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `compatibilities`
--

DROP TABLE IF EXISTS `compatibilities`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `compatibilities` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`script_id` int(11) NOT NULL,
`browser_id` int(11) NOT NULL,
`compatible` tinyint(1) NOT NULL,
`comments` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_compatibilities_on_script_id` (`script_id`),
KEY `fk_rails_f4cc20665e` (`browser_id`),
CONSTRAINT `fk_rails_f4cc20665e` FOREIGN KEY (`browser_id`) REFERENCES `browsers` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_rails_d5a68992a0` FOREIGN KEY (`script_id`) REFERENCES `scripts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `cpd_duplication_scripts`
--
Expand Down Expand Up @@ -1077,7 +1113,7 @@ CREATE TABLE `daily_update_check_counts` (
`update_check_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `index_daily_update_check_counts_on_script_id_and_ip` (`script_id`,`ip`)
) ENGINE=InnoDB AUTO_INCREMENT=64540127 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=64540128 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -1102,7 +1138,7 @@ CREATE TABLE `delayed_jobs` (
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `delayed_jobs_priority` (`priority`,`run_at`)
) ENGINE=InnoDB AUTO_INCREMENT=173212 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1155,7 +1191,7 @@ CREATE TABLE `install_counts` (
`installs` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_install_counts_on_script_id_and_install_date` (`script_id`,`install_date`)
) ENGINE=InnoDB AUTO_INCREMENT=385499 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=384602 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1188,7 +1224,7 @@ CREATE TABLE `locale_contributors` (
`transifex_user_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `index_locale_contributors_on_locale_id` (`locale_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1297 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=1675 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1231,7 +1267,7 @@ CREATE TABLE `localized_script_attributes` (
PRIMARY KEY (`id`),
KEY `index_localized_script_attributes_on_script_id` (`script_id`),
KEY `index_localized_script_attributes_on_locale_id` (`locale_id`)
) ENGINE=InnoDB AUTO_INCREMENT=124957 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=124987 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -1252,7 +1288,7 @@ CREATE TABLE `localized_script_version_attributes` (
PRIMARY KEY (`id`),
KEY `index_localized_script_version_attributes_on_script_version_id` (`script_version_id`),
KEY `index_localized_script_version_attributes_on_locale_id` (`locale_id`)
) ENGINE=InnoDB AUTO_INCREMENT=29187 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=29193 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1331,7 +1367,7 @@ CREATE TABLE `screenshots` (
`screenshot_updated_at` datetime DEFAULT NULL,
`caption` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=347 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=348 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -1348,7 +1384,7 @@ CREATE TABLE `screenshots_script_versions` (
PRIMARY KEY (`id`),
KEY `index_screenshots_script_versions_on_screenshot_id` (`screenshot_id`),
KEY `index_screenshots_script_versions_on_script_version_id` (`script_version_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1346 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=1349 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1380,7 +1416,7 @@ CREATE TABLE `script_codes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=56228 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED;
) ENGINE=InnoDB AUTO_INCREMENT=56233 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1553,7 +1589,7 @@ CREATE TABLE `script_versions` (
PRIMARY KEY (`id`),
KEY `index_script_versions_on_script_id` (`script_id`),
CONSTRAINT `fk_script_versions_script_id` FOREIGN KEY (`script_id`) REFERENCES `scripts` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39510 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=39516 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1638,7 +1674,7 @@ CREATE TABLE `update_check_counts` (
`update_checks` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_update_check_counts_on_script_id_and_update_check_date` (`script_id`,`update_check_date`)
) ENGINE=InnoDB AUTO_INCREMENT=751484 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=748154 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1676,7 +1712,7 @@ CREATE TABLE `users` (
PRIMARY KEY (`id`),
UNIQUE KEY `index_users_on_email` (`email`),
UNIQUE KEY `index_users_on_reset_password_token` (`reset_password_token`)
) ENGINE=InnoDB AUTO_INCREMENT=9547 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=9548 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

Expand All @@ -1688,7 +1724,7 @@ CREATE TABLE `users` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2015-03-07 18:34:41
-- Dump completed on 2015-03-16 12:30:16
INSERT INTO schema_migrations (version) VALUES ('20140210194333');

INSERT INTO schema_migrations (version) VALUES ('20140210201355');
Expand Down Expand Up @@ -1855,3 +1891,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150221013413');

INSERT INTO schema_migrations (version) VALUES ('20150307234007');

INSERT INTO schema_migrations (version) VALUES ('20150316170754');

1 change: 1 addition & 0 deletions public/assets/Chart-af3d8734d96a308cdecdde9508eafcba.js

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
6 changes: 6 additions & 0 deletions public/assets/application-ff1bd06269c1b45408515c15bfe928f9.js

Large diffs are not rendered by default.

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/assets/coderay-3e63e4c5e3f5a4f41c55045acd965b13.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Binary file not shown.
Loading

0 comments on commit 32432ff

Please sign in to comment.