Skip to content

Commit

Permalink
Added code contribution page and syntax highlighting css
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaex committed Feb 25, 2017
1 parent 0d839c3 commit a16dc4c
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_site/
.sass-cache/
.jekyll-metadata
.jekyll-metadata
Gemfile.lock
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins
5 changes: 3 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ url: https://getsharex.com
author: ShareX Team
github: https://github.com/ShareX/ShareX
twitter: GetShareX
markdown: kramdown

googleAnalyticsId: UA-40712139-3
addThisId: 53e2d1c30114f995

markdown: kramdown
highlighter: rouge

kramdown:
input: GFM
33 changes: 33 additions & 0 deletions _sass/highlight.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #008000 } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #0000ff } /* Keyword */
.highlight .cm { color: #008000 } /* Comment.Multiline */
.highlight .cp { color: #0000ff } /* Comment.Preproc */
.highlight .c1 { color: #008000 } /* Comment.Single */
.highlight .cs { color: #008000 } /* Comment.Special */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gh { font-weight: bold } /* Generic.Heading */
.highlight .gp { font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { font-weight: bold } /* Generic.Subheading */
.highlight .kc { color: #0000ff } /* Keyword.Constant */
.highlight .kd { color: #0000ff } /* Keyword.Declaration */
.highlight .kn { color: #0000ff } /* Keyword.Namespace */
.highlight .kp { color: #0000ff } /* Keyword.Pseudo */
.highlight .kr { color: #0000ff } /* Keyword.Reserved */
.highlight .kt { color: #2b91af } /* Keyword.Type */
.highlight .s { color: #a31515 } /* Literal.String */
.highlight .nc { color: #2b91af } /* Name.Class */
.highlight .ow { color: #0000ff } /* Operator.Word */
.highlight .sb { color: #a31515 } /* Literal.String.Backtick */
.highlight .sc { color: #a31515 } /* Literal.String.Char */
.highlight .sd { color: #a31515 } /* Literal.String.Doc */
.highlight .s2 { color: #a31515 } /* Literal.String.Double */
.highlight .se { color: #a31515 } /* Literal.String.Escape */
.highlight .sh { color: #a31515 } /* Literal.String.Heredoc */
.highlight .si { color: #a31515 } /* Literal.String.Interpol */
.highlight .sx { color: #a31515 } /* Literal.String.Other */
.highlight .sr { color: #a31515 } /* Literal.String.Regex */
.highlight .s1 { color: #a31515 } /* Literal.String.Single */
.highlight .ss { color: #a31515 } /* Literal.String.Symbol */
31 changes: 16 additions & 15 deletions css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---

@import "sticky-footer";
@import "highlight";

$color-primary: #1c5288;
$color-primary-2: #12598d;
Expand Down Expand Up @@ -416,10 +417,17 @@ footer {
background: linear-gradient(to right, $color-primary 0%, transparent 100%) left bottom transparent no-repeat;
background-size: 100% 1px;
}

.markdown > ul {
padding-left: 25px;
}
}

code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
padding: 3px 5px;
margin: 0px;
font-size: 85%;
color: #337ab7;
color: #333;
background-color: rgba(0, 0, 0, 0.03);
border-radius: 3px;
}

.markdown {
Expand All @@ -432,22 +440,15 @@ footer {
h4 {
margin-top: 15px;
}

ul {
padding-left: 25px;
}

li {
margin-top: 4px;
}

code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
padding: 3px 5px;
margin: 0px;
font-size: 85%;
color: #337ab7;
color: #333;
background-color: rgba(0, 0, 0, 0.03);
border-radius: 3px;
}

hr {
border-top: 1px solid #ababab;
}
Expand Down
183 changes: 183 additions & 0 deletions docs/code-contribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
layout: markdown
title: Code contribution
---

## Requirements

* [Visual Studio 2015](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx) (You can't compile ShareX with VS2013 or older versions)

## Code formatting

We are using [CodeMaid](http://www.codemaid.net/) for code formatting. You can import our project settings from [here](https://github.com/ShareX/ShareX/blob/master/CodeMaid.config). When you press ``Ctrl + S`` to save current file, it will automatically format codes before saving.

**Tab spacing:** 4 spaces

**New line:** CR + LF (Windows)

## How to create a new uploader

In the interest of keeping the size of ShareX setup small and in order to maintain performance of ShareX, utilization of external libraries is discouraged.

Best way to understand how to make a new uploader is by going through existing uploader classes and checking how these uploaders work. There are many example uploaders and you can probably copy & paste majority of codes from them when creating new uploader.

---

In `ShareX.UploadersLib` project, create a new uploader class file in the folder according to uploader type (ImageUploaders, TextUploaders, FileUploaders, URLShorteners). Inherit uploader according to uploader type (ImageUploader, TextUploader, FileUploader, URLShortener).

```csharp
namespace ShareX.UploadersLib.ImageUploaders
{
...

public sealed class Imgur : ImageUploader, IOAuth2
{
public override UploadResult Upload(Stream stream, string fileName)
{
...

UploadResult result = UploadData(stream, "https://api.imgur.com/3/image", fileName, "image", args, headers);

...
}
}
}
```

---

After uploader class is ready, add uploader name to `ShareX.UploadersLib/Enum.cs` (ImageDestination, TextDestination, FileDestination, UrlShortenerType)

```csharp
public enum ImageDestination
{
...
[Description("Imgur")]
Imgur,
...
}
```

---

Also need to create uploader service class which will be used by ShareX to initiate uploader class and check config to enable/disable destination.

```csharp
namespace ShareX.UploadersLib.ImageUploaders
{
public class ImgurImageUploaderService : ImageUploaderService
{
public override ImageDestination EnumValue { get; } = ImageDestination.Imgur;

public override Icon ServiceIcon => Resources.Imgur;

public override bool CheckConfig(UploadersConfig config)
{
return config.ImgurAccountType == AccountType.Anonymous || OAuth2Info.CheckOAuth(config.ImgurOAuth2Info);
}

public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
if (config.ImgurOAuth2Info == null)
{
config.ImgurOAuth2Info = new OAuth2Info(APIKeys.ImgurClientID, APIKeys.ImgurClientSecret);
}

return new Imgur(config.ImgurOAuth2Info)
{
UploadMethod = config.ImgurAccountType
};
}

public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpImgur;
}

...

public sealed class Imgur : ImageUploader, IOAuth2
{
...
}
}
```

`EnumValue` must be assigned so ShareX can know this service belongs to which uploader.

[Optional] `ServiceIcon` or `ServiceImage` only required if you gonna have tab in uploaders config window. Add icon/image file to `ShareX.UploadersLib\Favicons` folder and add it to `ShareX.UploadersLib` project resources.

`CheckConfig` function is used to check validation of config. For example if account type was user and if account info was empty then destination will be disabled in destinations menu.

`CreateUploader` function is used by ShareX task system to initiate uploader class with config.

[Optional] `GetUploadersConfigTabPage` function only required if you gonna have tab in uploaders config window. It will be used when user try to upload with missing or invalid account info then ShareX can open uploaders config window with current uploader tab selected.

Both service class and uploader class should be in same file (Example: `Imgur.cs`) for consistency with other uploaders.

---

You can store uploader settings in `ShareX.UploadersLib/UploadersConfig.cs`.

```csharp
public class UploadersConfig : SettingsBase<UploadersConfig>
{
...

// Imgur
public AccountType ImgurAccountType = AccountType.Anonymous;
public OAuth2Info ImgurOAuth2Info = null;

...
}
```

If uploader settings need to be configurable by user then in `ShareX.UploadersLib/Forms/UploadersConfigForm.cs` form, create new tab for your uploader.

```csharp
public void LoadSettings(UploadersConfig uploadersConfig)
{
...

// Imgur
oauth2Imgur.Enabled = Config.ImgurAccountType == AccountType.User;

if (OAuth2Info.CheckOAuth(Config.ImgurOAuth2Info))
{
oauth2Imgur.Status = OAuthLoginStatus.LoginSuccessful;
btnImgurRefreshAlbumList.Enabled = true;
}

atcImgurAccountType.SelectedAccountType = Config.ImgurAccountType;

...
}

...

private void atcImgurAccountType_AccountTypeChanged(AccountType accountType)
{
Config.ImgurAccountType = accountType;
oauth2Imgur.Enabled = Config.ImgurAccountType == AccountType.User;
}

private void oauth2Imgur_OpenButtonClicked()
{
ImgurAuthOpen();
}

private void oauth2Imgur_CompleteButtonClicked(string code)
{
ImgurAuthComplete(code);
}

private void oauth2Imgur_ClearButtonClicked()
{
Config.ImgurOAuth2Info = null;
}

private void oauth2Imgur_RefreshButtonClicked()
{
ImgurAuthRefresh();
}
```

0 comments on commit a16dc4c

Please sign in to comment.