Giter Club home page Giter Club logo

resourcespoet's Introduction

ResourcePoet

Kotlin API for generating Android XML Resources

Maven Central

Gradle

dependencies {
    implementation("com.commit451:resourcespoet:latest.release.here")
}

Basic Usage

Write variables to the poet like:

val poet = ResourcesPoet.create()
    .addString("app_name", "Test")
    .addColor("color_primary", "#FF0000")
    .addBool("is_cool", true)
    .addComment("This is a comment")
    .addDrawable("logo", "@drawable/logo")
    .addStyle("AppTheme.Dark", "Base.AppTheme.Dark")
    // etc
    .indent(true)
val xml: String = poet.build()
println(xml)

which would output this XML:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
    <string name="app_name">Test</string>
    <color name="color_primary">#FF0000</color>
    <bool name="is_cool">true</bool>
    <!--This is a comment-->
    <drawable name="logo">@drawable/logo</drawable>
    <style name="AppTheme.Dark" parent="Base.AppTheme.Dark"/>
</resources>

To get the XML result as a file:

val valuesFolder = File(resFolderPath + File.separator + "values")
valuesFolder.mkdirs()
val configXml = File(valuesFolder, "config.xml")
configXml.createNewFile()
poet.build(configXml)

You can even start with and modify an existing resource file:

val file = File("some/path/to/file")
val poet = ResourcesPoet.create(file)
    .remove(Type.STRING, "app_name")
    .addString("app_name", "Even Better App Name")
    .add(Type.BOOL, "is_cool", "true")

Supported Types

Most resource types are supported. All look similar in usage:

val poet = ResourcesPoet.create()
    .addBool("is_cool", true)
    .addColor("color_primary", "#FF0000")
    .addComment("This is a comment")
    .addDimension("margin", "2dp")
    .addDrawable("logo", "@drawable/logo")
    .addId("some_id")
    .addInteger("number", 0)
    .addIntegerArray("numbers", numbers)
    .addPlurals("songs", plurals)
    .addString("app_name", "Test")
    .addStringArray("stuff", strings)
    .addStyle("AppTheme.Dark", "Base.AppTheme.Dark")
    .addTypedArray("some_typed_array", typedArray)

We do not allow configuration of more complicated resources like drawable and anim in the creation sense.

License

Copyright 2024 Commit 451

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

resourcespoet's People

Contributors

jawnnypoo avatar jbarr21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

resourcespoet's Issues

Don't ship the sample

Looks like jitpack is including the sample as a JAR when someone includes the library. Not great

Add resource by type

Something like

poet.add(type, name, value)

would be great. It would need special configuration for things like IDs, etc

Add ability to ignore Lint warnings

It'd be useful to be able to add tools:ignore="SomeLintIssue" to elements somehow. Not sure what the API would look like.

Thanks for the great library!

Publish to Maven Central/JCenter?

Would it be possible for you to publish artifacts to Maven Central or JCenter? Otherwise, users of libraries that depend on this library are forced to add Jitpack as a repo, which is a poor experience and they may have policies not allowing this.

Add modification support

I could see a use case where if the user is working with an existing XML configuration file that they would want to script something out to modify an existing resource. We should support this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.