diff --git a/rhodecode/controllers/summary.py b/rhodecode/controllers/summary.py --- a/rhodecode/controllers/summary.py +++ b/rhodecode/controllers/summary.py @@ -23,23 +23,25 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import traceback import calendar import logging from time import mktime -from datetime import datetime, timedelta, date +from datetime import timedelta, date +from itertools import product -from vcs.exceptions import ChangesetError +from vcs.exceptions import ChangesetError, EmptyRepositoryError, \ + NodeDoesNotExistError from pylons import tmpl_context as c, request, url from pylons.i18n.translation import _ -from rhodecode.model.db import Statistics, Repository -from rhodecode.model.repo import RepoModel - +from rhodecode.model.db import Statistics +from rhodecode.lib import ALL_READMES, ALL_EXTS from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseRepoController, render from rhodecode.lib.utils import EmptyChangeset - +from rhodecode.lib.markup_renderer import MarkupRenderer from rhodecode.lib.celerylib import run_task from rhodecode.lib.celerylib.tasks import get_commits_stats, \ LANGUAGES_EXTENSIONS_MAP @@ -48,6 +50,9 @@ from rhodecode.lib.compat import json, O log = logging.getLogger(__name__) +README_FILES = [''.join([x[0][0], x[1][0]]) for x in + sorted(list(product(ALL_READMES, ALL_EXTS)), + key=lambda y:y[0][1] + y[1][1])] class SummaryController(BaseRepoController): @@ -161,8 +166,33 @@ class SummaryController(BaseRepoControll if c.enable_downloads: c.download_options = self._get_download_links(c.rhodecode_repo) + c.readme_data,c.readme_file = self.__get_readme_data() return render('summary/summary.html') + def __get_readme_data(self): + readme_data = None + readme_file = None + + try: + cs = c.rhodecode_repo.get_changeset('tip') + renderer = MarkupRenderer() + for f in README_FILES: + try: + readme = cs.get_node(f) + readme_file = f + readme_data = renderer.render(readme.content, f) + break + except NodeDoesNotExistError: + continue + except ChangesetError: + pass + except EmptyRepositoryError: + pass + except Exception: + log.error(traceback.format_exc()) + + return readme_data, readme_file + def _get_download_links(self, repo): download_l = [] @@ -181,3 +211,4 @@ class SummaryController(BaseRepoControll download_l.append(tags_group) return download_l + diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -66,6 +66,34 @@ ADDITIONAL_MAPPINGS = {'xaml': 'XAML'} LANGUAGES_EXTENSIONS_MAP.update(ADDITIONAL_MAPPINGS) +# list of readme files to search in file tree and display in summary +# attached weights defines the search order lower is first +ALL_READMES = [ + ('readme', 0), ('README', 0), ('Readme', 0), + ('doc/readme', 1), ('doc/README', 1), ('doc/Readme', 1), + ('Docs/readme', 2), ('Docs/README', 2), ('Docs/Readme', 2), + ('DOCS/readme', 2), ('DOCS/README', 2), ('DOCS/Readme', 2), + ('docs/readme', 2), ('docs/README', 2), ('docs/Readme', 2), +] + +# extension together with weights to search lower is first +RST_EXTS = [ + ('', 0), ('.rst', 1),('.rest', 1), + ('.RST', 2) ,('.REST', 2), + ('.txt', 3), ('.TXT', 3) +] + +MARKDOWN_EXTS = [ + ('.md', 1), ('.MD', 1), + ('.mkdn', 2), ('.MKDN', 2), + ('.mdown', 3), ('.MDOWN', 3), + ('.markdown', 4), ('.MARKDOWN', 4) +] + +PLAIN_EXTS = [('.text', 2),('.TEXT', 2)] + +ALL_EXTS = MARKDOWN_EXTS + RST_EXTS + PLAIN_EXTS + def str2bool(_str): """ diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -3011,4 +3011,96 @@ div#legend_container table td,div#legend border: 0px solid #545454; color: #AAAAAA; padding-left: 3px; -} \ No newline at end of file +} + +/*README STYLE*/ + +div.readme { + padding:0px; +} + +div.readme h2 { + font-weight: normal; +} + +div.readme .readme_box { + background-color: #fafafa; +} + +div.readme .readme_box { +clear:both; +overflow:hidden; +margin:0; +padding:0 20px 10px; +} + +div.readme .readme_box h1, div.readme .readme_box h2, div.readme .readme_box h3, div.readme .readme_box h4, div.readme .readme_box h5, div.readme .readme_box h6 { +border-bottom: 0 !important; +margin: 0 !important; +padding: 0 !important; +line-height: 1.5em !important; +} + + +div.readme .readme_box h1:first-child { +padding-top: .25em !important; +} + +div.readme .readme_box h2, div.readme .readme_box h3 { +margin: 1em 0 !important; +} + +div.readme .readme_box h2 { +margin-top: 1.5em !important; +border-top: 4px solid #e0e0e0 !important; +padding-top: .5em !important; +} + +div.readme .readme_box p { +color: black !important; +margin: 1em 0 !important; +line-height: 1.5em !important; +} + +div.readme .readme_box ul { +list-style: disc !important; +margin: 1em 0 1em 2em !important; +} + +div.readme .readme_box ol { +list-style: decimal; +margin: 1em 0 1em 2em !important; +} + +div.readme .readme_box pre, code { +font: 12px "Bitstream Vera Sans Mono","Courier",monospace; +} + +div.readme .readme_box code { + font-size: 12px !important; + background-color: ghostWhite !important; + color: #444 !important; + padding: 0 .2em !important; + border: 1px solid #dedede !important; +} + +div.readme .readme_box pre code { +padding: 0 !important; +font-size: 12px !important; +background-color: #eee !important; +border: none !important; +} + +div.readme .readme_box pre { +margin: 1em 0; +font-size: 12px; +background-color: #eee; +border: 1px solid #ddd; +padding: 5px; +color: #444; +overflow: auto; +-webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset; +-webkit-border-radius: 3px; +-moz-border-radius: 3px; +border-radius: 3px; +} diff --git a/rhodecode/templates/summary/summary.html b/rhodecode/templates/summary/summary.html --- a/rhodecode/templates/summary/summary.html +++ b/rhodecode/templates/summary/summary.html @@ -64,29 +64,22 @@ ##FORK %if c.dbrepo.fork:
- - ${_('public')} - ${_('Fork of')} ${c.dbrepo.fork.repo_name} + ${_('public')} + ${_('Fork of')} ${c.dbrepo.fork.repo_name}
%endif ##REMOTE %if c.dbrepo.clone_uri:
- - ${_('remote clone')} - ${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)} + ${_('remote clone')} + ${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)}
%endif -
@@ -94,7 +87,6 @@
${h.urlify_text(c.dbrepo.description)}
-
@@ -119,7 +111,6 @@ ${h.age(c.rhodecode_repo.last_change)}
${_('by')} ${h.get_changeset_safe(c.rhodecode_repo,'tip').author} -
@@ -187,123 +178,6 @@
-
@@ -319,7 +193,6 @@ %if h.HasPermissionAll('hg.admin')('enable stats on from summary'): ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-button-small")} %endif - %else: ${_('Loaded in')} ${c.stats_percentage} % %endif @@ -331,333 +204,9 @@
-
+
- -
@@ -669,32 +218,461 @@
<%include file='../shortlog/shortlog_data.html'/>
- ##%if c.repo_changesets: - ## ${h.link_to(_('show more'),h.url('changelog_home',repo_name=c.repo_name))} - ##%endif + + + +%if c.readme_data: +
+ +
+
+ ${c.readme_data|n} +
-
-
- -
-
- <%include file='../tags/tags_data.html'/> - %if c.repo_changesets: - ${h.link_to(_('show more'),h.url('tags_home',repo_name=c.repo_name))} - %endif -
-
-
-
- -
-
- <%include file='../branches/branches_data.html'/> - %if c.repo_changesets: - ${h.link_to(_('show more'),h.url('branches_home',repo_name=c.repo_name))} - %endif -
-
+%endif + + + diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -24,7 +24,9 @@ requirements = [ "python-dateutil>=1.5.0,<2.0.0", "dulwich>=0.8.0,<0.9.0", "vcs>=0.2.3.dev", - "webob==1.0.8" + "webob==1.0.8", + "markdown==2.0.3", + "docutils==0.8.1", ] dependency_links = [