From 011efb0c4bec3561c98861eb7255af8cf7d52973 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 20 Jan 2012 19:01:59 +0400 Subject: [PATCH] [issue #64] Added git access to Wiki. --- app/controllers/wiki_controller.rb | 3 + app/helpers/projects_helper.rb | 4 + app/models/project.rb | 2 +- app/views/wiki/_git_access.html.haml | 23 ++++ .../wiki/_git_access_message.en.html.haml | 17 +++ .../wiki/_git_access_message.ru.html.haml | 18 +++ app/views/wiki/compare.html.haml | 2 +- app/views/wiki/edit.html.haml | 2 +- app/views/wiki/git.html.haml | 27 +++++ app/views/wiki/history.html.haml | 2 +- app/views/wiki/new.html.haml | 2 +- app/views/wiki/pages.html.haml | 2 +- app/views/wiki/search.html.haml | 2 +- app/views/wiki/show.html.haml | 2 +- config/locales/ru.yml | 4 + lib/grack/base.rb | 1 + public/stylesheets/gollum/gollum.css | 104 ++++++++++++++++++ 17 files changed, 209 insertions(+), 8 deletions(-) create mode 100644 app/views/wiki/_git_access.html.haml create mode 100644 app/views/wiki/_git_access_message.en.html.haml create mode 100644 app/views/wiki/_git_access_message.ru.html.haml create mode 100644 app/views/wiki/git.html.haml diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 0b7a9bac1..5b0075b68 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -102,6 +102,9 @@ class WikiController < ApplicationController redirect_to project_wiki_index_path(@project) end + def git + end + def compare @name = params[:id] if request.post? diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 363bde95d..193d36049 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -6,4 +6,8 @@ module ProjectsHelper "http://#{request.host_with_port}/#{name}.git" end end + + def git_wiki_repo_url(name) + git_repo_url("#{name}.wiki") + end end diff --git a/app/models/project.rb b/app/models/project.rb index 4411fd2bc..58949f04e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -148,7 +148,7 @@ class Project < ActiveRecord::Base end def build_wiki_path(dir) - File.join(APP_CONFIG['root_path'], 'projects_wiki', "#{dir}.wiki.git") + File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.wiki.git") end def attach_to_personal_repository diff --git a/app/views/wiki/_git_access.html.haml b/app/views/wiki/_git_access.html.haml new file mode 100644 index 000000000..d30ea0dba --- /dev/null +++ b/app/views/wiki/_git_access.html.haml @@ -0,0 +1,23 @@ +.url-box + %ul.clone-urls + %li.http-clone-url.selected + = link_to t("layout.wiki.clones.http"), git_wiki_repo_url(@project.name), + :'data-permissions' => (can? @project, :write) ? 'Read+Write' : 'Read' + %input.url-field{:type => 'text', :spellcheck => 'false'} + %p.url-description + %strong + access + +:javascript + $(document).ready(function() { + var link = $('li.http-clone-url a').first(); + + $('.url-box input.url-field').attr('value', link.attr('href')); + $('.url-box p.url-description strong').text(link.attr('data-permissions')); + + $('li.http-clone-url a').live('click', function(e) { + e.preventDefault(); + $('.url-box input.url-field').attr('value', $(this).attr('href')); + $('.url-box p.url-description strong').text($(this).attr('data-permissions')); + }); + }); diff --git a/app/views/wiki/_git_access_message.en.html.haml b/app/views/wiki/_git_access_message.en.html.haml new file mode 100644 index 000000000..599cf7da5 --- /dev/null +++ b/app/views/wiki/_git_access_message.en.html.haml @@ -0,0 +1,17 @@ +#template + %p + Your wiki data can be cloned from a git repository for offline access. + You have several options for editing it at this point: + %ol + %li + With your favorite text editor or IDE. + %li + With the built-in web interface, included with the + = link_to 'Gollum', "https://github.com/github/gollum" + Ruby API. + %li + With the Gollum Ruby API. + %p + When you're done, you can simply push your changes back to our system to + see them reflected on the site. The wiki repositories obey the same + access rules as the source repository that they belong to. diff --git a/app/views/wiki/_git_access_message.ru.html.haml b/app/views/wiki/_git_access_message.ru.html.haml new file mode 100644 index 000000000..37176047f --- /dev/null +++ b/app/views/wiki/_git_access_message.ru.html.haml @@ -0,0 +1,18 @@ +#template + %p + Все данные вашей Wiki могут быть клонированы из Git-репозитория для + доступа без интернета. В этом случае вы можете редактировать страницы + следующими способами: + %ol + %li + Вашим любимым текстовым редактором или IDE. + %li + С помощью встроенного Web-интерфейса, включенного в + = link_to 'Gollum', "https://github.com/github/gollum" + Ruby API. + %li + С помощью Gollum Ruby API. + %p + Когда изменения будут завершены, просто запуште их обратно в нашу систему + чтобы увидеть их на сайте. Доступ к репозиторию Wiki осуществляется с теми + же правами, что и к проекту, с которым она связана. diff --git a/app/views/wiki/compare.html.haml b/app/views/wiki/compare.html.haml index 45c3687cc..e14d200f0 100644 --- a/app/views/wiki/compare.html.haml +++ b/app/views/wiki/compare.html.haml @@ -9,7 +9,7 @@ %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li{:class => (!@name and action_name == 'compare') ? 'active' : ''} = link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content #wiki-wrapper.inner.compare diff --git a/app/views/wiki/edit.html.haml b/app/views/wiki/edit.html.haml index d2c2e3618..8b67a1a1d 100644 --- a/app/views/wiki/edit.html.haml +++ b/app/views/wiki/edit.html.haml @@ -8,7 +8,7 @@ %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content #wiki-wrapper.inner diff --git a/app/views/wiki/git.html.haml b/app/views/wiki/git.html.haml new file mode 100644 index 000000000..ad20cbd37 --- /dev/null +++ b/app/views/wiki/git.html.haml @@ -0,0 +1,27 @@ += render :partial => 'gollum_includes' += render :partial => 'project_short' + +%a{ :name => "wiki"} +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) + %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) + %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) + %li.active= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) + + .content + #wiki-wrapper.inner.compare + #head + %h1.title + = t("layout.wiki.wiki_git_access") + + #wiki-content + = render :partial => "git_access" + %br + = render :partial => "git_access_message" + +- content_for :sidebar do + - render :partial => 'projects/sidebar' + + diff --git a/app/views/wiki/history.html.haml b/app/views/wiki/history.html.haml index 27a3768ff..d9c853d4b 100644 --- a/app/views/wiki/history.html.haml +++ b/app/views/wiki/history.html.haml @@ -9,7 +9,7 @@ %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li{:class => (!@name and action_name == 'history') ? 'active' : ''} = link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content #wiki-wrapper.inner.history diff --git a/app/views/wiki/new.html.haml b/app/views/wiki/new.html.haml index f9a5a4756..5ea39dc21 100644 --- a/app/views/wiki/new.html.haml +++ b/app/views/wiki/new.html.haml @@ -8,7 +8,7 @@ %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content #wiki-wrapper.inner diff --git a/app/views/wiki/pages.html.haml b/app/views/wiki/pages.html.haml index d55399349..62fd0ae4f 100644 --- a/app/views/wiki/pages.html.haml +++ b/app/views/wiki/pages.html.haml @@ -9,7 +9,7 @@ = link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li.active= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content .inner diff --git a/app/views/wiki/search.html.haml b/app/views/wiki/search.html.haml index 856a53389..2410ad019 100644 --- a/app/views/wiki/search.html.haml +++ b/app/views/wiki/search.html.haml @@ -8,7 +8,7 @@ %li.first= link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content .inner diff --git a/app/views/wiki/show.html.haml b/app/views/wiki/show.html.haml index 435e0cec7..cde1d11c5 100644 --- a/app/views/wiki/show.html.haml +++ b/app/views/wiki/show.html.haml @@ -9,7 +9,7 @@ = link_to t("layout.wiki.home"), project_wiki_index_path(@project) %li= link_to t("layout.wiki.pages"), pages_project_wiki_index_path(@project) %li= link_to t("layout.wiki.wiki_history"), history_project_wiki_index_path(@project) - %li= link_to t("layout.wiki.git_access"), '#' + %li= link_to t("layout.wiki.git_access"), git_project_wiki_index_path(@project) .content .inner diff --git a/config/locales/ru.yml b/config/locales/ru.yml index bc391a8ad..9028aefcd 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -171,6 +171,7 @@ ru: delete_page: Удалить страницу page_history: История create_page: Создать страницу + wiki_git_access: Доступ к Wiki через Git page_title: Заголовок страницы expand_collapse: Развернуть last_edited_by: Последним редактировал @@ -202,6 +203,9 @@ ru: search_results_for: "Результаты поиска для %{query}:" preview: Предпросмотр + clones: + http: HTTP + editor: bold: Жирный italic: Курсив diff --git a/lib/grack/base.rb b/lib/grack/base.rb index e2ee2a121..a4fd2a4d5 100644 --- a/lib/grack/base.rb +++ b/lib/grack/base.rb @@ -35,6 +35,7 @@ module Grack @project ||= begin uname, name = @env['PATH_INFO'].split('/')[1,2] name.gsub! /\.git$/, '' + name.gsub! /\.wiki$/, '' owner = User.find_by_uname(uname) || Group.find_by_uname(uname) Project.where(:owner_id => owner.id, :owner_type => owner.class).find_by_name(name) end diff --git a/public/stylesheets/gollum/gollum.css b/public/stylesheets/gollum/gollum.css index fe6ef710c..20b989713 100755 --- a/public/stylesheets/gollum/gollum.css +++ b/public/stylesheets/gollum/gollum.css @@ -459,7 +459,111 @@ margin-right: 0.6em; } + +/* git_access */ +#wiki-content .url-box { + border: medium none; + margin-left: 0; + padding: 0; +} + +.url-box { + border-top: 1px solid #DDDDDD; + height: 23px; + margin-left: -10px; + margin-top: 10px; + padding: 10px 10px 0; + width: 100%; +} +#wiki-content .url-box ul.clone_urls { + float: left; + height: 23px; + margin: 0; +} + +#wiki-content ul.clone-urls li.selected { + border-right-color: #BBBBBB; +} + +#wiki-content ul.clone-urls li { + border: medium none; + cursor: pointer; + float: left; + height: 23px; + list-style-type: none; + margin: 0; + overflow: visible; + padding: 0; + white-space: nowrap; +} + +ul.clone-urls li { + list-style-type: none; + margin: 5px 0 0; +} + +.url-box p { + color: #666666; + float: left; + font-size: 11px; + height: 23px; + line-height: 23px; + margin: 0 0 0 5px; +} + +#wiki-content ul.clone-urls li.selected > a { + background: -moz-linear-gradient(center top , #D7D7D7, #ABABAB) repeat scroll 0 0 transparent; + border-color: #C9C9C9 #C9C9C9 #9A9A9A; + color: #000000; + text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6); +} + +#wiki-content ul.clone-urls li:first-child a { + border-bottom-left-radius: 3px; + border-left: 1px solid #D4D4D4; + border-top-left-radius: 3px; +} + +#wiki-content ul.clone-urls li > a { + -moz-border-bottom-colors: none; + -moz-border-image: none; + -moz-border-left-colors: none; + -moz-border-right-colors: none; + -moz-border-top-colors: none; + background: -moz-linear-gradient(center top , #F4F4F4, #ECECEC) repeat scroll 0 0 transparent; + border-color: #D4D4D4 #D4D4D4 #D4D4D4 -moz-use-text-color; + border-style: solid solid solid none; + border-width: 1px 1px 1px medium; + color: #333333; + display: block; + font-size: 11px; + font-weight: bold; + height: 21px; + line-height: 21px; + margin: 0; + padding: 0 9px; + text-decoration: none; + text-shadow: 1px 1px 0 #FFFFFF; +} + +#wiki-content input.url-field { + -moz-border-bottom-colors: none; + -moz-border-image: none; + -moz-border-left-colors: none; + -moz-border-right-colors: none; + -moz-border-top-colors: none; + border-color: #CCCCCC #CCCCCC #CCCCCC -moz-use-text-color; + border-style: solid solid solid none; + border-width: 1px 1px 1px medium; + color: #666666; + float: left; + font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace; + font-size: 11px; + height: 16px; + padding: 3px 5px 2px; + width: 400px; +} /* @control syntax */ .highlight { background: #ffffff; }